5.4 Forecast Evaluation Methods
Learning Outcomes
By the end of this section, you should be able to:
- Explain the nature of error in forecasting a time series.
- Compute common error measures for time series models.
- Produce prediction intervals in a forecasting example.
A time series forecast essentially predicts the middle of the road values for future terms of the series. For the purposes of prediction, the model considers only the trend and any cyclical or seasonal variation that could be detected within the known data. Although noise and random variation certainly do influence future values of the time series, their precise effects cannot be predicted (by their very nature). Thus, a forecasted value is the best guess of the model in the absence of an error term. On the other hand, error does affect how certain we can be of the model’s forecasts. In this section, we focus on quantifying the error in forecasting using statistical tools such as prediction intervals.
Forecasting Error
Suppose that you have a model for a given time series . Recall from Components of Time Series Analysis that the residuals quantify the error between the time series the model and serve as an estimate of the noise or random variation.
The better the fit of the model to the observed data, the smaller the values of will be. However, even very good models can turn out to be poor predictors of future values of the time series. Ironically, the better a model does at fitting to known data, the worse it may be at predicting future data. There is a danger of overfitting. (This term is defined in detail in Decision-Making Using Machine Learning Basics, but for now we do not need to go deeply into this topic.) A common technique to avoid overfitting is to build the model using only a portion of the known data, and then the model’s accuracy can be tested on the remaining data that was held out.
To discuss the accuracy of a model, we should ask the complementary question: How far away are the predictions from the true values? In other words, we should try to quantify the total error. There are several measures of error, or measures of fit, the metrics used to assess how well a model's predictions align with the observed data. We will only discuss a handful of them here that are most useful for time series. In each formula, refers to the term of the time series, and is the error between the actual term and the predicted term of the series.
- Mean absolute error (MAE): . A measure of the average magnitude of errors.
- Root mean squared error (RMSE): . A measure of the standard deviation of errors, penalizing larger errors more heavily than MAE does.
- Mean absolute percentage error (MAPE): . A measure of the average relative errors—that is, a percentage between the predicted values and the actual values (on average).
- Symmetric mean absolute percentage error (sMAPE): . Similar to MAPE, a measure of the average relative errors, but scaled so that errors are measured in relation to both actual values and predicted values.
Of these error measures, MAE and RMSE are scale-dependent, meaning that the error is in direct proportion to the data itself. In other words, if all terms of the time series and the model were scaled by a factor of , then the MAE and RMSE would both be multiplied by as well. On the other hand, MAPE and sMAPE are not scale-dependent. These measures of errors are often expressed as percentages (by multiplying the result of the formula by 100%). However, neither MAPE nor sMAPE should be used for data that is measured on a scale containing 0 and negative numbers. For example, it would not be wise to use MAPE or sMAPE as a measure of error for a time series model of Celsius temperature readings. For all of these measures of error, lower values indicate less error and hence more accuracy of the model. This is useful when comparing two or more models.
Prediction Intervals
A forecast is often accompanied by a prediction interval giving a range of values the variable could take with some level of probability. For example, if the prediction interval of a forecast is indicated to be 80%, then the prediction interval contains a range of values that should include the actual future value with a probability of 0.8. Prediction intervals were introduced in Analysis of Variance (ANOVA) in the context of linear regression, so we won’t get into the details of the mathematics here. The key point is that we want a measure of margin of error, (depending on ), such that future observations of the data will be within the interval with probability , where is a chosen level of confidence.
Here, we will demonstrate how to use Python to obtain prediction intervals.
The Python library statsmodels.tsa.arima.model contains functions for finding confidence intervals as well. Note that the command get_forecast is used here rather than forecast, as the former contains more functionality.
The forecast data (dashed curve) is now surrounded by a shaded region. With 80% probability, all future observations should fit into the shaded region. Of course, the further into the future we try to go, the more uncertain our forecasts will be, which is indicated by the wider and wider confidence interval region.
Project A – Smoothing out the Stock Market
Predicting the ups and downs of the stock market is a notoriously difficult task. On the other hand, if anyone could obtain accurate forecasts of future stock prices, then they could make a lot of money by buying up stocks at low prices and selling them later at higher prices. It is often useful just to predict whether the trend of a stock is upward or downward in the near future. In this project, you will use standard time series smoothing techniques to estimate trends in the S&P 500 Index.
Using the data set SP500.csv, perform multiple techniques to smooth the time series including simple moving averages with various window lengths and exponential moving averages.
- Produce SMA trendlines with window sizes 10, 30, 60, and 120. Graph the trendlines on the same set of axes as the original graph and describe the results. What happens to the trendline as the window size increases?
- Produce EMA trendlines with and . Graph the trendlines on the same set of axes as the original graph and describe the results. What happens to the trendline as the value of increases?
- Now compare your results from part a and part b. As a group, discuss the advantages and disadvantages of using SMA vs. EMA. What characteristics of the data are emphasized (or de-emphasized) by each method as the parameters (window size and , respectively) change.
Project B – ARIMA Analysis of Coal Consumption
As a group, explore the time series in the data set MonthlyCoalConsumption.xlsx.
- Find the smallest order of differencing so that the time series becomes stationary.
- Then run an ACF diagram and look for any spikes that might indicate periodicity of a seasonal component.
- Run ARIMA analysis of the time series using the parameters for and established by your findings about periodicity and stationarity, trying different values of . Evaluate the model’s accuracy by computing the AIC score for each combination of parameters.
- As a group, decide which parameters you think will give the most accurate forecast. Then forecast up to 30 time units into the future and produce confidence intervals for your forecasts. Interpret your results by indicating how likely your forecasts are to be within a range of values.