【发布时间】:2021-06-30 23:57:49
【问题描述】:
我正在尝试使用功能工具创建自定义原语 rolling-sum 功能,下面是代码:-
class RollingSumOnDatetime(TransformPrimitive):
"""Calculates the rolling sum on a Datetime time index column.
Description:
Given a list of values and a Datetime time index, return the rolling sum.
"""
name = "rolling_sum_on_datetime"
input_types = [Numeric, DatetimeTimeIndex]
return_type = Numeric
uses_full_entity = True
description_template = "the rolling sum of {} on {}"
def __init__(self, window=None,on=None):
self.window = window
self.on = on
def get_function(self):
def rolling_sum(to_roll, on_column):
"""method is passed a pandas series"""
# create a DataFrame that has the both columns in it
df = pd.DataFrame({to_roll.name: to_roll, on_column.name: on_column})
rolled_df = df.rolling(window=self.window, on=on_column.name).sum()
return rolled_df[to_roll.name]
return rolling_sum
feature_matrix, feature_defs = ft.dfs(
entityset=es,
n_jobs=10,
target_entity="contracts",
agg_primitives=agg_prim,
trans_primitives=trans_prim,
groupby_trans_primitives=[
RollingSumOnDatetime(window="5D", on=es["days"]["datetime"])
],
max_depth=2,
drop_contains=["contract_id", "merchant_id"],
)
代码的第一部分是自定义原语,第二部分我调用函数 它给出了错误:
ValueError: setting an array element with a sequence.
【问题讨论】:
标签: python featuretools