在Featuretools中创建实体集错误TypeError:'str'对象不支持项目分配

丹尼尔·加西亚·德切塞雷斯·赫兰

我有这3个数据框:

df_train cortado:____________________ 
    SK_ID_CURR  TARGET  NAME_CONTRACT_TYPE_Cash loans  \
0      100002       1                              1   
1      100003       0                              1   
2      100004       0                              0   
3      100006       0                              1   
4      100007       0                              1   

   NAME_CONTRACT_TYPE_Revolving loans  CODE_GENDER_F  CODE_GENDER_M  
0                                   0              0              1  
1                                   0              1              0  
2                                   1              0              1  
3                                   0              1              0  
4                                   0              0              1  

df_bureau cortado:____________________ 
    SK_ID_CURR  SK_ID_BUREAU  CREDIT_ACTIVE_Active
0      100002       5714464                     1
1      100002       5714465                     1
2      215354       5714466                     1
3      215354       5714467                     1
4      215354       5714468                     1

bureau_balance cortado 3:____________________ 
    SK_ID_BUREAU  MONTHS_BALANCE  STATUS_C
0       5715448               0         1
1       5715448              -1         1
2       5715448              -2         1
3       5715448              -3         1
4       5715448              -4         1 

这是我正在尝试运行以进行功能综合的脚本:

entities = {
    "train"          : (df_train,         "SK_ID_CURR"),
    "bureau"         : (df_bureau,        "SK_ID_BUREAU"),
    "bureau_balance" : (df_bureau_balance,"MONTHS_BALANCE", "STATUS", "SK_ID_BUREAU")                       , 
    }

relationships = [
    ("bureau", "SK_ID_BUREAU", "bureau_balance", "SK_ID_BUREAU"),
    ("train", "SK_ID_CURR", "bureau", "SK_ID_CURR")
             ]

feature_matrix_customers, features_defs = ft.dfs(entities=entities,
                                             relationships=relationships,
                                             target_entity="train"
                                             )

但是,一旦我引入“ STATUS”列,就会发生此错误:TypeError:“ str”对象不支持项目分配

如果我不输入“ STATUS”列,那么数据框的几行就可以了。当行数增加时(仅将STATUS作为键可以解决该问题),会发生其他错误:AssertionError:数据帧上的索引不是唯一的(Entity Bureau_balance)

提前致谢!!

意志

您是对的,因为数据框需要唯一索引才能成为实体。一个简单的选择是唯一索引添加到df_bureau_balance使用

df_bureau_balance.reset_index(inplace = True)

然后制作实体:

entities = {
    "train"          : (df_train,         "SK_ID_CURR"),
    "bureau"         : (df_bureau,        "SK_ID_BUREAU"),
    "bureau_balance" : (df_bureau_balance, "index")
    }

更好的选择是使用实体集来表示您的数据当我们从中创建实体时df_bureau_balance,因为它没有唯一的索引,所以我们传入make_index = True一个索引名称(如果它还不是数据中的列,则可以是任何名称。)其余的与您的非常相似使用稍微不同的语法即可工作!这是一个完整的工作示例:

# Create the entityset
es = ft.EntitySet('customers')

# Add the entities to the entityset
es = es.entity_from_dataframe('train', df_train, index = 'SK_ID_CURR')
es = es.entity_from_dataframe('bureau', df_bureau, index = 'SK_ID_BUREAU')
es = es.entity_from_dataframe('bureau_balance', df_bureau_balance, 
                               make_index = True, index = 'bureau_balance_index')

# Define the relationships
r_train_bureau = ft.Relationship(es['train']['SK_ID_CURR'], es['bureau']['SK_ID_CURR'])
r_bureau_balance = ft.Relationship(es['bureau']['SK_ID_BUREAU'], 
                                   es['bureau_balance']['SK_ID_BUREAU'])

# Add the relationships
es = es.add_relationships([r_train_bureau, r_bureau_balance])

# Deep feature synthesis
feature_matrix_customers, feature_defs = ft.dfs(entityset=es, target_entity = 'train')

实体集可帮助您以单一结构跟踪所有数据!Featuretools文档是越来越下降使用entitysets的基础,我会建议给它一个读好。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TypeError:'str'对象不支持项目分配,带有json文件的python

TypeError:'Tensor'对象不支持TensorFlow中的项目分配

TypeError:“范围”对象不支持项目分配

'str'对象不支持Python中的项目分配

对象不支持项目分配错误

'str'对象不支持Python中的项目分配

Python TypeError:“类型”对象不支持项目分配

错误:“浮动”对象不支持项目分配

TypeError:“ NodeView”对象不支持项目分配-NetworkX

TypeError:“类型”对象不支持项目分配

TypeError:“ int”对象不支持项目分配错误

TypeError:'str'对象不支持项目分配,熊猫操作

如何修复“ TypeError:'NoneType'对象不支持项目分配”

Lambda错误“ TypeError:'str'对象不支持项目分配回溯”

“ TypeError:'功能'对象不支持项目分配”

如何修复:TypeError'tuple'对象不支持项目分配

“'str'对象不支持项目分配”

TypeError:“ str”对象不支持项目分配

Python,TypeError:“ int”对象不支持项目分配”

'str'对象不支持项目分配telnetlib

TypeError /数组索引;'int'对象不支持项目分配

Python:TypeError:“ str”对象不支持项目分配

TypeError'set'对象不支持项目分配

Python:TypeError:'int' 对象不支持 MinMaxScaler 的项目分配

错误:“str”对象不支持项目分配

类型错误:“str”对象不支持项目分配熊猫添加列

类型错误:“str”对象不支持迭代中的项目分配

从 Python3 获取“'str'对象不支持项目分配”错误

Python 脚本... TypeError: 'method' 对象不支持项目分配