# Data partitioning (estimation & evaluation part)
Note: For the estimation/training part, set the end of your data based on the percentage of data partitioning. For example, there are 766 data points for COVID-19 in Selangor. I would like to reserve 99 percent of the data for the estimation part and the remaining for the evaluation part.
99% x 766 = 758.34, or 758 (after rounding off); thus, 758 will be the end of my estimation part. The evaluation part will start with data number 759.
estimation1 <- window(selangor, start = 1, end = 758) #99%
estimation2 <- window(selangor, start = 1, end = 751) #98%
estimation3 <- window(selangor, start = 1, end = 743) #97%
estimation4 <- window(selangor, start = 1, end = 735) #96%
estimation5 <- window(selangor, start = 1, end = 728) #95%
evaluation1 <- window(selangor, start = 759)
evaluation2 <- window(selangor, start = 752)
evaluation3 <- window(selangor, start = 744)
evaluation4 <- window(selangor, start = 734)
evaluation5 <- window(selangor, start = 729)
# Install packages (one-time only)
install.packages("fpp")
install.packages("forecast")
# Load packages (at the beginning of each RStudio session)
package_diperlukan <- c("forecast","fpp")
require(package_diperlukan)
lapply(package_diperlukan, require, character.only = TRUE)
Note: Please make sure your data set is free from missing values. Clean and transform your data if necessary before proceeding to the next step.
# Estimate model
naive1 <- naive(estimation1, h = length(evaluation1))
naive2 <- naive(estimation2, h = length(evaluation2))
naive3 <- naive(estimation3, h = length(evaluation3))
naive4 <- naive(estimation4, h = length(evaluation4))
naive5 <- naive(estimation5, h = length(evaluation5))
# Model summary
naive1
naive2
naive3
naive4
naive5
# Model accuracy
accuracy1 <- accuracy(naive1, evaluation1)
accuracy2 <- accuracy(naive2, evaluation2)
accuracy3 <- accuracy(naive3, evaluation3)
accuracy4 <- accuracy(naive4, evaluation4)
accuracy5 <- accuracy(naive5, evaluation5)
# Model accuracy
accuracy1
accuracy2
accuracy3
accuracy4
accuracy5
# Install packages (one-time only)
install.packages("fpp")
install.packages("forecast")
# Load packages (at the beginning of each RStudio session)
package_diperlukan <- c("forecast","fpp")
require(package_diperlukan)
lapply(package_diperlukan, require, character.only = TRUE)
Note: Please make sure your data set is free from missing values. Clean and transform your data if necessary before proceeding to the next step.
# Estimate model
mean1 <- meanf(estimation1, h = length(evaluation1))
mean2 <- meanf(estimation2, h = length(evaluation2))
mean3 <- meanf(estimation3, h = length(evaluation3))
mean4 <- meanf(estimation4, h = length(evaluation4))
mean5 <- meanf(estimation5, h = length(evaluation5))
# Model summary
mean1
mean2
mean3
mean4
mean5
# Model accuracy
accuracy1 <- accuracy(mean1, evaluation1)
accuracy2 <- accuracy(mean2, evaluation2)
accuracy3 <- accuracy(mean3, evaluation3)
accuracy4 <- accuracy(mean4, evaluation4)
accuracy5 <- accuracy(mean5, evaluation5)
# Model accuracy
accuracy1
accuracy2
accuracy3
accuracy4
accuracy5
# Install packages (one-time only)
install.packages("fpp")
install.packages("forecast")
# Load packages (at the beginning of each RStudio session)
package_diperlukan <- c("forecast","fpp")
require(package_diperlukan)
lapply(package_diperlukan, require, character.only = TRUE)
Note: Please make sure your data set is free from missing values. Clean and transform your data if necessary before proceeding to the next step.
# Estimate model
ets1 <- ets(estimation1)
ets2 <- ets(estimation2)
ets3 <- ets(estimation3)
ets4 <- ets(estimation4)
ets5 <- ets(estimation5)
# Model summary
ets1
ets2
ets3
ets4
ets5
# Model accuracy
predict_ets1 <- forecast.ets(ets1, h = length(evaluation1))
predict_ets2 <- forecast.ets(ets2, h = length(evaluation2))
predict_ets3 <- forecast.ets(ets3, h = length(evaluation3))
predict_ets4 <- forecast.ets(ets4, h = length(evaluation4))
predict_ets5 <- forecast.ets(ets5, h = length(evaluation5))
accuracy1 <- accuracy(predict_ets1, evaluation1)
accuracy2 <- accuracy(predict_ets2, evaluation2)
accuracy3 <- accuracy(predict_ets3, evaluation3)
accuracy4 <- accuracy(predict_ets4, evaluation4)
accuracy5 <- accuracy(predict_ets5, evaluation5)
# Model accuracy
accuracy1
accuracy2
accuracy3
accuracy4
accuracy5
# Install packages (one-time only)
install.packages("fpp")
install.packages("forecast")
# Load packages (at the beginning of each RStudio session)
package_diperlukan <- c("forecast","fpp")
require(package_diperlukan)
lapply(package_diperlukan, require, character.only = TRUE)
Note: Please make sure your data set is free from missing values. Clean and transform your data if necessary before proceeding to the next step.
# Estimate model
arima1 <- auto.arima(estimation1)
arima2 <- auto.arima(estimation2)
arima3 <- auto.arima(estimation3)
arima4 <- auto.arima(estimation4)
arima5 <- auto.arima(estimation5)
# Model summary
arima1
arima2
arima3
arima4
arima5
# Model accuracy
predict_arima1 <- forecast(arima1, h = length(evaluation1))
predict_arima2 <- forecast(arima2, h = length(evaluation2))
predict_arima3 <- forecast(arima3, h = length(evaluation3))
predict_arima4 <- forecast(arima4, h = length(evaluation4))
predict_arima5 <- forecast(arima5, h = length(evaluation5))
accuracy1 <- accuracy(predict_arima1, evaluation1)
accuracy2 <- accuracy(predict_arima2, evaluation2)
accuracy3 <- accuracy(predict_arima3, evaluation3)
accuracy4 <- accuracy(predict_arima4, evaluation4)
accuracy5 <- accuracy(predict_arima5, evaluation5)
# Model accuracy
accuracy1
accuracy2
accuracy3
accuracy4
accuracy5