3

I am trying to use the latest (2nd) 0.3 version of the Prophet package for Python.

My model should include an exogenous regressor, but I receive a ValueError stating that the indeed existing regressor is missing from dataframe. Is this a bug or what am I doing wrong?

#Random Dataset Preparation

import random
random.seed(a=1)

df = pandas.DataFrame(data = None, columns = ['ds', 'y', 'ex'], index = range(50))
datelist = pandas.date_range(pandas.datetime.today(), periods = 50).tolist()

y = numpy.random.normal(0, 1, 50)
ex = numpy.random.normal(0, 2, 50)

df['ds'] = datelist
df['y'] = y
df['ex'] = ex

#Model
prophet_model = Prophet(seasonality_prior_scale = 0.1)
Prophet.add_regressor(prophet_model, 'ex')
prophet_model.fit(df)
prophet_forecast_step = prophet_model.make_future_dataframe(periods=1)

#Result-df
prophet_x_df = pandas.DataFrame(data=None, columns=['Date_x', 'Res'], index = range(int(len(y))))

#Error
prophet_x_df.iloc[0,1] = prophet_model.predict(prophet_forecast_step).iloc[0,0] 
B..H
  • 39
  • 1
  • 4

2 Answers2

3

You need to first create a column with the regressor value which need to be present in both the fitting and prediction dataframes.
Refer prophet docs

Ganesh Jadhav
  • 712
  • 6
  • 22
1

make_future_dataframe generates a dataframe with ds column only. You need to add 'ex' column to prophet_forecast_step dataframe in order to use it as a regressor