Flieber, Syrup Tech, and SupChains Launch an AI-Driven Supply Chain Forecasting Competition
This notebook describes how ETS/iETS from the smooth package in R can be used to produce forecasts. The score is 0.613417419243
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:
aid()
function from the `greybox` package in R.oes()
. This way model will not react on them.adam()
to fit the full 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")
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!
Arnold Kakas
Posted 3 months agoTejas Khandwekar
Posted 3 months ago