首页 > 解决方案 > 假日季节性在 FBProphet 中全为零

问题描述

我正在尝试对具有多个随机分布峰值的时间序列进行预测。我确切地知道峰值何时出现,我用假期数据框告诉 Prophet。当我在拟合和预测之后查看组件时,假期都是零。有什么我想念的吗?

这是我正在运行的代码:

# create dummy data

from pandas import util
df= util.testing.makeTimeDataFrame(nper=150)
df['Amount']=np.random.randint(low=200, high=300, size=150)
df['ds']=df.index
df.drop(['A','B','C','D'],axis=1,inplace=True)
df.loc['2000-02-14','Amount'] = np.random.randint(low=1200, high=1300, size=1)
df.loc['2000-02-15','Amount'] = np.random.randint(low=1200, high=1300, size=1)
df.loc['2000-02-16','Amount'] = np.random.randint(low=1200, high=1300, size=1)
df.loc['2000-02-17','Amount'] = np.random.randint(low=1200, high=1300, size=1)
df.loc['2000-02-18','Amount'] = np.random.randint(low=1200, high=1300, size=1)

# load holidays dataframe
holidays=pd.DataFrame([['2000-02-14','Forbes Article ']],columns=['ds','holiday'])
holidays['ds']=pd.to_datetime(holidays['ds'])

# instantiate Prophet model
model1=Prophet(holidays=holidays)

# log transform the y variable to try to convert from non-stationary to stationary
df['y']=np.log(df['Amount'])

# Split data between train and test
split=int(len(df) * 0.8) 
# Make train and test variables, with 'train, test'
train, test = df[0:split], df[split:len(df)]

# fit Prophet model with training data
model1.fit(train)

# run predict on all data - test and train
forecast = model1.predict(df)

# plot outcomes
model1.plot_components(forecast)

标签: pythonfacebook-prophetpython-holidays

解决方案


这是熊猫的问题。您必须从 1.1.0(或更高版本)降级,因为它会破坏先知假期。有些人建议将 fbprophet 更新为 >= 0.7,但我在使用 pystan 时遇到了多个错误(使用 fbprophet 0.7.1)。我现在使用 pandas-1.0.5 和 Fbprophet 0.6。一切都按预期工作。


推荐阅读