The Algorithm Pattern Sequence based Forecasting (PSF) was first proposed by Martinez Alvarez, et al., 2008 and then modified and suggested improvement by Martinez Alvarez, et al., 2011. The technical detailes are mentioned in referenced articles. PSF algorithm consists of various statistical operations like:
This section discusses about the examples to introduce the use of the PSF package and to compare it with auto.arima() and ets() functions, which are well accepted functions in the R community working over time series forecasting techniques. The data used in this example are ’nottem’ and ’sunspots’ which are the standard time series dataset available in R. The ’nottem’ dataset is the average air temperatures at Nottingham Castle in degrees Fahrenheit, collected for 20 years, on monthly basis.
Similarly, ’sunspots’ dataset is mean relative sunspot numbers from 1749 to 1983, measured on monthly basis. First of all, the psf() function from PSF package is used to forecast the future values. For both datasets, all the recorded values except for the final year are considered as training data, and the last year is used for testing purposes. The predicted values for final year with psf() function for both datasets are now discussed.
## $predictions
## [1] 39.83125 38.96250 42.39375 46.41250 52.35000 58.12500 62.51250 61.21875
## [9] 56.69375 49.73750 42.55625 39.10625
##
## $k
## [1] 2
##
## $w
## [1] 1
## $predictions
## [1] 52.62500 49.27500 48.05000 56.97500 45.67500 45.95000 37.55000 45.05000
## [9] 46.00000 45.20000 39.32500 39.75000 33.53000 37.93000 36.22000 40.39000
## [17] 31.84000 30.03000 27.46000 24.65000 23.23000 27.61000 24.79000 18.80000
## [25] 22.12500 21.85000 24.30833 19.08333 20.89167 18.64167 19.27500 22.40000
## [33] 15.39167 18.62500 22.05000 17.08333 16.27143 15.01429 11.84286 13.35714
## [41] 14.88571 15.05000 14.47857 17.22857 17.25714 21.75714 23.02857 21.10714
##
## $k
## [1] 2
##
## $w
## [1] 6
To represent the prediction performance in plot format, the psf_plot() function is used as shown in the following code.
psf() with auto.arima() and
ets() functions:Example below shows the comparisons for psf(),
auto.arima() and ets() functions when using
the Root Mean Square Error (RMSE) parameter as metric, for ’sunspots’
dataset. In order to avail more accurate and robust comparison results,
error values are calculated for 5 times and the mean value of error
values for methods under comparison are also shown. These values clearly
state that ‘psf()’ function is able to outperform the comparative time
series prediction methods. Additionally, the reader might want to refer
to the results published in the original work Martinez Alvarez et
al. (2011), in which it was shown that PSF outperformed many different
methods when applied to electricity prices and demand forecasting.
library(PSF)
library(forecast)
options(warn=-1)
## Consider data `sunspots` with removal of last years's readings
# Training Data
x <- sunspots[1:2772]
# Test Data
y <- sunspots[2773:2820]
PSF <- NULL
ARIMA <- NULL
ETS <- NULL
for(i in 1:5)
{
set.seed(i)
# for PSF
a <- psf(data = x, n.ahead = 48)$predictions
# for ARIMA
b <- forecast(auto.arima(x), 48)$mean
# for ets
c <- as.numeric(forecast(ets(x), 48)$mean)
## For Error Calculations
# Error for PSF
PSF[i] <- sqrt(mean((y - a)^2))
# Error for ARIMA
ARIMA[i] <- sqrt(mean((y - b)^2))
# Error for ETS
ETS[i] <- sqrt(mean((y - c)^2))
}
## Error values for PSF
PSF## [1] 61.08512 61.08512 61.08512 61.08512 61.08512
## [1] 61.08512
## [1] 103.0719 103.0719 103.0719 103.0719 103.0719
## [1] 103.0719
## [1] 70.66647 70.66647 70.66647 70.66647 70.66647
## [1] 70.66647
Martínez-Álvarez, F., Troncoso, A., Riquelme, J.C. and Ruiz, J.S.A., 2008, December. LBF: A labeled-based forecasting algorithm and its application to electricity price time series. In Data Mining, 2008. ICDM’08. Eighth IEEE International Conference on (pp. 453-461). IEEE.
Martinez Alvarez, F., Troncoso, A., Riquelme, J.C. and Aguilar Ruiz, J.S., 2011. Energy time series forecasting based on pattern sequence similarity. Knowledge and Data Engineering, IEEE Transactions on, 23(8), pp.1230-1243.