def test_cum_count(es): log_id_feat = es['log']['id'] cum_count = CumCount(log_id_feat, es['log']['session_id']) features = [cum_count] pandas_backend = PandasBackend(es, features) df = pandas_backend.calculate_all_features(instance_ids=range(15), time_last=None) cvalues = df[cum_count.get_name()].values assert len(cvalues) == 15 cum_count_values = [1, 2, 3, 4, 5, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3] for i, v in enumerate(cum_count_values): assert v == cvalues[i]
def test_cum_handles_uses_full_entity(es): def check(feature): pandas_backend = PandasBackend(es, [feature]) df_1 = pandas_backend.calculate_all_features(instance_ids=[0, 1, 2], time_last=None) df_2 = pandas_backend.calculate_all_features(instance_ids=[2], time_last=None) # check that the value for instance id 2 matches assert (df_2.loc[2] == df_1.loc[2]).all() for primitive in [CumSum, CumMean, CumMax, CumMin]: check(primitive(es['log']['value'], es['log']['session_id'])) check(CumCount(es['log']['id'], es['log']['session_id']))
verbose = 1, target_entity='WIP', agg_primitives=[], trans_primitives=['cum_sum', 'cum_count'], groupby_trans_primitives=['cum_sum', 'cum_count'], #累積總計、累積總數 ignore_variables={'WIP': ['PRIORITY']} ) feature_matrix # %% from featuretools.primitives import CumCount #累績總數 cum_count = CumCount() cum_count([1, 2, 3, 4, None, 5]).tolist() # %% from featuretools.primitives import CumCount from featuretools.primitives import IsWeekend #累績總數 cum_count = CumCount() cum_count([1, 2, 3, 4, None, 5]).tolist() isWkend = IsWeekend() feature_matrix, features_list = ft.dfs(entityset=es, verbose = 1, target_entity='WIP', agg_primitives=[], trans_primitives=['cum_sum','cum_count','is_weekend'],