首页 > 解决方案 > 如何使用来自多个特征/列的值组合创建有趣的值

问题描述

我对功能工具相当陌生,并试图了解是否以及如何将有趣的值添加到使用多个功能生成的实体集中。

例如,我有一个包含两个实体的实体集:客户和交易。交易可以是借记或贷记 (c_d),并且可以发生在不同的消费类别 (tran_category) - 餐馆、服装、杂货等。

到目前为止,我能够为这些功能中的任何一个创建有趣的值,但不能从它们的组合中创建:

import featuretools as ft

x = ft.EntitySet()

x.entity_from_dataframe(entity_id = 'customers', dataframe = customer_ids, index = cust_id)
x.entity_from_dataframe(entity_id = 'transactions', dataframe = transactions, index = tran_id, time_index = 'transaction_date')

x_rel = ft.Relationship(x['parties']['cust_id'], x['transactions']['cust_id])
x.add_relationship(x_rel)

x['transactions']['d_c'].interesting_values = ['D', 'C']
x['transactions']['tran_category'].interesting_values = ['restaurants', 'clothing', 'groceries']

如何添加一个有趣的值,它结合了 c_d 和 tran_category 中的值?(即餐厅借记、杂货贷记、服装借记等)。然后,目标是使用 where_primitives 使用这些有趣的值来汇总交易金额、交易之间的时间等:

feature_matrix, feature_defs = ft.dfs(entityset = x, target_entity = 'customers', agg_primitives = list_of_agg_primitives, where_primitives = list_of_where_primitives, trans_primitives = list_of_trans_primitives, max_depth = 3)

标签: featuretools

解决方案


目前,没有办法做到这一点。

一种方法是创建一个d_c__tran_category包含所有可能组合的新列d_ctran_category然后向该列添加有趣的值。

x['transactions']['d_c__tran_category'].interesting_values = ['D_restaurants', 'C_restaurants', 'D_clothing', 'C_clothing','D_groceries', 'C_groceries']

推荐阅读