输入数据中具有多个特征的时间序列预测
Time Series prediction with multiple features in the input data
假设我们有一个时间序列数据,其中包含过去两年的每日订单数:
我们可以使用 Python 的 statsmodels 库预测未来的订单:
fit = statsmodels.api.tsa.statespace.SARIMAX(
train.Count, order=(2, 1, 4),seasonal_order=(0,1,1,7)
).fit()
y_hat_avg['SARIMA'] = fit1.predict(
start="2018-06-16", end="2018-08-14", dynamic=True
)
结果(不要介意数字):
现在假设我们的输入数据有一些不寻常的增加或减少,因为假期或公司的促销活动。因此,我们添加了两列,分别说明每一天是否是 "holiday" 以及公司有过的一天 "promotion".
是否有一种方法(以及在Python中实现它的方法)使用这种新型输入数据并帮助模型理解异常值的原因,并通过提供预测未来的订单"holiday" 和 "promotion_day" 信息?
fit1.predict('2018-08-29', holiday=True, is_promotion=False)
# or
fit1.predict(start="2018-08-20", end="2018-08-25", holiday=[0,0,0,1,1,0], is_promotion=[0,0,1,1,0,1])
这个问题有不同的名称,例如 anomaly detection
、rare event detection
和 extreme event detection
。
虽然它不是来自 statsmodels
,但您可以使用 facebook 的 prophet 库进行时间序列预测,您可以在其中将具有重复事件的日期传递给您的模型。
参见 here。
试试这个(根据您的 problem/data 它可能有效也可能无效):
您可以将日期拆分为多个特征,例如星期几、月几、年月、年,它是月中的最后一天吗?是月中的第一天吗?还有更多,如果你想到它然后使用一些普通的 ML 算法,如随机森林或梯度提升树或神经网络(特别是为你的分类特征嵌入层,例如星期几)来训练你的模型。
SARIMAX
作为 SARIMA
模型的概括,旨在准确处理此问题。来自docs,
Parameters:
- endog (array_like) – The observed time-series process y;
- exog (array_like, optional) – Array of exogenous regressors, shaped
(nobs, k)
.
您可以将 holiday
和 promotion_day
作为大小为 (nobs, 2)
的数组传递给 exog
,这将告知模型其中一些的外生性质观察。
假设我们有一个时间序列数据,其中包含过去两年的每日订单数:
我们可以使用 Python 的 statsmodels 库预测未来的订单:
fit = statsmodels.api.tsa.statespace.SARIMAX(
train.Count, order=(2, 1, 4),seasonal_order=(0,1,1,7)
).fit()
y_hat_avg['SARIMA'] = fit1.predict(
start="2018-06-16", end="2018-08-14", dynamic=True
)
结果(不要介意数字):
现在假设我们的输入数据有一些不寻常的增加或减少,因为假期或公司的促销活动。因此,我们添加了两列,分别说明每一天是否是 "holiday" 以及公司有过的一天 "promotion".
是否有一种方法(以及在Python中实现它的方法)使用这种新型输入数据并帮助模型理解异常值的原因,并通过提供预测未来的订单"holiday" 和 "promotion_day" 信息?
fit1.predict('2018-08-29', holiday=True, is_promotion=False)
# or
fit1.predict(start="2018-08-20", end="2018-08-25", holiday=[0,0,0,1,1,0], is_promotion=[0,0,1,1,0,1])
这个问题有不同的名称,例如 anomaly detection
、rare event detection
和 extreme event detection
。
虽然它不是来自 statsmodels
,但您可以使用 facebook 的 prophet 库进行时间序列预测,您可以在其中将具有重复事件的日期传递给您的模型。
参见 here。
试试这个(根据您的 problem/data 它可能有效也可能无效):
您可以将日期拆分为多个特征,例如星期几、月几、年月、年,它是月中的最后一天吗?是月中的第一天吗?还有更多,如果你想到它然后使用一些普通的 ML 算法,如随机森林或梯度提升树或神经网络(特别是为你的分类特征嵌入层,例如星期几)来训练你的模型。
SARIMAX
作为 SARIMA
模型的概括,旨在准确处理此问题。来自docs,
Parameters:
- endog (array_like) – The observed time-series process y;
- exog (array_like, optional) – Array of exogenous regressors, shaped
(nobs, k)
.
您可以将 holiday
和 promotion_day
作为大小为 (nobs, 2)
的数组传递给 exog
,这将告知模型其中一些的外生性质观察。