是否可以使用 FB Prophet 进行多元多步预测? [英] Is it possible to do multivariate multi-step forecasting using FB Prophet?

查看:90
本文介绍了是否可以使用 FB Prophet 进行多元多步预测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个多变量(100 多个变量)多步(t1 到 t30)预测问题,其中时间序列频率为每 1 分钟一次.该问题需要预测 100 多个变量之一作为目标.我很想知道是否可以使用 FB Prophet 的 Python API 来做到这一点.我能够以单变量方式仅使用目标变量和日期时间变量来完成它.任何帮助和方向表示赞赏.请让我知道是否需要对此问题进行进一步的输入或澄清.

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.

推荐答案

您可以使用 add_regressor 方法.

例如,如果我们想同时使用附加变量 add1add2 的值来预测变量 y.

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

让我们首先创建一个示例df:

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

拆分训练和测试:

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

在训练预测器之前,我们可以添加使用附加变量的回归器.这里add_regressor的参数是训练df中附加变量的列名.

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)

predict 方法将使用附加变量进行预测:

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

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

请注意,附加变量应具有您未来(测试)数据的值.如果没有,可以先用单变量时间序列预测 add1add2,然后用 add_regressor 预测 y 和预测的 add1add2 作为附加变量的未来值.

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.

从文档中我了解到,对于 t+1 的 y 的预测只会使用 t+ 时的 add1add2 的值1,而不是像 y 那样在 t、t-1、...、tn 处的值.如果这对您很重要,您可以使用滞后创建新的附加变量.

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.

这篇关于是否可以使用 FB Prophet 进行多元多步预测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆