【问题标题】:cutoff time and training window at featuretools特征工具的截止时间和训练窗口
【发布时间】:2018-11-17 01:24:10
【问题描述】:

假设我有两个数据集(对应于我的实体集中的两个实体):

第一个:客户(cust_id、姓名、生日、customer_since)
第二个:bookings(booking_id、service、chargeamount、booking_date)

现在我想创建一个数据集,其中包含由所有客户(无论他们何时成为客户)构建的特征,但仅限于过去两年的预订

如何使用“last_time_index”?我可以只为一个实体设置“last_time_index”吗?在这种情况下,仅适用于预订实体,因为我想要所有客户,但不是所有预订。

如果使用此代码创建功能:

feature_matrix, features = ft.dfs(entityset=es,
                              target_entity="customers",
                              cutoff_time= pd.to_datetime('30/05/2018'),
                              training_window = ft.Timedelta(2*365,"d"),
                              agg_primitives=["count"],
                              trans_primitives=["time_since","year"],
                              cutoff_time_in_index = True)

【问题讨论】:

    标签: featuretools


    【解决方案1】:

    实体的time_index 指定实例首次有效使用的时间。这样,您在设置时间索引时所做的选择会影响您的最终结果。根据您设置time_index 的方式,可以将ft.dfs 与您的示例中的设置完全相同,以获得所需的输出。这是一个类似于您描述的数据的玩具示例:

    bookings_df = pd.DataFrame()
    bookings_df['booking_id'] = [1, 2, 3, 4]
    bookings_df['cust_id'] = [1, 1, 2, 5]
    bookings_df['booking_date'] = pd.date_range('1/1/2014', periods=4, freq='Y')
    
    customer_df = pd.DataFrame()
    customer_df['cust_id'] = [1, 2, 5]
    customer_df['customer_since']  = pd.to_datetime(['2014-01-01', '2016-01-01', '2017-01-01'])
    
    es = ft.EntitySet('Bookings')
    es.entity_from_dataframe('bookings', bookings_df, 'booking_id', time_index='booking_date')
    es.entity_from_dataframe('customers', customer_df, 'cust_id')
    
    es.add_relationship(ft.Relationship(es['customers']['cust_id'], es['bookings']['cust_id']))
    

    在过去的四年里,我们设置了我们的bookings_df,每年举办一次活动。数据框如下所示:

        booking_id  cust_id  booking_date
    0    1           1        2014-12-31
    1    2           1        2015-12-31
    2    3           2        2016-12-31
    3    4           5        2017-12-31
    

    请注意,我们customers 设置时间索引,这意味着所有客户数据始终有效使用。在没有training_window 参数的情况下运行 DFS 将返回

             YEAR(customer_since)   COUNT(bookings)
    cust_id     
    1         2014                   2.0
    2         2016                   1.0
    5         2017                   1.0
    

    通过添加两年的training_window(如您的示例),我们只能看到使用前四个预订中的两个的结果:

             YEAR(customer_since)   COUNT(bookings)
    cust_id     
    1         2014                   0.0
    2         2016                   1.0
    5         2017                   1.0
    

    【讨论】:

      猜你喜欢
      • 2019-07-14
      • 2019-05-10
      • 2019-05-16
      • 2020-03-30
      • 2019-01-22
      • 2014-03-26
      • 2016-06-16
      • 2021-10-20
      • 2019-02-27
      相关资源
      最近更新 更多