一键运行baseline代码研读
- 数据清洗代码
train_df = train_power_forecast_history.groupby(['id_encode','ds']).head(1)代码片
作用:按照id和日期聚类,获得每天每个id第一个数据:
后续改进:
a)考虑对时间变化,sum获取所有一天24小时的数据。
b)考虑打上高地峰出行时间的标签。
train_df['flag'] = train_df['flag'].map({'A':0,'B':1})
test_df['flag'] = test_df['flag'].map({'A':0,'B':1})
作用:将flag字段映射为0,1
def get_time_feature(df, col):
df_copy = df.copy()
prefix = col + "_"
df_copy['new_'+col] = df_copy[col].astype(str)
col = 'new_'+col
df_copy[col] = pd.to_datetime(df_copy[col], format='%Y%m%d')
df_copy[prefix + 'year'] = df_copy[col].dt.year
df_copy[prefix + 'month'] = df_copy[col].dt.month
df_copy[prefix + 'day'] = df_copy[col].dt.day
# df_copy[prefix + 'weekofyear'] = df_copy[col].dt.weekofyear
df_copy[prefix + 'dayofweek'] = df_copy[col].dt.dayofweek
df_copy[prefix + 'is_wknd'] = df_copy[col].dt.dayofweek // 6
df_copy[prefix + 'quarter'] = df_copy[col].dt.quarter
df_copy[prefix + 'is_month_start'] = df_copy[col].dt.is_month_start.astype(int)
df_copy[prefix + 'is_month_end'] = df_copy[col].dt.is_month_end.astype(int)
del df_copy[col]
return df_copy
作用:获取时间,改进:添加其余时间标签,如是否是节假日
最后进行k-fold
其余改进:
- h3标签:使用h3获取城市相关标签,添加gdp等数据
- 去除去年数据的影响