python - 假日季节性在 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)
解决方案
这是熊猫的问题。您必须从 1.1.0(或更高版本)降级,因为它会破坏先知假期。有些人建议将 fbprophet 更新为 >= 0.7,但我在使用 pystan 时遇到了多个错误(使用 fbprophet 0.7.1)。我现在使用 pandas-1.0.5 和 Fbprophet 0.6。一切都按预期工作。
推荐阅读
- java - 无法在更改位置时绘制多边形
- apache-spark - 无法从 MacOS 上的终端运行 spark-shell
- python - 如何排除一个列丢失和另一个具有特定值的条件?
- unity3d - 有没有办法将 FULL 3D REAL WORLD TERRAIN 加载到 Unity 中?
- javascript - 如何动态添加 jquery 滑块,包括幻灯片功能?
- javascript - 当调用 javasript 文件在 Wordpress 中不起作用时
- python - 使用 pytest-mock 检查调用顺序
- c++ - 声明中的 * 在哪里写?
- amazon-dynamodb - DynamoDB 插入调用的 Vertx 超时
- cordova - HMS Cordova HMS 地图视图阻止了所有剩余的 UI