简体   繁体   中英

Holt-Winters forecast in R

I am trying to perform a Holt-Winters forecast in R and obtain predictions on the test data but the final forecast plot looks very wrong.

Where am I going wrong, why are the predictions so wild?

Data:

data("sunspots")

data <- as.data.frame(sunspots)



smp_size <- 0.80
train_ind <- nrow(data) * smp_size

train <- data[1:train_ind, ]
test <- data[(train_ind + 1):nrow(data), ]

fit <- HoltWinters(train, gamma=FALSE)

plot(forecast(fit, h = length(test)))

The sunspots data is actually a time series data which means that it has a period associated with it. If we use as.data.frame this converts it into a vector and information is lost. Hence, we keep this time series data, subset it and forecast.

Also, HoltWinters() requires a timeseries dataset as an input.

data("sunspots")

data <- sunspots


smp_size <- 0.80
train_ind <- length(data)/12 * smp_size
train = window(data,start = 1749, end = c(1749+train_ind,12))
test = window(data,start = 1749+train_ind+1,end = c(1749+length(data)/12,12))

fit <- HoltWinters(train)

plot(forecast(fit,h = length(test)))
lines(test)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM