【问题标题】:Using multiple Ids in featuretools在功能工具中使用多个 ID
【发布时间】:2021-10-02 22:11:56
【问题描述】:

我有一个数据集,我想对其进行自动特征工程。然而它是基于时间序列的,所以为了让它工作,我必须使用 2 个东西作为 id,对象 id 和日期。

x = pd.DataFrame({'id': [1,2,1], 'date': [2012021,2032021,4052021], 'x1': [1,2,3]})
y = pd.DataFrame({'id': [1,2,1], 'date': [2012021,2032021,4052021], 'label': [3,2,1]})
entities = {"features": (x, ['id','date']), "labels": (y, ['id','date'])}
feature_matrix, features_defs = ft.dfs(entities=entities,target_entity="y")

当我运行它时,我得到了这个错误:

TypeError: unhashable type: 'list'

我该如何解决这个问题?

【问题讨论】:

    标签: python pandas feature-extraction featuretools


    【解决方案1】:

    您是对的,但是在这里,您应该为实体集创建唯一索引,然后在 dfs 中使用正确的索引 (id)。我会推荐这种方式:

    1. 创建单个数据框而不是两个
    data = pd.DataFrame({'id': [1,2,1], 'date': [2012021,2032021,4052021], 'x1': [1,2,3], 'label': [3,2,1]})
    
    1. 为列添加唯一索引
    data['index'] = data.index
    
    1. 创建实体集
    es = ft.EntitySet('My EntitySet')
    
    1. 从数据框创建实体(不使用两种索引)
    es.entity_from_dataframe(
        entity_id='main_data',
        dataframe=data,
        index='index',
        time_index='date'
    )
    
    1. 规范化它
    es.normalize_entity(
        base_entity_id='main_data',
        new_entity_id='observations',
        index='id',
        make_time_index=True
    )
    
    1. 创建功能(如果您不想使用默认设置,请不要忘记设置,例如聚合)
    feature_matrix, features_defs = ft.dfs(entityset=es, target_entity="main_data")
    

    可能有另一种甚至更好的方法来处理这个问题,请查看this github questionthis SO answer

    【讨论】:

      猜你喜欢
      • 2020-05-29
      • 2022-10-21
      • 1970-01-01
      • 2017-06-10
      • 2021-10-05
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      • 2018-09-24
      相关资源
      最近更新 更多