Python 在Featuretools中使用多个训练窗口计算相同的特征

Python 在Featuretools中使用多个训练窗口计算相同的特征,python,pandas,feature-extraction,feature-engineering,featuretools,Python,Pandas,Feature Extraction,Feature Engineering,Featuretools,Featuretools已经支持处理多个截止时间 但正如您看到的,对于一个ID,会在多个时间点生成一个多索引。如何(可能通过枢轴?)获得所有的最小/最大/。。。生成的列前缀为last_x_days_MIN/MAX/。。。那么,每个截止窗口都有额外的功能吗 编辑所需的输出格式 initial feature 1、initial feature 2、time\u frame\u 1\u特征、time\u frame\u 1\u特征、time\u frame\u 2\u特征、time\u frame\

Featuretools已经支持处理多个截止时间

但正如您看到的,对于一个ID,会在多个时间点生成一个多索引。如何(可能通过枢轴?)获得所有的最小/最大/。。。生成的列前缀为last_x_days_MIN/MAX/。。。那么,每个截止窗口都有额外的功能吗

编辑所需的输出格式
initial feature 1、initial feature 2、time\u frame\u 1\u特征、time\u frame\u 1\u特征、time\u frame\u 2\u特征、time\u frame\u 2\u特征、time\u frame\u 2\u特征

您可以通过使用不同的
培训窗口
对ft.calculate\u feature\u matrix进行两次调用,并将生成的特征矩阵连接在一起,来实现这一点。比如说,

import featuretools as ft
import pandas as pd

entityset = ft.demo.load_retail()

cutoffs = pd.DataFrame({
      'customer_name': ["Micheal Nicholson", "Krista Maddox"],
      'cutoff_time': [pd.Timestamp('2011-10-14'), pd.Timestamp('2011-08-18')]
    })

feature_defs = ft.dfs(entityset=entityset,
                      target_entity='customers',
                      agg_primitives=["sum"],
                      trans_primitives=[],
                      max_features=1,
                      features_only=True)



fm_60_days = ft.calculate_feature_matrix(entityset=entityset,
                                         features=feature_defs,
                                         cutoff_time=cutoffs,
                                         training_window="60 days")

fm_30_days = ft.calculate_feature_matrix(entityset=entityset,
                                         features=feature_defs,
                                         cutoff_time=cutoffs,
                                         training_window="30 days")

fm_60_days.merge(fm_30_days, left_index=True, right_index=True, suffixes=("__60_days", "__30_days"))
上面的代码返回这个数据帧,其中我们使用过去60天和30天的数据计算相同的特性

                  SUM(order_products.quantity)__60_days  SUM(order_products.quantity)__30_days
customer_name                                                                                  
Krista Maddox                                        466                                    306
Micheal Nicholson                                    710                                    539

注意:此示例运行在最新版本的Featuretools(v0.3.1)上,其中我们更新了demo retail数据集,使其具有可解释的名称作为客户ID

您能告诉我们所需的输出应该是什么样子吗?编辑是否足够清晰?我可以问一下,为什么您不使用
ft.make_temporal_cutoffs
,而是指定
cutoff_time
?如果您想创建多个按时间均匀间隔的截止时间,您可以使用
ft.make_temporal_cutoffs
。这将控制您要使用数据的最后一个时间点,因此这可以与
训练窗口
结合使用,以限制您要使用数据的时间。@MaxKanter如果我得到正确的答案,我必须找到由此创建的重复特征,像所有一阶trans特征一样,将复制的特征从最终特征矩阵中删除?
import featuretools as ft
import pandas as pd

entityset = ft.demo.load_retail()

cutoffs = pd.DataFrame({
      'customer_name': ["Micheal Nicholson", "Krista Maddox"],
      'cutoff_time': [pd.Timestamp('2011-10-14'), pd.Timestamp('2011-08-18')]
    })

feature_defs = ft.dfs(entityset=entityset,
                      target_entity='customers',
                      agg_primitives=["sum"],
                      trans_primitives=[],
                      max_features=1,
                      features_only=True)



fm_60_days = ft.calculate_feature_matrix(entityset=entityset,
                                         features=feature_defs,
                                         cutoff_time=cutoffs,
                                         training_window="60 days")

fm_30_days = ft.calculate_feature_matrix(entityset=entityset,
                                         features=feature_defs,
                                         cutoff_time=cutoffs,
                                         training_window="30 days")

fm_60_days.merge(fm_30_days, left_index=True, right_index=True, suffixes=("__60_days", "__30_days"))
                  SUM(order_products.quantity)__60_days  SUM(order_products.quantity)__30_days
customer_name                                                                                  
Krista Maddox                                        466                                    306
Micheal Nicholson                                    710                                    539