Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FBProphet giving error when growth='logistic' python

Here is the code data and the error that I am facing while using Fbprophet library in python.

DATA

   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  

Code:

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)

Error:

---------------------------------------------------------------------------
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: 

Please let me know how I can resolve this issue.

like image 475
Jaffer Wilson Avatar asked Jan 03 '23 18:01

Jaffer Wilson


1 Answers

I think you should read the documentation for implementing the growth='logistic'. Here read the documentation.

Now regarding your issue. I guess it can be resolved if you just make or add the dataframe as cap and floor column. Check this out:

#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)   

I guess this will certainly help you.

like image 117
Amazing Things Around You Avatar answered Jan 12 '23 01:01

Amazing Things Around You