葛冬冬斯坦福专业_比较预测模型的表现冬冬与有马

葛冬冬斯坦福专业

This is the third in a series of articles I am writing on time series forecasting models. The first article was a real-world application of time series forecasting that I did with US housing market data, with the purpose of demonstrating how forecasting is implemented and interpreted. In the second article, I outlined 5 simple steps to build a forecasting model aiming at beginners who have never done forecasting before. In today’s article, I’m going to show how two different techniques can be applied to the same dataset and how to evaluate and compare their performance.

这是我撰写的有关时间序列预测模型的系列文章中的第三篇。 第一篇文章是我对美国住房市场数据所做的时间序列预测实际应用,目的是演示如何实施和解释预测。 在第二篇文章中,我概述针对未曾进行过预测的初学者建立预测模型的5个简单步骤 。 在今天的文章中,我将展示如何将两种不同的技术应用于同一数据集,以及如何评估和比较它们的性能。

Among the many different forecasting techniques out there, I’ve picked 2 models to evaluate: ARIMA and Holt-Winters exponential smoothing. Before going any further I’ll briefly describe what they are and how they differ conceptually.

许多不同的预测技术中 ,我选择了两个模型进行评估:ARIMA和Holt-Winters指数平滑。 在继续之前,我将简要描述它们是什么以及它们在概念上的不同。

ARIMA (Autoregressive Integrated Moving Average): ARIMA is arguably the most popular and widely used statistical technique for forecasting. As the name suggests, ARIMA has 3 components: a) an Autoregressive component models the relationship between the series and its lagged values; b) the Moving Average component predicts future value as a function of lagged forecast errors; and c) the Integrated component makes the series stationary.

ARIMA(自回归综合移动平均线) ARIMA可以说是最流行和使用最广泛的统计技术来进行预测。 顾名思义,ARIMA有3个组成部分:a) 自回归组成部分对序列及其滞后值之间的关系进行建模; b) 移动平均线组件根据滞后的预测误差来预测未来价值; c) 集成组件使系列固定。

ARIMA model — represented as ARIMA(p, q, d) — takes the following parameters:

ARIMA模型(表示为ARIMA(p,q,d))具有以下参数:

  • p that defines the number of lags;

    p定义滞后数;

  • d that specifies the number of differences used; and

    d指定使用的差异数; 和

  • q that defines the size of moving average window

    q定义移动平均窗口的大小

Holt-Winters: it is another suit of techniques that also uses historical values. However, a key distinguishing feature is the so-called “exponential smoothing”.

Holt-Winters:这是另一套使用历史价值的技术。 但是,关键的区别特征是所谓的“指数平滑”。

If decomposed, a time series will disaggregate into 3 components: trend, seasonality, and white noise (i.e., random data points). For forecasting purposes, we can predict the predictable components (i.e., trend and seasonality), but not the unpredictable terms which occur in a random fashion. Exponential smoothing can handle this kind of variability within a series by smoothing out white noise. A Moving Average can smooth training data, but it does so by taking an average of past values and by weighting them equally. On the other hand, in Exponential Smoothing, the past observations are weighted in an exponentially decreasing order. Meaning, most recent observations are given higher weights than far-away values.

如果分解,则时间序列将分解为3个组成部分:趋势,季节性和白噪声(即随机数据点)。 出于预测目的,我们可以预测可预测的组成部分(即趋势和季节性),但不能预测以随机方式出现的不可预测的术语。 指数平滑可以通过平滑白噪声来处理一系列此类变化。 移动平均值可以使训练数据平滑,但是可以通过对过去值进行平均并对其进行平均加权来实现。 另一方面,在指数平滑中,过去的观测值以指数递减的顺序加权。 意思是,最近的观测值被赋予比远处的值更高的权重。

Now let’s dive right into implementing, comparing and evaluating these two forecasting techniques.

现在,让我们深入研究实现,比较和评估这两种预测技术。

资料准备 (Data preparation)

I am doing this exercise in a way that you don’t have to look for external datasets. I’ve included a subset of the US residential housing data — a real-world and recent dataset — below you so you could just copy them in your program. You should be able to follow along and reproduce everything from here to the end just fine.

我这样做的方式是您不必寻找外部数据集。 我在下面包括了一部分美国住宅数据(真实世界和最新数据集),因此您可以在程序中复制它们。 您应该能够跟随并从头到尾重现一切。

I am doing this implementation in R programming environment with fpp2 forecasting package developed by Rob J. Hyndman.

我正在用Rob J. Hyndman开发的fpp2预测包在R编程环境中执行此实现。

# required package
library(fpp2)# data
values = c(92.1, 92.6, 89.5, 80.9, 95.6, 72.5, 71.2, 78.8, 73.8, 83.5, 97.9, 93.4, 98.0, 90.2, 96.7, 100.0, 103.6, 74.6, 78.9, 92.0, 83.4, 98.1, 109.9, 102.2, 102.1, 96.2, 106.9, 95.1, 113.4, 84.0, 88.6, 94.9, 94.7, 105.7, 108.6, 101.9, 113.9, 100.9, 100.2, 91.9, 99.6, 87.2, 92.1, 104.9, 103.4, 103.3, 103.9, 108.5)# time series
time_series = ts(values, start = 2015, frequency =12)

时间序列分解 (Time series decomposition)

Time series decomposition means deconstructing and visualizing the series into these component parts — trend, seasonality, and the random component.

时间序列分解意味着将序列分解并可视化为这些组成部分,即趋势,季节性和随机组成部分。

The trend and seasonality are predictable in time series and are easy to forecast. The random part is most interesting to me since this component actually determines the uncertainty in forecasting. The smaller the randomness the better the forecasting performance.

趋势和季节性在时间序列中是可预测的,并且易于预测。 随机部分对我来说最有趣,因为该部分实际上确定了预测的不确定性。 随机性越小,预测性能越好。

# decomposition
autoplot(decompose(time_series)) + ggtitle("Decomposition of the series") + theme(plot.title = element_text(size=8))
Image for post
Time series decomposition
时间序列分解

建模:ARIMA和HW (Modeling: ARIMA and HW)

You can parameterize ARIMA and Holt-Winter in many different ways but I am keeping it simple. The fpp2 package has auto.arima() function that optimizes the parameters itself, but of course you can tweak the parameters as you wish. On the Holt-Winters technique, I needed to specify whether seasonality will be additive or multiplicative. In both cases, I am doing forecasting for 60 steps ahead (h = 60), i.e., 5 years into the future.

您可以通过许多不同的方式对ARIMA和Holt-Winter进行参数设置,但我将其保持简单。 fpp2软件包具有auto.arima()函数,该函数本身可以优化参数,但是当然您可以根据需要调整参数。 在Holt-Winters技术上,我需要指定季节性是相加还是相乘。 在这两种情况下,我都在预测未来60步(h = 60),即未来5年。

# ARIMA
forecast_arima = auto.arima(predictor_series, seasonal=TRUE, stepwise = FALSE, approximation = FALSE)
forecast_arima = forecast(forecast_arima, h=60)# Holt-Winters
forecast_hw = hw(predictor_series, seasonal="multiplicative", h=60)

预测 (Forecasting)

Once you run the models, you are ready to check your forecasting results. You could check the results in a dataframe or visualize them in figures.

运行模型后,就可以检查预测结果了。 您可以在数据框中检查结果或以图形形式显示结果。

The fpp2 model has built-in visualization function authoplot() that creates ggplot style figures of time series data and forecast values. They allow you to visually inspect and determine model performance at a glance.

fpp2模型具有内置的可视化功能authoplot() ,可创建时间序列数据和预测值的ggplot样式图形。 它们使您可以直观地检查和确定模型性能。

# ARIMA
autoplot(predictor_series, series=" Historical data") +
autolayer(forecast_arima, series=" ARIMA Forecast") +
ggtitle(" ARIMA forecasting") +
theme(plot.title = element_text(size=8))# HW
autoplot(predictor_series, series=" Historical data") +
autolayer(forecast_hw, series="Holt-Winter forecast") +
ggtitle("HW Exponential Smoothing") +
theme(plot.title = element_text(size=8))
Image for post
Forecasting with model: ARIMA
用模型预测:ARIMA
Image for post
Forecasting with model: Holt-Winters
使用模型进行预测:Holt-Winters

模型评估 (Model evaluation)

Time for model evaluation. Visual inspection of the forecasting figures above does not show much difference in forecasting results, and it’s probably because of predictable seasonality and trend components. However, Holt-Winters does show (at least visually) a bit of higher uncertainty around the forecast values.

模型评估的时间。 目视检查上面的预测数字不会显示出太大的预测结果差异,这可能是由于可预测的季节性和趋势成分所致。 但是,Holt-Winters确实(至少在视觉上)在预测值周围显示出更高的不确定性。

But we can go beyond visual inspection and use quantitative metrics to evaluate performance. If you check out the model description and call the accuracy() function a bunch of information pops up. In the table below I am summarizing some key metrics that you might use to evaluate models.

但是我们可以超越目视检查,而可以使用定量指标来评估性能。 如果您查看模型描述并调用accuracy()函数,则会弹出一堆信息。 在下表中,我总结了一些可用于评估模型的关键指标。

# ARIMA
forecast_arima['model']
accuracy(forecast_arima)# HW
forecast_hw['model']
accuracy(forecast_hw)
Image for post

The metrics need to be carefully interpreted. In this case study, there are some differences in RMSE measurements on training data but the difference in MAE is not significant. In terms of AIC, ARIMA seems to be a better model. A note of caution: while AIC is great at comparing models within the same class (e.g. within ARIMA models), it should not be used to compare two very different model classes (e.g. ARIMA vs HW). I am just showing them here as a way to tell how it looks like in actual implementation.

指标需要仔细解释。 在本案例研究中,训练数据的RMSE测量值存在一些差异,但MAE的差异并不显着。 在AIC方面,ARIMA似乎是一个更好的模型。 注意事项:尽管AIC擅长比较同一类别(例如ARIMA模型)内的模型,但不应将其用于比较两种截然不同的模型类别(例如ARIMA与HW)。 我只是在这里展示它们,以说明实际实施中的情况。

All that being said, the final determination of an appropriate model needs to be carefully judged and selected based on quantitative model selection criteria as well as using domain knowledge.

综上所述,需要基于定量模型选择标准以及使用领域知识来仔细判断和选择合适模型的最终确定。

结论 (Conclusion)

The purpose of this article was to show different forecasting model implementation using the same dataset and to demonstrate how to evaluate model performance and select the one that is appropriate for a problem space. Here I’ve compared two models — ARIMA and Holt-Winters — but there is a whole range of other forecasting techniques that can be applied to a given dataset. I’d encourage you to go and find a different dataset and try different forecasting models to see how they perform in different implementations.

本文的目的是展示使用同一数据集的不同预测模型的实现,并演示如何评估模型性能并选择适合问题空间的模型。 在这里,我比较了ARIMA和Holt-Winters这两个模型,但是还有一系列其他预测技术可以应用于给定的数据集。 我鼓励您去寻找不同的数据集,并尝试不同的预测模型,以了解它们在不同实现中的表现。

翻译自: https://towardsdatascience.com/comparing-the-performance-of-forecasting-models-holt-winters-vs-arima-e226af99205f

葛冬冬斯坦福专业

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值