我很难理解cutoff_dates的概念。我真正想要的是通过一个时间窗口来计算不同的特性,比如说60天前(没有当前事务(,cutoffdate看起来像是示例中硬编码的日期。我对每一行使用时间索引(下面的A_time(,根据这里的文档what_is_cutoff_datetime:
时间索引被定义为第一次可以使用行中的任何信息。如果在计算要素时指定了截止时间,则会自动忽略时间索引值较晚的行。
所以不清楚如果我不放截止日期,功能将被计算,直到时间索引值。
这是我的实体集定义:
es = ft.EntitySet('payment')
es = es.entity_from_dataframe(entity_id='tableA',
dataframe=tableA_dfpd,
index='paymentIndex',
time_index='A_time')
es.normalize_entity(base_entity_id='tableA',
new_entity_id='tableB',
index='B_index',
additional_variables=['B_x','B_time'],
make_time_index='B_time')
es.normalize_entity(base_entity_id='tableA',
new_entity_id='tableC',
index='C_index',
additional_variables=["C_x","C_date"],
make_time_index="C_date")
es.normalize_entity(base_entity_id='tableA',
new_entity_id='tableD',
index='D_index',
additional_variables=["D_x"],
make_time_index=False)
Entityset: payment
Entities:
tableA [Rows: 310083, Columns: 8]
tableB [Rows: 30296, Columns: 3]
tableC [Rows: 206565, Columns: 3]
tableD [Rows: 18493, Columns: 2]
Relationships:
tableA.B_index -> tableB.B_index
tableA.C_index -> tableC.C_index
tableA.D_index -> tableD.D_index
我到底该怎么做窗口计算?我是否需要通过截止日期?到dfs方法?我想使用所有基于A_time变量的窗口计算,对于截至当前事务的60天窗口,,所以实际上每个事务的截止日期都是该事务的time_A值,不是吗?
谢谢你的提问。您可以使用DFS中的培训窗口,根据时间窗口计算功能。您也可以通过设置include_cutoff_time=False
来排除截止时间的事务。我将使用这个事务数据集来介绍一个示例。
import featuretools as ft
df = ft.demo.load_mock_customer(return_single_table=True)
df = df[['transaction_id', 'transaction_time', 'customer_id', 'amount']]
df.sort_values(['customer_id', 'transaction_time'], inplace=True)
df.head()
transaction_id transaction_time customer_id amount
290 2014-01-01 00:44:25 1 21.35
275 2014-01-01 00:45:30 1 108.11
101 2014-01-01 00:46:35 1 112.53
80 2014-01-01 00:47:40 1 6.29
484 2014-01-01 00:48:45 1 47.95
首先,我们为交易和客户创建一个实体集。
es = ft.EntitySet()
es.entity_from_dataframe(
entity_id='transactions',
index='transaction_id',
time_index='transaction_time',
dataframe=df,
)
es.normalize_entity(
base_entity_id='transactions',
new_entity_id='customers',
index='customer_id',
)
es.add_last_time_indexes()
Entityset: None
Entities:
transactions [Rows: 500, Columns: 4]
customers [Rows: 5, Columns: 2]
Relationships:
transactions.customer_id -> customers.customer_id
然后,我们为每个客户在每个交易中创建一个截止时间。
cutoff_time = df[['customer_id', 'transaction_time']]
cutoff_time['time'] = cutoff_time.pop('transaction_time')
cutoff_time.head()
customer_id time
1 2014-01-01 00:44:25
1 2014-01-01 00:45:30
1 2014-01-01 00:46:35
1 2014-01-01 00:47:40
1 2014-01-01 00:48:45
现在,我们可以使用训练窗口运行DFS,以基于时间窗口计算特征。在本例中,我们将训练窗口设置为1小时。这将包括每个客户截止时间前1小时内的所有交易。
默认情况下,截止时间的交易也包括在计算中。我们可以通过设置include_cutoff_time=False
来排除这些事务。
fm, fd = ft.dfs(
target_entity='customers',
entityset=es,
cutoff_time=cutoff_time,
include_cutoff_time=False,
cutoff_time_in_index=True,
training_window='1h',
trans_primitives=[],
agg_primitives=['sum'],
verbose=True,
)
fm.sort_index().head()
SUM(transactions.amount)
customer_id time
1 2014-01-01 00:44:25 0.00
2014-01-01 00:45:30 21.35
2014-01-01 00:46:35 129.46
2014-01-01 00:47:40 241.99
2014-01-01 00:48:45 248.28
如果截止时间未传递给DFS,则每个客户的所有交易都包含在计算中。如果这有帮助,请告诉我。