Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

Bayesian Model forecasting is going of from what we are expecting

$
0
0

@keerthi8280 wrote:

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))

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles