gpt4 book ai didi

python - FBProphet 在增长 ='logistic' python 时给出错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:08:54 24 4
gpt4 key购买 nike

这是我在 python 中使用 Fbprophet 库时遇到的代码数据和错误。

数据

   Timestamp     Open     High      Low        y    Volume  \
0 1519084800 11379.2 11388.9 11379.2 11388.9 0.083001
1 1519084860 11362.0 11362.0 11362.0 11362.0 0.017628
2 1519084920 11383.9 11395.0 11370.7 11393.0 3.023621
3 1519084980 11384.3 11399.0 11379.9 11387.3 2.979175
4 1519085040 11395.0 11400.0 11390.1 11390.1 1.430360

ds y_orig y_pred
0 2018-02-20 00:00:00 11388.9 9.340394
1 2018-02-20 00:01:00 11362.0 9.338030
2 2018-02-20 00:02:00 11393.0 9.340754
3 2018-02-20 00:03:00 11387.3 9.340254
4 2018-02-20 00:04:00 11390.1 9.340500

代码:

model = Prophet(growth='logistic')
model.fit(data);

#create 12 months of future data
future_data = model.make_future_dataframe(periods=1, freq = 'M')

#forecast the data for future data
forecast_data = model.predict(future_data)

错误:

---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-25-c41038b3c799> in <module>()
1 model = Prophet(growth='logistic')
----> 2 model.fit(data);
3
4 #create 12 months of future data
5 future_data = model.make_future_dataframe(periods=1, freq = 'M')

/usr/local/lib/python2.7/dist-packages/fbprophet/forecaster.pyc in fit(self, df, **kwargs)
776 self.history_dates = pd.to_datetime(df['ds']).sort_values()
777
--> 778 history = self.setup_dataframe(history, initialize_scales=True)
779 self.history = history
780 self.set_auto_seasonalities()

/usr/local/lib/python2.7/dist-packages/fbprophet/forecaster.pyc in setup_dataframe(self, df, initialize_scales)
242 df['floor'] = 0
243 if self.growth == 'logistic':
--> 244 assert 'cap' in df
245 df['cap_scaled'] = (df['cap'] - df['floor']) / self.y_scale
246

AssertionError:

请告诉我如何解决这个问题。

最佳答案

我认为您应该阅读实现growth='logistic' 的文档。在这里阅读 documentation .

现在关于您的问题。我想如果您只是将数据框制作或添加为 cap and floor 列,就可以解决这个问题。看看这个:

#considreing your dataframe
df = pandas.read_csv('yourCSV')
cap = df['High']
flr = df['Low']
df['cap'] = cap
df['floor'] = flr
model = Prophet(growth='logistic')
model.fit(data);

#create 12 months of future data
future_data = model.make_future_dataframe(periods=1, freq = 'M')
forecast_data['cap'] = cap
forecast_data['floor'] = flr
#forecast the data for future data
forecast_data = model.predict(future_data)

我想这一定会对你有所帮助。

关于python - FBProphet 在增长 ='logistic' python 时给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48925255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com