【问题标题】:The logics of the creation of aggregated features with featuretools使用特征工具创建聚合特征的逻辑
【发布时间】:2022-01-07 00:49:52
【问题描述】:
我有一个包含几列的数据集,包括 date、instance_id、numerical_x 和 categorical_y。我使用featuretools 包进行特征生成,因为它具有强大的考虑时间变化的能力。
我想要得到像mean(numerical_x groupby categorical_y) 这样的功能并将其合并到categorical_y 列上的主框架。我猜如何用featuretools 自己创建它 - 我的 EntitySet 应该是什么样子,应该包含哪些功能原语等等?
【问题讨论】:
标签:
python
machine-learning
feature-engineering
featuretools
【解决方案1】:
Featuretools 有一个原语 CumMean 可以用作 groupby 原语以及额外的 primitive_options 参数到 dfs 以获得您所描述的确切功能。可以在 here 中查看 Featuretools 文档中的示例。
对于您所描述的情况,如果您有一个数据框 df,则听起来您的 EntitySet 应该看起来像这样:
es = EntitySet()
es.add_dataframe(dataframe_name="my_dataframe",
dataframe=df,
index="instance_id"
)
那么你的 DFS 调用可以这样进行:
fm, f = ft.dfs(entityset=es,
target_dataframe_name='my_dataframe',
agg_primitives=[],
trans_primitives=[],
groupby_trans_primitives=['cum_mean'],
primitive_options={
'cum_mean': {'include_groupby_columns': {'my_dataframe': ['categorical_y']},
'include_columns': {'my_dataframe': ['numerical_x']}
}
})