使用 FeatureTools 时无法将列转换为带有时间戳的 normalize_entity
Cannot convert column when using FeatureTools to normalize_entity with timestamps
我正在尝试使用 FeatureTools 规范化 table 以进行特征合成。我的 table 与 Max-Kanter 对 How to apply Deep Feature Synthesis to a single table 的回应相似。我遇到了一个例外,希望能得到一些帮助。
异常源自 featuretools.entityset.entity.entityset_convert_variable_type
,它似乎不处理时间类型。
异常的性质是什么,我可以解决它吗?
Table,df
:
PatientId | AppointmentID | Gender | ScheduledDay | AppointmentDay | Age | Neighbourhood | Scholarship | Hipertension | Diabetes | Alcoholism | Handcap | SMS_received | No-show
12345 | 5642903 | F | 2016-04-29 | 2016-04-29 | 62 | JARDIM DA | 0 | 1 | 0 | 0 | 0 | 0 | No
67890 | 3902943 | M | 2016-03-18 | 2016-04-29 | 44 | Other Nbh | 1 | 1 | 0 | 0 | 0 | 0 | Yes
...
我的代码:
appointment_entity_set = ft.EntitySet('appointments')
appointment_entity_set.entity_from_dataframe(
dataframe=df, entity_id='appointments',
index='AppointmentID', time_index='AppointmentDay')
# error generated here
appointment_entity_set.normalize_entity(base_entity_id='appointments',
new_entity_id='patients',
index='PatientId')
ScheduledDay 和 AppointmentDay 是 pandas._libs.tslib.Timestamp
类型,与 Max-Kanter's response 中的情况一样。
异常:
~/.virtualenvs/trane/lib/python3.6/site-packages/featuretools/entityset/entity.py in entityset_convert_variable_type(self, column_id, new_type, **kwargs)
474 df = self.df
--> 475 if df[column_id].empty:
476 return
477 if new_type == vtypes.Numeric:
Exception: Cannot convert column first_appointments_time to <class 'featuretools.variable_types.variable.DatetimeTimeIndex'>
featuretools==0.1.21
显示的错误似乎与 pandas 读取 AppointmentDay
变量的方式有关。实际上,我们有一个包含该数据集的示例 Kaggle kernel。在那里,我们需要使用 pandas.read_csv
和 parse_dates
:
data = pd.read_csv("data/KaggleV2-May-2016.csv", parse_dates=['AppointmentDay', 'ScheduledDay'])
那个 returns 一个 pandas 值类型为 numpy.datetime64
的系列。这应该可以很好地加载到 Featuretools。
另外,你能确定你有来自 pip 的最新版本的 Featuretools 吗?该堆栈跟踪中有一个不在最新版本中的设置跟踪命令。
我正在尝试使用 FeatureTools 规范化 table 以进行特征合成。我的 table 与 Max-Kanter 对 How to apply Deep Feature Synthesis to a single table 的回应相似。我遇到了一个例外,希望能得到一些帮助。
异常源自 featuretools.entityset.entity.entityset_convert_variable_type
,它似乎不处理时间类型。
异常的性质是什么,我可以解决它吗?
Table,df
:
PatientId | AppointmentID | Gender | ScheduledDay | AppointmentDay | Age | Neighbourhood | Scholarship | Hipertension | Diabetes | Alcoholism | Handcap | SMS_received | No-show
12345 | 5642903 | F | 2016-04-29 | 2016-04-29 | 62 | JARDIM DA | 0 | 1 | 0 | 0 | 0 | 0 | No
67890 | 3902943 | M | 2016-03-18 | 2016-04-29 | 44 | Other Nbh | 1 | 1 | 0 | 0 | 0 | 0 | Yes
...
我的代码:
appointment_entity_set = ft.EntitySet('appointments')
appointment_entity_set.entity_from_dataframe(
dataframe=df, entity_id='appointments',
index='AppointmentID', time_index='AppointmentDay')
# error generated here
appointment_entity_set.normalize_entity(base_entity_id='appointments',
new_entity_id='patients',
index='PatientId')
ScheduledDay 和 AppointmentDay 是 pandas._libs.tslib.Timestamp
类型,与 Max-Kanter's response 中的情况一样。
异常:
~/.virtualenvs/trane/lib/python3.6/site-packages/featuretools/entityset/entity.py in entityset_convert_variable_type(self, column_id, new_type, **kwargs)
474 df = self.df
--> 475 if df[column_id].empty:
476 return
477 if new_type == vtypes.Numeric:
Exception: Cannot convert column first_appointments_time to <class 'featuretools.variable_types.variable.DatetimeTimeIndex'>
featuretools==0.1.21
显示的错误似乎与 pandas 读取 AppointmentDay
变量的方式有关。实际上,我们有一个包含该数据集的示例 Kaggle kernel。在那里,我们需要使用 pandas.read_csv
和 parse_dates
:
data = pd.read_csv("data/KaggleV2-May-2016.csv", parse_dates=['AppointmentDay', 'ScheduledDay'])
那个 returns 一个 pandas 值类型为 numpy.datetime64
的系列。这应该可以很好地加载到 Featuretools。
另外,你能确定你有来自 pip 的最新版本的 Featuretools 吗?该堆栈跟踪中有一个不在最新版本中的设置跟踪命令。