Go to Data Market. (Links to an external site.) Pick a time series of interest to you. For the time series data you selected, use neural nets to build forecasts. Interpret.
Exports = read.csv("/Users/austin/Desktop/Graduate\ School\ /Boston\ College/Spring\ Semster\ 2021/Predictive\ Analytics/Discussions/Week\ 5/EXPCH.csv")
Exports$DATE = as.Date(Exports$DATE)
#mutate(DATE = ymd(DATE)) %>%
#filter(DATE < ymd("2021-02-01")) %>%
#filter(DATE > ymd("2010-12-01"))
#as.numeric(Exports$EXPCH)
head(Exports)
## DATE EXPCH
## 1 2011-01-01 8017.792
## 2 2011-02-01 8383.310
## 3 2011-03-01 9563.728
## 4 2011-04-01 8000.503
## 5 2011-05-01 7849.159
## 6 2011-06-01 7867.005
Exports.ts = ts(Exports$EXPCH, start = 2011, frequency = 12)
Exports.train = ts(Exports.ts[1:96], start = 2011, frequency = 12)
Exports.test = ts(Exports.ts[97:108], start = 2019, frequency = 12) # 12 month test set
#snaive model
snaive.model = snaive(Exports.train)
snaive.forecast = forecast(snaive.model, h = 12)
summary(snaive.model)
##
## Forecast method: Seasonal naive method
##
## Model Information:
## Call: snaive(y = Exports.train)
##
## Residual sd: 1289.174
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 192.4734 1289.174 945.8892 1.294726 9.313116 1 0.7123777
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2019 9910.228 8258.085 11562.37 7383.493 12436.96
## Feb 2019 9741.753 8089.610 11393.90 7215.018 12268.49
## Mar 2019 12653.174 11001.031 14305.32 10126.440 15179.91
## Apr 2019 10510.478 8858.335 12162.62 7983.744 13037.21
## May 2019 10396.624 8744.481 12048.77 7869.890 12923.36
## Jun 2019 10858.295 9206.152 12510.44 8331.560 13385.03
## Jul 2019 10156.528 8504.385 11808.67 7629.793 12683.26
## Aug 2019 9280.892 7628.750 10933.04 6754.158 11807.63
## Sep 2019 9732.405 8080.262 11384.55 7205.670 12259.14
## Oct 2019 9187.534 7535.391 10839.68 6660.799 11714.27
## Nov 2019 8650.889 6998.746 10303.03 6124.154 11177.62
## Dec 2019 9210.488 7558.345 10862.63 6683.753 11737.22
## Jan 2020 9910.228 7573.745 12246.71 6336.885 13483.57
## Feb 2020 9741.753 7405.270 12078.24 6168.411 13315.10
## Mar 2020 12653.174 10316.691 14989.66 9079.832 16226.52
## Apr 2020 10510.478 8173.995 12846.96 6937.136 14083.82
## May 2020 10396.624 8060.141 12733.11 6823.282 13969.97
## Jun 2020 10858.295 8521.812 13194.78 7284.952 14431.64
## Jul 2020 10156.528 7820.045 12493.01 6583.186 13729.87
## Aug 2020 9280.892 6944.410 11617.38 5707.550 12854.23
## Sep 2020 9732.405 7395.922 12068.89 6159.062 13305.75
## Oct 2020 9187.534 6851.051 11524.02 5614.191 12760.88
## Nov 2020 8650.889 6314.406 10987.37 5077.547 12224.23
## Dec 2020 9210.488 6874.005 11546.97 5637.146 12783.83
snaive.accuracy = accuracy(snaive.forecast, Exports.test)
print(snaive.accuracy)
## ME RMSE MAE MPE MAPE MASE
## Training set 192.4734 1289.174 945.8892 1.294726 9.313116 1.000000
## Test set -1153.5031 1638.768 1418.0364 -13.961324 16.595837 1.499157
## ACF1 Theil's U
## Training set 0.7123777 NA
## Test set 0.4400204 1.114542
#Graph the results
autoplot(Exports.ts) +
autolayer(snaive.forecast, series = "snaive Forecast") +
autolayer(Exports.test, series = "Actual Exports")
ANN.model = nnetar(Exports.train)
ANN.forecast = forecast(ANN.model, 12)
summary(ANN.model)
## Length Class Mode
## x 96 ts numeric
## m 1 -none- numeric
## p 1 -none- numeric
## P 1 -none- numeric
## scalex 2 -none- list
## size 1 -none- numeric
## subset 96 -none- numeric
## model 20 nnetarmodels list
## nnetargs 0 -none- list
## fitted 96 ts numeric
## residuals 96 ts numeric
## lags 2 -none- numeric
## series 1 -none- character
## method 1 -none- character
## call 2 -none- call
ANN.accuracy = accuracy(ANN.forecast, Exports.test)
print(ANN.accuracy)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.409754 848.4736 615.4357 -0.6682556 6.038955 0.6506425
## Test set -1417.159143 1792.3256 1555.8751 -17.2055316 18.578504 1.6448809
## ACF1 Theil's U
## Training set 0.2512399 NA
## Test set 0.1369753 1.231204
#Graph the results
autoplot(Exports.ts) +
autolayer(ANN.forecast, series = "ANN Forecast") +
autolayer(Exports.test, series = "Actual Exports")