Reputation: 1
I'm trying to plot my training data using ARIMA with a dataset that has the dates from 2021/02/28 - 2022/03/22. But when I plot my training ARIMA, it plots 2021-2022, leaves a gap in the graph and starts predicting from 2027-2028 instead .
What am i doing wrong?
My code:
#load dataset [390 rows x 15 columns]
df = read_csv("data.csv")
#convert to time series and select the 4th column
ts <- ts(df[1:390,4], start = c(2021, 02), end = c(2022, 03), frequency = 52)
#train data (80-20)
train <- ts(ts[1:311], start = c(2021, 02), frequency = 52)
test <- ts(ts[312:390], start = c(2021, 011),frequency = 52)
#get summary
myarima <- auto.arima(train)
summary(myarima)
#plot training ARIMA data and original dataset
fc_arima1 <- forecast(myarima, 52)
autoplot(fc_arima1)
my attempt: weird arima plot
Upvotes: 0
Views: 164
Reputation: 31820
Your ts
object has 390 observations, but the last 336 are missing because you have set end
to be part way through the data set. With frequency of 52, there are only 54 observations between the start
of c(2021,02)
and the end
of c(2022,04)
.
You should also use either the window
or subset
functions to form the training and test sets, so you don't have to re-specify the time series attributes.
The following should work. I've assumed your start
date was wrong but your end
date was correct:
#convert to time series and select the 4th column
ts <- ts(df[1:390,4], end = c(2022, 04), frequency = 52)
#train data (80-20)
train <- subset(ts, end=311)
test <- subset(ts, start=312)
#fit model
myarima <- auto.arima(train)
summary(myarima)
#plot training ARIMA data and original dataset
fc_arima1 <- forecast(myarima, 52)
autoplot(fc_arima1)
Upvotes: 1