首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在特性工具中计算多个训练窗口的特征

在特性工具中计算多个训练窗口的特征
EN

Stack Overflow用户
提问于 2018-08-15 19:35:45
回答 1查看 447关注 0票数 2

我有一张与客户和交易有关的桌子。有没有一种方法可以让功能在最后的3/6/9/12个月中被过滤?我想自动生成功能:

  • 过去3个月的跨性别人口数
  • ……
  • 过去12个月中的跨性别人口数
  • 过去3个月的平均运输量
  • ..。
  • 过去12个月的平均运输量

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

示例:

代码语言:javascript
运行
复制
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

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

EN

Stack Overflow用户

回答已采纳

发布于 2018-08-16 14:32:40

正如您所提到的,在Featuretools 0.2.1中,您必须为每个培训窗口分别构建特征矩阵,然后合并结果。使用您的示例,您可以这样做:

代码语言:javascript
运行
复制
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"))

然后,新的dataframe将如下所示:

代码语言:javascript
运行
复制
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
票数 3
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51865267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档