I'm working on a multivariate (100+ variables) multi-step (t1 to t30) forecasting problem where the time series frequency is every 1 minute. The problem requires to forecast one of the 100+ variables as target. I'm interested to know if it's possible to do it using FB Prophet's Python API. I was able to do it in a univariate fashion using only the target variable and the datetime variable. Any help and direction is appreciated. Please let me know if any further input or clarity is needed on the question.
问题:
回答1:
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.
回答2:
To do forecasting for more than one dependent variable you need to implement that time series using Vector Auto Regression.
In VAR model, each variable is a linear function of the past values of itself and the past values of all the other variables.
for more information on VAR go to https://www.analyticsvidhya.com/blog/2018/09/multivariate-time-series-guide-forecasting-modeling-python-codes/
回答3:
This might be late, however if you are reading this in 2019, you can implement multivariate time series using LSTM, Keras.