【问题标题】:FeatureTools deal with aggregation like count(distinct day())FeatureTools 处理像 count(distinct day()) 这样的聚合
【发布时间】:2022-01-18 07:41:57
【问题描述】:

我正在通过功能工具处理数据,并在检查结果后。我发现 count distinct day() 可能比 count() 更好。但我是 ft 新手,找不到获得这些功能的方法。有什么想法吗?

a = pd.DataFrame({'ID1':['A01','A01','A02','A02','A02'],'ID2':['B02','B03','B04','B05','B06'],'f1':[1,1,2,2,2],'f2':[9,1,2,3,4],'f3':['click','end',"start",'click','end'],
'mytime':pd.to_datetime(['2021-01-20 14:44:00','2021-01-18 12:30:04','2021-01-13 11:33:31','2021-01-15 18:31:19','2021-01-19 21:09:32'])})
es = ft.EntitySet(id = 'test1')
es.entity_from_dataframe(entity_id = 'a', 
                         dataframe = a, 
                         index = 'ID2',
                         time_index='mytime')
es.normalize_entity(base_entity_id='a', 
                    new_entity_id='b', 
                    index = 'ID1', 
                    additional_variables = ['f1'])
feature_matrix, feature_names = ft.dfs(entityset=es, 
                                       target_entity = 'b', 
                                       max_depth = 6, 
                                       verbose = 1, 
                                       n_jobs = -1, 
                                       chunk_size = 100,
                                       agg_primitives=['count'],
                                       trans_primitives=['day'])
feature_matrix

似乎 dfs 在一天转换后不会自动计数。

【问题讨论】:

    标签: aggregation featuretools


    【解决方案1】:

    听起来您想应用不同的日期转换,然后在转换之上应用计数聚合。

    Featuretools 具有内置的 Day of the MonthDay of the Week 原语,可能适合您不同的一天转换。

    如果您在agg_primitives 中包含“count”,在trans_primitives 中包含“weekday”和“day”以用于您的dfs 调用,DFS 可能会自动生成您想要的功能(请注意,聚合原语需要两个数据帧通过关系链接)。此外,您可以使用dfs 中的seed_features 参数手动定义您想要的功能(参见documentation

    如果内置原语不适合您的不同日期转换,您可以编写自定义转换原语来应用您想要的功能。 Relevant guide

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多