我有一个Prophet模型,可以预测公司的出货量。当我添加特殊事件(促销和节假日)时,它们似乎对模型的预测没有影响。难道我做错了什么?在我检查的所有示例中,假期始终会对先知模型产生影响。
from fbprophet.make_holidays import make_holidays_df
import datetime
country_name= 'ES'
festivos=make_holidays_df([2017,2018,2019,2020],'ES')
festivos['dia']=0
for index, row in festivos.iterrows():
festivos.loc[index,"dia"]='Festivo ' + str(datetime.datetime.weekday(festivos.iloc[index]["ds"]))
festivo2=pd.DataFrame({'holiday':festivos['dia'],'ds':festivos['ds'],'lower_window':-9,'upper_window':1,})
festivo1=pd.DataFrame({'holiday':festivos['holiday'],'ds':festivos['ds'],'lower_window':-9,'upper_window':1,})
festivo=pd.concat((festivo2,festivo1))
festivo=pd.DataFrame(festivo)
festivo
ph_home = Prophet(holidays=festivo)
ph_home.add_country_holidays(country_name='ES')
ph_home.fit(home_train)
fut_home= ph_home.make_future_dataframe(periods=6,freq='M')
pred_home=ph_home.predict(fut_home)
fig1 =ph_home.plot(pred_home)
a = add_changepoints_to_plot(fig1.gca(), ph_home, pred_home)
fig1=ph_home.plot_components(pred_home)
pd.concat([home_train.set_index('ds')['y'],pred_home.set_index('ds')['yhat']],axis=1).plot(figsize=(15,10))
答案 0 :(得分:0)
由于您每月汇总,因此喜欢它。请参阅最后的注释here。
With data that has been aggregated to weekly or monthly frequency, holidays that don’t fall on the particular date used in the data will be ignored