Subscribe to DSC Newsletter

We are trying to forecast the quantity based on 5 years of monthly historical data. We used Bayesian model. It looks like our forecast is going a bit off.

data <- read.table(file="QTY5years.txt", sep="\t",header =FALSE)
data <- ts(data, start=c(2015,1), frequency=12)
Y
<- window(data, start=c(2015,1), end=c(2019,12))
y
<- log10(Y)
ss
<- AddLocalLinearTrend(list(), y)
ss
<- AddSeasonal(ss, y, nseasons = 12)
bsts.model <- bsts(y, state.specification = ss, niter = 500, ping=0, seed=2020)
burn
<- SuggestBurn(0.1, bsts.model)
p <- predict.bsts(bsts.model, horizon = 12, burn = burn, quantiles = c(.025, .975))
d2 <- data.frame( # fitted values and predictions
c
(10^as.numeric(-colMeans(bsts.model$one.step.prediction.errors[-(1:burn),])+y),
10^as.numeric(p$median)),
# actual data and dates as.numeric(data), as.Date(time(data)) )
names(d2) <- c("Fitted", "Actual", "Date")


Tags: R, data, learning, machine, science

Views: 261

Reply to This

Videos

  • Add Videos
  • View All

© 2019   Data Science Central ®   Powered by

Badges  |  Report an Issue  |  Privacy Policy  |  Terms of Service