【问题标题】:AttributeError: Parent variable '<Variable: user_id (dtype = numeric)>' is not the index of entity Entity: train Variables:AttributeError:父变量'<Variable:user_id(dtype = numeric)>'不是实体实体的索引:train变量:
【发布时间】:2019-12-30 14:11:17
【问题描述】:

我正在尝试基于两个数据框中相同的 2 列创建实体关系,但我收到标题中所述的错误。

在互联网上搜索了该问题,但找不到任何东西

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)

【问题讨论】:

  • 错误是说user_id 不是实体的主键。 FT 中的关系是一对多的,这就是为什么user_id 必须是主键

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


【解决方案1】:

我遇到了同样的问题。我相信这是到期了,因为一个数据集包含 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'])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-27
    • 2019-02-28
    • 2014-02-28
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-04
    • 1970-01-01
    相关资源
    最近更新 更多