Loading data into x ts object FOR E C ASTIN G P R OD U C T D E MAN D IN R Aric LaBarr , Ph . D . Senior Data Scientist , Elder Research
x ts objects eXtensible Time Series object B u ilds u pon z oo objects FORECASTING PRODUCT DEMAND IN R
Loading Data Into x ts Object A � ach a date inde x on to a data matri x Ver y eas y to manip u late ! FORECASTING PRODUCT DEMAND IN R
x ts objects Manip u lating Time Series Data in R w ith x ts & z oo Manip u lating Time Series Data in R : Case St u dies FORECASTING PRODUCT DEMAND IN R
Loading Data E x ample dates <- seq(as.Date("2014-01-19"), length = 176, by = "weeks") bev_xts <- xts(bev, order.by = dates) head(bev_xts[,"M.hi"], n = 3) M.hi 2014-01-19 458 2014-01-26 477 2014-02-02 539 FORECASTING PRODUCT DEMAND IN R
Let ' s practice ! FOR E C ASTIN G P R OD U C T D E MAN D IN R
ARIMA Time Series 101 FOR E C ASTIN G P R OD U C T D E MAN D IN R Aric LaBarr , Ph . D . Senior Data Scientist , Elder Research
Other co u rses on time series Time Series w ith R skill track FORECASTING PRODUCT DEMAND IN R
What is an ARIMA Model ? A u to R egressi v e Models I ntegrated M o v ing A v erage FORECASTING PRODUCT DEMAND IN R
Integrated - Stationarit y Does y o u r data ha v e a dependence across time ? Ho w long does this dependence last ? Stationarit y E � ect of an obser v ation dissipates as time goes on Best long term prediction is the mean of the series Commonl y achie v ed thro u gh di � erencing FORECASTING PRODUCT DEMAND IN R
Differencing T y picall y u sed to remo v e ... or seasonalit y Y − Y trend ... t −12 t Y − Y t −1 t FORECASTING PRODUCT DEMAND IN R
A u toregressi v e ( AR ) Piece A u toregressi v e Models Depend onl y on pre v io u s v al u es - called lags Y = ω + α Y + α Y + ... + ε 0 1 t −1 2 t −2 t t Long - memor y models - e � ect slo w l y dissipates FORECASTING PRODUCT DEMAND IN R
Mo v ing A v erage ( MA ) Piece Mo v ing A v erage Models Depend onl y on pre v io u s " shocks " or errors Y = ω + ε + β ε + β ε + ... 0 1 t −1 2 t −2 t t Short - memor y models - e � ects q u ickl y disappear completel y FORECASTING PRODUCT DEMAND IN R
Training v s . Validation M_t <- bev_xts[,"M.hi"] + bev_xts[,"M.lo"] FORECASTING PRODUCT DEMAND IN R
Training v s . Validation M_t_train <- M_t[index(M_t) < "2017-01-01"] M_t_valid <- M_t[index(M_t) >= "2017-01-01"] FORECASTING PRODUCT DEMAND IN R
Ho w to B u ild ARIMA Models ? auto.arima(M_t_train) Series: M_t_train ARIMA(4,0,1) with non-zero mean Coefficients: ar1 ar2 ar3 ar4 ma1 mean 1.3158 -0.5841 0.1546 0.0290 -0.6285 2037.5977 s.e. 0.3199 0.2562 0.1534 0.1165 0.3089 87.5028 sigma^2 estimated as 67471: log likelihood=-1072.02 AIC=2158.05 AICc=2158.81 BIC=2179.31 FORECASTING PRODUCT DEMAND IN R
Let ' s practice ! FOR E C ASTIN G P R OD U C T D E MAN D IN R
Forecasting FOR E C ASTIN G P R OD U C T D E MAN D IN R Aric LaBarr , Ph . D . Senior Data Scientist , Elder Research
Forecasting Goal of most time series models ! Models u se past v al u es or " shocks " to predict the f u t u re Pa � ern recognition follo w ed b y pa � ern repetition FORECASTING PRODUCT DEMAND IN R
Forecasting FORECASTING PRODUCT DEMAND IN R
Forecasting E x ample forecast_M_t <- forecast(M_t_model, h = 22) for_dates <- seq(as.Date("2017-01-01"), length = 22, by = "weeks") for_M_t_xts <- xts(forecast_M_t$mean, order.by = for_dates) plot(M_t_valid, main = 'Forecast Comparison') lines(for_M_t_xts, col = "blue") FORECASTING PRODUCT DEMAND IN R
FORECASTING PRODUCT DEMAND IN R
Ho w to E v al u ate Forecasts ? 2 Common Meas u res of Acc u rac y: 1. M ean A bsol u te E rror ( MAE ) n 1 ∑ ^ t ∣ Y − ∣ Y t n i =1 2. M ean A bsol u te P ercentage E rror ( MAPE ) ^ t n 1 Y − Y ∑ t ∣ ∣ × 100 n Y t i =1 FORECASTING PRODUCT DEMAND IN R
MAE and MAPE E x ample for_M_t <- as.numeric(forecast_M_t$mean) v_M_t <- as.numeric(M_t_valid) MAE <- mean(abs(for_M_t - v_M_t)) MAPE <- 100*mean(abs((for_M_t - v_M_t)/v_M_t)) print(MAE) [1] 198.7976 print(MAPE) [1] 9.576247 FORECASTING PRODUCT DEMAND IN R
Let ' s practice ! FOR E C ASTIN G P R OD U C T D E MAN D IN R
Recommend
More recommend