B..H
B..H

Reputation: 39

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] 

Upvotes: 3

Views: 6656

Answers (3)

Ник 1
Ник 1

Reputation: 1

You should also consider the holiday and seasonal settings! this affects the outcome of the prophet.

m.add_regressor('aab', prior_scale=None, standardize='auto', mode='multiplicative')
m.add_regressor('aba', prior_scale=None, standardize='auto', mode='multiplicative')
m.add_regressor('abb', prior_scale=None, standardize='auto', mode='multiplicative')
m.add_regressor('baa', prior_scale=None, standardize='auto', mode='multiplicative')
m.add_regressor('bab', prior_scale=None, standardize='auto', mode='multiplicative')
m.add_regressor('bba', prior_scale=None, standardize='auto', mode='multiplicative')
m.add_regressor('bbb', prior_scale=None, standardize='auto', mode='multiplicative')
m.fit(train_df)

future = m.make_future_dataframe(periods=predictions)  # Прогноз на 30 дней вперед
future['aab'] = df_o['aab'].values  # Добавьте значения 'r2' из тестового набора данных
future['aba'] = df_o['aba'].values
future['abb'] = df_o['abb'].values
future['baa'] = df_o['baa'].values
future['bab'] = df_o['bab'].values
future['bba'] = df_o['bba'].values
future['bbb'] = df_o['bbb'].values
forecast = m.predict(future)

I did this

Upvotes: 0

Ganesh Jadhav
Ganesh Jadhav

Reputation: 802

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

Upvotes: 3

michelemihu
michelemihu

Reputation: 11

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

Upvotes: 1

Related Questions