2

我有一张桌子,上面有客户和交易。有没有办法获得在过去 3/6/9/12 个月内被过滤的功能?我想自动生成功能:

  • 过去 3 个月的跨性别人数
  • ……
  • 过去 12 个月的跨性别人数
  • 过去 3 个月的平均跨性别
  • ...
  • 过去 12 个月的平均跨性别

我试过使用training_window =["1 month", "3 months"],,但它似乎没有为每个窗口返回多个功能。

例子:

import featuretools as ft
es = ft.demo.load_mock_customer(return_entityset=True)

window_features = ft.dfs(entityset=es,
   target_entity="customers",
   training_window=["1 hour", "1 day"],
   features_only = True)

window_features

我是否必须单独执行单个窗口然后合并结果?

4

1 回答 1

3

正如您所提到的,在 Featuretools 0.2.1 中,您必须为每个训练窗口单独构建特征矩阵,然后合并结果。使用您的示例,您可以按以下方式执行此操作:

import pandas as pd
import featuretools as ft
es = ft.demo.load_mock_customer(return_entityset=True)
cutoff_times = pd.DataFrame({"customer_id": [1, 2, 3, 4, 5],
                             "time": pd.date_range('2014-01-01 01:41:50', periods=5, freq='25min')})
features = ft.dfs(entityset=es,
                  target_entity="customers",
                  agg_primitives=['count'],
                  trans_primitives=[],
                  features_only = True)
fm_1 = ft.calculate_feature_matrix(features, 
                                   entityset=es, 
                                   cutoff_time=cutoff_times,
                                   training_window='1h', 
                                   verbose=True)

fm_2 = ft.calculate_feature_matrix(features, 
                                   entityset=es, 
                                   cutoff_time=cutoff_times,
                                   training_window='1d', 
                                   verbose=True)
new_df = fm_1.reset_index()
new_df = new_df.merge(fm_2.reset_index(), on="customer_id", suffixes=("_1h", "_1d"))

然后,新的数据框将如下所示:

customer_id COUNT(sessions)_1h  COUNT(transactions)_1h  COUNT(sessions)_1d COUNT(transactions)_1d
1           1                   17                      3                 43
2           3                   36                      3                 36
3           0                   0                       1                 25
4           0                   0                       0                 0
5           1                   15                      2                 29
于 2018-08-16T14:32:40.633 回答