Is it possible to do multivariate multi-step forecasting using FB Prophet?

You can add additional variables in Prophet using the add_regressor method.

For example if we want to predict variable y using also the values of the additional variables add1 and add2.

Let’s first create a sample df:

import pandas as pd
df = pd.DataFrame(pd.date_range(start="2019-09-01", end="2019-09-30", freq='D', name="ds"))
df["y"] = range(1,31)
df["add1"] = range(101,131)
df["add2"] = range(201,231)
df.head()
            ds  y   add1 add2
0   2019-09-01  1   101 201
1   2019-09-02  2   102 202
2   2019-09-03  3   103 203
3   2019-09-04  4   104 204
4   2019-09-05  5   105 205

and split train and test:

df_train = df.loc[df["ds"]<"2019-09-21"]
df_test  = df.loc[df["ds"]>="2019-09-21"]

Before training the forecaster, we can add regressors that use the additional variables. Here the argument of add_regressor is the column name of the additional variable in the training df.

from fbprophet import Prophet
m = Prophet()
m.add_regressor('add1')
m.add_regressor('add2')
m.fit(df_train)

The predict method will then use the additional variables to forecast:

forecast = m.predict(df_test.drop(columns="y"))

Note that the additional variables should have values for your future (test) data. If you don’t have them, you could start by predicting add1 and add2 with univariate timeseries, and then predict y with add_regressor and the predicted add1 and add2 as future values of the additional variables.

From the documentation I understand that the forecast of y for t+1 will only use the values of add1 and add2 at t+1, and not their values at t, t-1, …, t-n as it does with y. If that is important for you, you could create new additional variables with the lags.

See also this notebook, with an example of using weather factors as extra regressors in a forecast of bicycle usage.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)