4

这是我在 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: 

请让我知道如何解决此问题。

4

2 回答 2

9

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

现在关于你的问题。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)   

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

于 2018-02-22T11:50:30.580 回答
0

如果您应该创建 12 个月的未来数据,我认为您应该使用 (periods=1, freq = 'Y')。不是'M'。如果您想使用“M”,请将句点更改为 12。

于 2021-07-03T05:29:23.050 回答