AttributeError:父变量'<Variable:user_id(dtype = numeric)>'不是实体Entity的索引:train变量:

时间:2019-08-26 11:25:07

标签: python-3.x entity-relationship featuretools

我试图基于两个数据帧中相同的2列创建实体关系,但出现标题中所述的错误。

在Internet上搜索了该问题,但找不到任何内容

es = es.entity_from_dataframe(entity_id="train", 
                              dataframe=df_es_train,
                              index="impression_id",
                              time_index="impression_time",
                              )

es = es.entity_from_dataframe(entity_id="viewlogs", 
                              dataframe=df_es_view_logs,
                              index="index",
                              time_index="server_time",
                              )

es = es.entity_from_dataframe(entity_id="itemdata", 
                              dataframe=df_es_item_data,
                              index="item_id",
                              )

new_relationship_1 = ft.Relationship(es["itemdata"]["item_id"],
                                   es["viewlogs"]["item_id"])
es = es.add_relationship(new_relationship_1)
new_relationship = ft.Relationship(es["train"]["user_id"],
                                   es["viewlogs"]["user_id"])
es = es.add_relationship(new_relationship)

实际结果是下面的错误,但这应该可以正常工作。

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-43-62d742a93d26> in <module>
 21 es = es.add_relationship(new_relationship_1)
 22 new_relationship = ft.Relationship(es["train"]["user_id"],
---> 23                                    es["viewlogs"]["user_id"])
 24 es = es.add_relationship(new_relationship)

D:\Anaconda3\envs\fastai\lib\site-packages\featuretools\entityset\relationship.py in __init__(self, parent_variable, child_variable)
 25         if (parent_variable.entity.index is not None and
 26                 parent_variable.id != parent_variable.entity.index):
---> 27             raise AttributeError("Parent variable '%s' is not the index of entity %s" % (parent_variable, parent_variable.entity))
 28 
 29     @classmethod

 AttributeError: Parent variable '<Variable: user_id (dtype = numeric)>' is not the index of entity Entity: train
 Variables:
   impression_id (dtype: index)
   impression_time (dtype: datetime_time_index)
   user_id (dtype: numeric)
   app_code (dtype: numeric)
   os_version (dtype: numeric)
is_4G (dtype: numeric)

形状:     (行:237609,列:6)

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。我相信这是由于一个数据集包含 100 000 行而另一个只有 30 000 行。因此,第一个数据集有 70 000 行没有 ID(您定义的特征工具索引)来匹配第二个数据集。

我的猜测是“连接”两个数据集以将它们的大小减少到 30 000 行。当然,当你有多个关系时,它会导致大量信息的删除,因为你需要减少所有数据集的大小。

如果我找到其他方式,我会在这里发布。

替代方法 1:我与此问题有 4 种关系。我通过反转第一个和最后一个参数来解决 3。

从这里

r_order_items_sellers = ft.Relationship(es['order_items']['seller_id'], es['sellers']['seller_id'])

为此

r_order_items_sellers = ft.Relationship(es['sellers']['seller_id'], es['order_items']['seller_id'])