FBProphet模型中的假期效应均为零

2024-10-03 17:14:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个预言家模型,可以预测一家公司的出货量。当我添加特殊事件(促销和假期)时,它们似乎对模型的预测没有影响。我做错什么了吗?在我检查的所有示例中,假期总是对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))

Holidays effect in my Prophet model

The DataFrame I am using to train the prophet model


Tags: dataframehomedatetimeindexmakeplotdsholidays
1条回答
网友
1楼 · 发布于 2024-10-03 17:14:54

看起来这是由于您每月的汇总。见最后一个注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

相关问题 更多 >