Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prophet Python ValueError: Regressor missing from dataframe

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] 
like image 491
B..H Avatar asked Jul 14 '26 19:07

B..H


1 Answers

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

like image 122
Ganesh Jadhav Avatar answered Jul 16 '26 08:07

Ganesh Jadhav