VN1 Forecasting - Accuracy Challenge Phase 1
Share:
Finished
competition-bg

VN1 Forecasting - Accuracy Challenge Phase 1

Flieber, Syrup Tech, and SupChains Launch an AI-Driven Supply Chain Forecasting Competition

VN1 Forecasting - Accuracy Challenge
Machine Learning/AI
Enterprise
E-commerce/Retail
Total Prize 20,000
Scroll To Top

Ivan Svetunkov · 26 September 2024

402
Copied!
8

Forecasts from ETS/iETS model

This notebook describes how ETS/iETS from the smooth package in R can be used to produce forecasts. The score is 0.613417419243

Description

Here is the R code for applying ETS/iETS (from this: https://openforecast.org/adam/) to the data and producing forecasts. The logic is as follows:

 

  1. Check how many non-zero values we have in the data. If we have more than 2, we will be able to apply iETS. If it is less, we just apply ETS(A,N,N).
  2. If we have more than two non-zero values, we need to check whether we have zeroes at all. If we don't have zeroes, we use the ETS with model selection.
  3. Detect stockouts using aid() function from the `greybox` package in R.
  4. If there are some stockouts, create dummy variables for them to treat them separately in the demand occurrence model, oes(). This way model will not react on them.
  5. Apply demand occurrence model, then use it in adam() to fit the full model.
  6. Produce final forecasts based on the selected model.

All calculations are done in parallel, I work on Linux, which is why I use doMC package. For Windows users, doParallel should be used instead. I have 32 threads (AMD Ryzen 9 3950), and the whole code execution took approximately 5 minutes on my PC.

 

library(doMC)
library(foreach)
library(greybox)
library(smooth)

h <- 13
registerDoMC(detectCores())
results <- foreach(i=1:ncol(VN1SalesT), .combine="rbind") %dopar% {
   # Extract a time series
   y <- VN1SalesT[-c(1:3),i]
   # If there is more than two in-sample non-zero observation, do things
   if(sum(y!=0)>2){
       # If there are any zeroes, use iETS
       if(any(y==0)){
           # Detect stockouts
           test <- aid(y)
           # Create a matrix with stockout dummies
           # The holdout is needed to produce correct forecasts for oes
           # We assume that no stockouts will happen in the holdout period
           xreg <- data.frame(y=c(as.vector(y),rep(NA,h)),
                              stockout=c(test$stockouts$dummy,rep(0,h)),
                              new=c(test$stockouts$new,rep(0,h)))
           # Fit the occurrence model
           oesModel <- oes(xreg$y, model="XXN", occurrence="direct", xreg=as.matrix(xreg)[,-1], holdout=TRUE, h=h)
           # Fit the final model
           test <- adam(y, "MNN", occurrence=oesModel, holdout=FALSE, h=h)
       }else{
           # Otherwise just do classical ETS model. lags=52 allows applying seasonal models
           test <- adam(y, "ZXZ", lags=52, holdout=FALSE, h=h)
       }
   }else{
       # If there is no more than two non-zero observation, fit ETS(A,N,N)
       test <- adam(y, "ANN", holdout=FALSE, h=h)
   }
   # Produce forecasts
   testForecast <- forecast(test, h=h, interval="none")
   return(testForecast$mean)
}
# Write down forecasts in a csv file
write.csv(results, file="Data/2024-09-24-Submission.csv")
      
      
    

Comments

Arnold Kakas

Posted 3 months ago
very interesting. would it be possible to get also preprocessing/full script after the competition? I would like to learn more once the competition is over.

Tejas Khandwekar

Posted 3 months ago
Didn't expect to see you here professor Ivan!
Join our private community in Discord

Keep up to date by participating in our global community of data scientists and AI enthusiasts. We discuss the latest developments in data science competitions, new techniques for solving complex challenges, AI and machine learning models, and much more!