Bayesian Model forecasting is going of from what we are expecting

r
machine_learning
predictive_model

#1

We are having 5 years of monthly data of Quantity and we are trying forecast for next 2 years how the quantity will be ordered from one particluar customer. Model we used is bsts, we are unable to find the exact error. also can anyone pls expalin how to Add seasonal to the model.

Below is my code:

library(lubridate)
library(bsts)
library(dplyr)
library(ggplot2)
library(qtl)

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, season.duration = 365)
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”)

MAPE <- filter(d2, year(Date)>2015) %>% summarise(MAPE=mean(abs(Actual-Fitted)/Actual))