【发布时间】:2020-11-01 13:07:47
【问题描述】:
我被困住了。使用 Featuretools,我要做的就是创建一个新列,将我的数据集中的两列加在一起,创建一个“堆叠”的排序特征。对我数据集中的所有列执行此操作。
我的代码如下所示:
# Define the function
def feature_engineering_dataset(df):
es = ft.EntitySet(id = 'stockdata')
# Make the "Date" index an actual column cuz defining it as the index below throws
# a "can't find Date in index" error for some reason.
df = df.reset_index()
# Save some columns not used in Featuretools to concat back later
dates = df['Date']
tickers = df['Ticker']
dailychange = df['DailyChange']
classes = df['class']
dataframe = df.drop(['Date', 'Ticker', 'DailyChange', 'class'],axis=1)
# Define the entity
es.entity_from_dataframe(entity_id='data', dataframe=dataframe, index='Date') # Won't find Date so uses a numbered index. We'll re-define date as index later
# Pesky warnings
warnings.filterwarnings("ignore", category=RuntimeWarning)
warnings.filterwarnings("once", category=ImportWarning)
# Run deep feature synthesis
feature_matrix, feature_defs = ft.dfs(n_jobs=-2,entityset=es, target_entity='data',
chunk_size=0.015,max_depth=2,verbose=True,
agg_primitives = ['sum'],
trans_primitives = []
)
# Now re-add previous columnes because featuretools...
df = pd.concat([dates, tickers, feature_matrix, dailychange, classes], axis=1)
df = df.set_index(['Date'])
# Return our new dataset!
return(df)
# Now run that defined function
df = feature_engineering_dataset(df)
我不确定这里到底发生了什么,但我已将深度定义为 2,因此我的理解是,对于我的数据集中的每对列的组合,它都会创建一个新列,将两者相加在一起吗?
我的初始数据框形状有 3101 列,当我运行此命令时,它显示 Built 3098 features,而最终的 df 在连接后有 3098 列,这是不对的,它应该具有我所有的原始功能,加上工程设计的。
我怎样才能实现我所追求的目标?功能工具页面和 API 文档上的示例非常令人困惑,并且处理了很多过时的示例,例如“time_since_last”trans 原语和其他似乎不适用于此处的内容。谢谢!
【问题讨论】: