library("forecast")
## Warning: package 'forecast' was built under R version 4.4.3
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library("graphics")
library("TTR")
## Warning: package 'TTR' was built under R version 4.4.3
library("TSA")
## Warning: package 'TSA' was built under R version 4.4.3
## Registered S3 methods overwritten by 'TSA':
## method from
## fitted.Arima forecast
## plot.Arima forecast
##
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
##
## acf, arima
## The following object is masked from 'package:utils':
##
## tar
library("rio")
## Warning: package 'rio' was built under R version 4.4.3
library(readxl)
## Warning: package 'readxl' was built under R version 4.4.3
data <- read_excel("C:/Users/LENOVO/Downloads/Data_MPDW1.xlsx")
data
## # A tibble: 200 × 2
## Date AI_Revenue_USD_Mn
## <dttm> <dbl>
## 1 2023-11-28 00:00:00 128.
## 2 2023-11-29 00:00:00 129.
## 3 2023-11-30 00:00:00 129.
## 4 2023-12-01 00:00:00 129.
## 5 2023-12-02 00:00:00 129.
## 6 2023-12-03 00:00:00 129.
## 7 2023-12-04 00:00:00 129.
## 8 2023-12-05 00:00:00 129.
## 9 2023-12-06 00:00:00 129.
## 10 2023-12-07 00:00:00 129.
## # ℹ 190 more rows
View(data)
str(data)
## tibble [200 × 2] (S3: tbl_df/tbl/data.frame)
## $ Date : POSIXct[1:200], format: "2023-11-28" "2023-11-29" ...
## $ AI_Revenue_USD_Mn: num [1:200] 128 129 129 129 129 ...
dim(data)
## [1] 200 2
data.ts <- ts(data$AI_Revenue_USD_Mn)
Menampilkan ringkasan data
summary(data.ts)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 128.2 153.9 154.6 150.4 155.0 156.0
Membuat plot data deret waktu
ts.plot(data.ts, xlab = "Date", ylab = "Revenue",
main = "Time Series Plot",
ylim = c(120, 160)) # atur rentang Y
points(data.ts)
karena terdapat nilai ekstrim pada data, maka dilakukan pemotongan data dengan menghilangkan data pada tahun 2023 dan dimulai pada tahun 2024
# Ubah kolom pertama jadi tipe Date
data$Date <- as.Date(data$Date)
# Ambil hanya data tahun 2024
data_2024 <- subset(data, format(Date, "%Y") == "2024")
data1 <- data_2024
data1
## # A tibble: 166 × 2
## Date AI_Revenue_USD_Mn
## <date> <dbl>
## 1 2024-01-01 155.
## 2 2024-01-02 155.
## 3 2024-01-03 155.
## 4 2024-01-04 154.
## 5 2024-01-05 155.
## 6 2024-01-06 154.
## 7 2024-01-07 155.
## 8 2024-01-08 154.
## 9 2024-01-09 155.
## 10 2024-01-10 155.
## # ℹ 156 more rows
data.ts <- ts(data1$AI_Revenue_USD_Mn)
summary(data.ts)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 153.1 154.3 154.8 154.7 155.1 156.0
ts.plot(data.ts, xlab = "Date", ylab = "Revenue",
main = "Time Series Plot",
ylim = c(150, 160)) # atur rentang Y
points(data.ts)
# hitung jumlah data
n <- nrow(data1)
# tentukan batas 80%
n_train <- floor(0.8 * n)
# bagi data
training_ma <- data1[1:n_train, ]
testing_ma <- data1[(n_train+1):n, ]
# ubah ke time series
train_ma.ts <- ts(training_ma$AI_Revenue_USD_Mn)
test_ma.ts <- ts(testing_ma$AI_Revenue_USD_Mn)
plot(data.ts, col="red",main="Plot semua data")
points(data.ts)
plot(train_ma.ts, col="blue",main="Plot data latih")
points(train_ma.ts)
plot(test_ma.ts, col="blue",main="Plot data uji")
points(test_ma.ts)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.2
ggplot() +
geom_line(data = training_ma, aes(x = Date, y = AI_Revenue_USD_Mn, col = "Data Latih")) +
geom_line(data = testing_ma, aes(x = Date, y = AI_Revenue_USD_Mn, col = "Data Uji")) +
labs(x = "Periode Waktu", y = "Sales", color = "Legend") +
scale_colour_manual(name="Keterangan:", breaks = c("Data Latih", "Data Uji"),
values = c("blue", "red")) +
theme_bw() + theme(legend.position = "bottom",
plot.caption = element_text(hjust=0.5, size=12))
#Menghitung nilai keakuratan data latih
data.sma<-SMA(train_ma.ts, n=4)
data.sma
## Time Series:
## Start = 1
## End = 132
## Frequency = 1
## [1] NA NA NA 154.8100 154.6375 154.3725 154.3975 154.3600
## [9] 154.3900 154.6025 154.7325 154.7975 155.1225 155.1975 155.0375 155.2825
## [17] 154.6975 154.6025 154.6175 154.4250 154.7500 154.6850 154.8100 154.9425
## [25] 154.6925 154.7700 154.5500 154.5000 154.5950 154.5325 154.4875 154.7300
## [33] 154.9600 154.8500 155.0075 154.5725 154.4675 154.7800 154.3175 154.4225
## [41] 154.3225 154.2375 154.5750 154.6950 154.6575 154.4725 154.3875 154.4200
## [49] 154.8250 154.9775 155.1225 155.3250 155.2050 155.1600 155.2600 154.9900
## [57] 154.8000 154.8175 154.6050 154.7975 154.8525 154.7725 155.0700 155.0275
## [65] 155.0575 154.9750 154.8250 154.6975 154.8750 155.0725 155.0550 154.9450
## [73] 154.6525 154.6150 154.5500 154.9525 154.9125 154.8750 155.0050 154.7475
## [81] 154.8450 154.9400 154.9950 154.8425 154.8925 154.9300 154.8725 155.0775
## [89] 154.9250 154.9725 155.1725 155.0600 154.9700 154.7600 154.2775 154.0575
## [97] 154.3375 154.5675 154.8875 155.0625 154.6975 154.5625 154.2325 154.3300
## [105] 154.4125 154.2300 154.3775 154.4100 154.3300 154.1600 154.2100 154.1300
## [113] 154.5675 154.6975 154.5325 154.4300 154.3000 154.6025 154.8575 154.8375
## [121] 154.7775 154.3225 154.2800 154.3450 154.4550 154.9725 154.7000 154.7625
## [129] 154.6400 154.5850 154.5825 154.3450
data.ramal<-c(NA,data.sma)
data.ramal #forecast 1 periode ke depan
## [1] NA NA NA NA 154.8100 154.6375 154.3725 154.3975
## [9] 154.3600 154.3900 154.6025 154.7325 154.7975 155.1225 155.1975 155.0375
## [17] 155.2825 154.6975 154.6025 154.6175 154.4250 154.7500 154.6850 154.8100
## [25] 154.9425 154.6925 154.7700 154.5500 154.5000 154.5950 154.5325 154.4875
## [33] 154.7300 154.9600 154.8500 155.0075 154.5725 154.4675 154.7800 154.3175
## [41] 154.4225 154.3225 154.2375 154.5750 154.6950 154.6575 154.4725 154.3875
## [49] 154.4200 154.8250 154.9775 155.1225 155.3250 155.2050 155.1600 155.2600
## [57] 154.9900 154.8000 154.8175 154.6050 154.7975 154.8525 154.7725 155.0700
## [65] 155.0275 155.0575 154.9750 154.8250 154.6975 154.8750 155.0725 155.0550
## [73] 154.9450 154.6525 154.6150 154.5500 154.9525 154.9125 154.8750 155.0050
## [81] 154.7475 154.8450 154.9400 154.9950 154.8425 154.8925 154.9300 154.8725
## [89] 155.0775 154.9250 154.9725 155.1725 155.0600 154.9700 154.7600 154.2775
## [97] 154.0575 154.3375 154.5675 154.8875 155.0625 154.6975 154.5625 154.2325
## [105] 154.3300 154.4125 154.2300 154.3775 154.4100 154.3300 154.1600 154.2100
## [113] 154.1300 154.5675 154.6975 154.5325 154.4300 154.3000 154.6025 154.8575
## [121] 154.8375 154.7775 154.3225 154.2800 154.3450 154.4550 154.9725 154.7000
## [129] 154.7625 154.6400 154.5850 154.5825 154.3450
data.gab<-cbind(
aktual=c(data.ts),
pemulusan=c(data.sma,rep(NA,33)),
ramalan=c(data.ramal,rep(data.ramal[length(data.ramal)],32)))
## Warning in cbind(aktual = c(data.ts), pemulusan = c(data.sma, rep(NA, 33)), :
## number of rows of result is not a multiple of vector length (arg 2)
data.gab #forecast 24 periode ke depan
## aktual pemulusan ramalan
## [1,] 155.23 NA NA
## [2,] 155.12 NA NA
## [3,] 154.85 NA NA
## [4,] 154.04 154.8100 NA
## [5,] 154.54 154.6375 154.8100
## [6,] 154.06 154.3725 154.6375
## [7,] 154.95 154.3975 154.3725
## [8,] 153.89 154.3600 154.3975
## [9,] 154.66 154.3900 154.3600
## [10,] 154.91 154.6025 154.3900
## [11,] 155.47 154.7325 154.6025
## [12,] 154.15 154.7975 154.7325
## [13,] 155.96 155.1225 154.7975
## [14,] 155.21 155.1975 155.1225
## [15,] 154.83 155.0375 155.1975
## [16,] 155.13 155.2825 155.0375
## [17,] 153.62 154.6975 155.2825
## [18,] 154.83 154.6025 154.6975
## [19,] 154.89 154.6175 154.6025
## [20,] 154.36 154.4250 154.6175
## [21,] 154.92 154.7500 154.4250
## [22,] 154.57 154.6850 154.7500
## [23,] 155.39 154.8100 154.6850
## [24,] 154.89 154.9425 154.8100
## [25,] 153.92 154.6925 154.9425
## [26,] 154.88 154.7700 154.6925
## [27,] 154.51 154.5500 154.7700
## [28,] 154.69 154.5000 154.5500
## [29,] 154.30 154.5950 154.5000
## [30,] 154.63 154.5325 154.5950
## [31,] 154.33 154.4875 154.5325
## [32,] 155.66 154.7300 154.4875
## [33,] 155.22 154.9600 154.7300
## [34,] 154.19 154.8500 154.9600
## [35,] 154.96 155.0075 154.8500
## [36,] 153.92 154.5725 155.0075
## [37,] 154.80 154.4675 154.5725
## [38,] 155.44 154.7800 154.4675
## [39,] 153.11 154.3175 154.7800
## [40,] 154.34 154.4225 154.3175
## [41,] 154.40 154.3225 154.4225
## [42,] 155.10 154.2375 154.3225
## [43,] 154.46 154.5750 154.2375
## [44,] 154.82 154.6950 154.5750
## [45,] 154.25 154.6575 154.6950
## [46,] 154.36 154.4725 154.6575
## [47,] 154.12 154.3875 154.4725
## [48,] 154.95 154.4200 154.3875
## [49,] 155.87 154.8250 154.4200
## [50,] 154.97 154.9775 154.8250
## [51,] 154.70 155.1225 154.9775
## [52,] 155.76 155.3250 155.1225
## [53,] 155.39 155.2050 155.3250
## [54,] 154.79 155.1600 155.2050
## [55,] 155.10 155.2600 155.1600
## [56,] 154.68 154.9900 155.2600
## [57,] 154.63 154.8000 154.9900
## [58,] 154.86 154.8175 154.8000
## [59,] 154.25 154.6050 154.8175
## [60,] 155.45 154.7975 154.6050
## [61,] 154.85 154.8525 154.7975
## [62,] 154.54 154.7725 154.8525
## [63,] 155.44 155.0700 154.7725
## [64,] 155.28 155.0275 155.0700
## [65,] 154.97 155.0575 155.0275
## [66,] 154.21 154.9750 155.0575
## [67,] 154.84 154.8250 154.9750
## [68,] 154.77 154.6975 154.8250
## [69,] 155.68 154.8750 154.6975
## [70,] 155.00 155.0725 154.8750
## [71,] 154.77 155.0550 155.0725
## [72,] 154.33 154.9450 155.0550
## [73,] 154.51 154.6525 154.9450
## [74,] 154.85 154.6150 154.6525
## [75,] 154.51 154.5500 154.6150
## [76,] 155.94 154.9525 154.5500
## [77,] 154.35 154.9125 154.9525
## [78,] 154.70 154.8750 154.9125
## [79,] 155.03 155.0050 154.8750
## [80,] 154.91 154.7475 155.0050
## [81,] 154.74 154.8450 154.7475
## [82,] 155.08 154.9400 154.8450
## [83,] 155.25 154.9950 154.9400
## [84,] 154.30 154.8425 154.9950
## [85,] 154.94 154.8925 154.8425
## [86,] 155.23 154.9300 154.8925
## [87,] 155.02 154.8725 154.9300
## [88,] 155.12 155.0775 154.8725
## [89,] 154.33 154.9250 155.0775
## [90,] 155.42 154.9725 154.9250
## [91,] 155.82 155.1725 154.9725
## [92,] 154.67 155.0600 155.1725
## [93,] 153.97 154.9700 155.0600
## [94,] 154.58 154.7600 154.9700
## [95,] 153.89 154.2775 154.7600
## [96,] 153.79 154.0575 154.2775
## [97,] 155.09 154.3375 154.0575
## [98,] 155.50 154.5675 154.3375
## [99,] 155.17 154.8875 154.5675
## [100,] 154.49 155.0625 154.8875
## [101,] 153.63 154.6975 155.0625
## [102,] 154.96 154.5625 154.6975
## [103,] 153.85 154.2325 154.5625
## [104,] 154.88 154.3300 154.2325
## [105,] 153.96 154.4125 154.3300
## [106,] 154.23 154.2300 154.4125
## [107,] 154.44 154.3775 154.2300
## [108,] 155.01 154.4100 154.3775
## [109,] 153.64 154.3300 154.4100
## [110,] 153.55 154.1600 154.3300
## [111,] 154.64 154.2100 154.1600
## [112,] 154.69 154.1300 154.2100
## [113,] 155.39 154.5675 154.1300
## [114,] 154.07 154.6975 154.5675
## [115,] 153.98 154.5325 154.6975
## [116,] 154.28 154.4300 154.5325
## [117,] 154.87 154.3000 154.4300
## [118,] 155.28 154.6025 154.3000
## [119,] 155.00 154.8575 154.6025
## [120,] 154.20 154.8375 154.8575
## [121,] 154.63 154.7775 154.8375
## [122,] 153.46 154.3225 154.7775
## [123,] 154.83 154.2800 154.3225
## [124,] 154.46 154.3450 154.2800
## [125,] 155.07 154.4550 154.3450
## [126,] 155.53 154.9725 154.4550
## [127,] 153.74 154.7000 154.9725
## [128,] 154.71 154.7625 154.7000
## [129,] 154.58 154.6400 154.7625
## [130,] 155.31 154.5850 154.6400
## [131,] 153.73 154.5825 154.5850
## [132,] 153.76 154.3450 154.5825
## [133,] 155.29 NA 154.3450
## [134,] 154.98 NA 154.3450
## [135,] 155.29 NA 154.3450
## [136,] 154.43 NA 154.3450
## [137,] 154.62 NA 154.3450
## [138,] 155.30 NA 154.3450
## [139,] 154.52 NA 154.3450
## [140,] 154.00 NA 154.3450
## [141,] 155.04 NA 154.3450
## [142,] 154.30 NA 154.3450
## [143,] 155.20 NA 154.3450
## [144,] 155.18 NA 154.3450
## [145,] 155.77 NA 154.3450
## [146,] 153.72 NA 154.3450
## [147,] 154.83 NA 154.3450
## [148,] 154.48 NA 154.3450
## [149,] 154.43 NA 154.3450
## [150,] 154.51 NA 154.3450
## [151,] 155.43 NA 154.3450
## [152,] 155.33 NA 154.3450
## [153,] 154.91 NA 154.3450
## [154,] 154.26 NA 154.3450
## [155,] 154.28 NA 154.3450
## [156,] 154.72 NA 154.3450
## [157,] 154.94 NA 154.3450
## [158,] 154.58 NA 154.3450
## [159,] 155.87 NA 154.3450
## [160,] 154.21 NA 154.3450
## [161,] 154.41 NA 154.3450
## [162,] 155.23 NA 154.3450
## [163,] 154.53 NA 154.3450
## [164,] 154.71 NA 154.3450
## [165,] 155.03 NA 154.3450
## [166,] 155.83 NA NA
ts.plot(data.ts, xlab="Date ", ylab="Revenue", main= "SMA N=4 Data Sales")
points(data.ts)
lines(data.gab[,2],col="green",lwd=2)
lines(data.gab[,3],col="red",lwd=2)
legend("topleft",c("data aktual","data pemulusan","data peramalan"), lty=8, col=c("black","green","red"), cex=0.5)
#Menghitung nilai keakuratan data latih
error_train.sma = train_ma.ts-data.ramal[1:length(train_ma.ts)]
SSE_train.sma = sum(error_train.sma[5:length(train_ma.ts)]^2)
MSE_train.sma = mean(error_train.sma[5:length(train_ma.ts)]^2)
MAPE_train.sma = mean(abs((error_train.sma[5:length(train_ma.ts)]/train_ma.ts[5:length(train_ma.ts)])*100))
akurasi_train.sma <- matrix(c(SSE_train.sma, MSE_train.sma, MAPE_train.sma))
row.names(akurasi_train.sma)<- c("SSE", "MSE", "MAPE")
colnames(akurasi_train.sma) <- c("Akurasi m = 4")
akurasi_train.sma
## Akurasi m = 4
## SSE 51.8973563
## MSE 0.4054481
## MAPE 0.3279922
Dalam hal ini nilai MAPE data latih pada metode pemulusan SMA sekitar 0,3%, nilai ini dapat dikategorikan sebagai nilai akurasi yang sangat baik. Selanjutnya dilakukan perhitungan nilai MAPE data uji pada metode pemulusan SMA.
#Menghitung nilai keakuratan data uji
error_test.sma = test_ma.ts-data.gab[132.8:166,3]
SSE_test.sma = sum(error_test.sma^2)
MSE_test.sma = mean(error_test.sma^2)
MAPE_test.sma = mean(abs((error_test.sma/test_ma.ts*100)))
akurasi_test.sma <- matrix(c(SSE_test.sma, MSE_test.sma, MAPE_test.sma))
row.names(akurasi_test.sma)<- c("SSE", "MSE", "MAPE")
colnames(akurasi_test.sma) <- c("Akurasi m = 4")
akurasi_test.sma
## Akurasi m = 4
## SSE 16.5649812
## MSE 0.4872053
## MAPE 0.3561893
Perhitungan akurasi menggunakan data latih menghasilkan nilai MAPE yang kurang dari 10% sehingga nilai akurasi ini dapat dikategorikan sebagai sangat baik.
# jumlah baris data
n <- nrow(data1)
# hitung batas 80%
n_train <- floor(0.8 * n)
# bagi data
training <- data1[1:n_train, ]
testing <- data1[(n_train+1):n, ]
# ubah ke time series
train.ts <- ts(training$AI_Revenue_USD_Mn)
test.ts <- ts(testing$AI_Revenue_USD_Mn)
#Cara 1 (fungsi ses)
ses.1 <- ses(train.ts, h = 10, alpha = 0.2)
plot(ses.1)
ses.1
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 133 154.3801 153.6213 155.1388 153.2196 155.5405
## 134 154.3801 153.6063 155.1538 153.1967 155.5635
## 135 154.3801 153.5915 155.1686 153.1741 155.5860
## 136 154.3801 153.5771 155.1830 153.1520 155.6081
## 137 154.3801 153.5629 155.1973 153.1303 155.6299
## 138 154.3801 153.5489 155.2112 153.1089 155.6512
## 139 154.3801 153.5351 155.2250 153.0879 155.6722
## 140 154.3801 153.5216 155.2385 153.0672 155.6929
## 141 154.3801 153.5083 155.2518 153.0468 155.7133
## 142 154.3801 153.4952 155.2649 153.0268 155.7333
ses.2<- ses(train.ts, h = 10, alpha = 0.7)
plot(ses.2)
ses.2
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 133 153.8734 152.9857 154.7610 152.5158 155.2309
## 134 153.8734 152.7899 154.9568 152.2163 155.5304
## 135 153.8734 152.6244 155.1224 151.9632 155.7835
## 136 153.8734 152.4783 155.2684 151.7399 156.0068
## 137 153.8734 152.3462 155.4005 151.5378 156.2089
## 138 153.8734 152.2247 155.5220 151.3519 156.3948
## 139 153.8734 152.1115 155.6352 151.1788 156.5679
## 140 153.8734 152.0051 155.7416 151.0161 156.7306
## 141 153.8734 151.9045 155.8422 150.8623 156.8844
## 142 153.8734 151.8088 155.9379 150.7159 157.0308
autoplot(ses.1) +
autolayer(fitted(ses.1), series="Fitted") +
ylab("Revenue") + xlab("Date")
#Cara 2 (fungsi Holtwinter)
ses1<- HoltWinters(train.ts, gamma = FALSE, beta = FALSE, alpha = 0.2)
plot(ses1)
#ramalan
ramalan1<- forecast(ses1, h=10)
ramalan1
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 133 154.3801 153.6178 155.1423 153.2143 155.5458
## 134 154.3801 153.6027 155.1574 153.1912 155.5689
## 135 154.3801 153.5879 155.1722 153.1686 155.5915
## 136 154.3801 153.5734 155.1867 153.1464 155.6138
## 137 154.3801 153.5591 155.2010 153.1245 155.6356
## 138 154.3801 153.5451 155.2150 153.1031 155.6571
## 139 154.3801 153.5313 155.2288 153.0819 155.6782
## 140 154.3801 153.5177 155.2424 153.0612 155.6989
## 141 154.3801 153.5043 155.2558 153.0407 155.7194
## 142 154.3801 153.4911 155.2690 153.0206 155.7395
ses2<- HoltWinters(train.ts, gamma = FALSE, beta = FALSE, alpha = 0.7)
plot(ses2)
#ramalan
ramalan2<- forecast(ses2, h=10)
ramalan2
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 133 153.8734 152.9859 154.7608 152.5161 155.2306
## 134 153.8734 152.7901 154.9566 152.2166 155.5301
## 135 153.8734 152.6246 155.1221 151.9635 155.7832
## 136 153.8734 152.4786 155.2681 151.7402 156.0065
## 137 153.8734 152.3465 155.4002 151.5382 156.2085
## 138 153.8734 152.2250 155.5217 151.3523 156.3944
## 139 153.8734 152.1118 155.6349 151.1793 156.5674
## 140 153.8734 152.0054 155.7413 151.0166 156.7301
## 141 153.8734 151.9049 155.8418 150.8628 156.8839
## 142 153.8734 151.8092 155.9375 150.7164 157.0303
#SES
ses.opt <- ses(train.ts, h = 10, alpha = NULL)
plot(ses.opt)
ses.opt
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 133 154.579 153.8474 155.3105 153.4602 155.6978
## 134 154.579 153.8470 155.3110 153.4595 155.6984
## 135 154.579 153.8466 155.3114 153.4589 155.6991
## 136 154.579 153.8461 155.3118 153.4582 155.6998
## 137 154.579 153.8457 155.3123 153.4575 155.7004
## 138 154.579 153.8453 155.3127 153.4569 155.7011
## 139 154.579 153.8448 155.3131 153.4562 155.7018
## 140 154.579 153.8444 155.3136 153.4555 155.7024
## 141 154.579 153.8440 155.3140 153.4549 155.7031
## 142 154.579 153.8435 155.3144 153.4542 155.7037
#Lamda Optimum Holt Winter
HWopt<- HoltWinters(train.ts, gamma = FALSE, beta = FALSE,alpha = NULL)
HWopt
## Holt-Winters exponential smoothing without trend and without seasonal component.
##
## Call:
## HoltWinters(x = train.ts, alpha = NULL, beta = FALSE, gamma = FALSE)
##
## Smoothing parameters:
## alpha: 0.08621003
## beta : FALSE
## gamma: FALSE
##
## Coefficients:
## [,1]
## a 154.4859
plot(HWopt)
#ramalan
ramalanopt<- forecast(HWopt, h=10)
ramalanopt
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 133 154.4859 153.7421 155.2297 153.3483 155.6234
## 134 154.4859 153.7393 155.2325 153.3441 155.6277
## 135 154.4859 153.7366 155.2352 153.3399 155.6319
## 136 154.4859 153.7338 155.2379 153.3357 155.6361
## 137 154.4859 153.7311 155.2407 153.3315 155.6402
## 138 154.4859 153.7284 155.2434 153.3274 155.6444
## 139 154.4859 153.7257 155.2461 153.3232 155.6485
## 140 154.4859 153.7230 155.2488 153.3191 155.6527
## 141 154.4859 153.7203 155.2515 153.3150 155.6568
## 142 154.4859 153.7176 155.2542 153.3109 155.6609
#Keakuratan Metode
#Pada data training
# SES dengan alpha = 0.2
SSE1<-ses1$SSE
MSE1<-ses1$SSE/length(train.ts)
RMSE1<-sqrt(MSE1)
akurasi1 <- matrix(c(SSE1,MSE1,RMSE1))
row.names(akurasi1)<- c("SSE", "MSE", "RMSE")
colnames(akurasi1) <- c("Akurasi lamda=0.2")
akurasi1
## Akurasi lamda=0.2
## SSE 46.1264451
## MSE 0.3494428
## RMSE 0.5911368
# SES dengan alpha = 0.7
SSE2<-ses2$SSE
MSE2<-ses2$SSE/length(train.ts)
RMSE2<-sqrt(MSE2)
akurasi2 <- matrix(c(SSE2,MSE2,RMSE2))
row.names(akurasi2)<- c("SSE", "MSE", "RMSE")
colnames(akurasi2) <- c("Akurasi lamda=0.7")
akurasi2
## Akurasi lamda=0.7
## SSE 62.3700053
## MSE 0.4725000
## RMSE 0.6873864
# Menghitung nilai keakuratan data latih secara manual
# Alpha = 0.2
fitted1<-ramalan1$fitted
sisaan1<-ramalan1$residuals
head(sisaan1)
## Time Series:
## Start = 1
## End = 6
## Frequency = 1
## [1] NA -0.110000 -0.358000 -1.096400 -0.377120 -0.781696
resid1<-training$AI_Revenue_USD_Mn-ramalan1$fitted
head(resid1)
## Time Series:
## Start = 1
## End = 6
## Frequency = 1
## [1] NA -0.110000 -0.358000 -1.096400 -0.377120 -0.781696
SSE.1=sum(sisaan1[2:length(train.ts)]^2)
SSE.1
## [1] 46.12645
MSE.1 = SSE.1/length(train.ts)
MSE.1
## [1] 0.3494428
MAPE.1 = sum(abs(sisaan1[2:length(train.ts)]/train.ts[2:length(train.ts)])*
100)/length(train.ts)
MAPE.1
## [1] 0.302635
akurasi.1 <- matrix(c(SSE.1,MSE.1,MAPE.1))
row.names(akurasi.1)<- c("SSE", "MSE", "MAPE")
colnames(akurasi.1) <- c("Akurasi lamda=0.2")
akurasi.1
## Akurasi lamda=0.2
## SSE 46.1264451
## MSE 0.3494428
## MAPE 0.3026350
# Alpha = 0.7
fitted2<-ramalan2$fitted
sisaan2<-ramalan2$residuals
head(sisaan2)
## Time Series:
## Start = 1
## End = 6
## Frequency = 1
## [1] NA -0.110000 -0.303000 -0.900900 0.229730 -0.411081
resid2<-training$AI_Revenue_USD_Mn-ramalan2$fitted
head(resid2)
## Time Series:
## Start = 1
## End = 6
## Frequency = 1
## [1] NA -0.110000 -0.303000 -0.900900 0.229730 -0.411081
SSE.2=sum(sisaan2[2:length(train.ts)]^2)
SSE.2
## [1] 62.37001
MSE.2 = SSE.2/length(train.ts)
MSE.2
## [1] 0.4725
MAPE.2 = sum(abs(sisaan2[2:length(train.ts)]/train.ts[2:length(train.ts)])*
100)/length(train.ts)
MAPE.2
## [1] 0.3627136
akurasi.2 <- matrix(c(SSE.2,MSE.2,MAPE.2))
row.names(akurasi.2)<- c("SSE", "MSE", "MAPE")
colnames(akurasi.2) <- c("Akurasi lamda=0.7")
akurasi.2
## Akurasi lamda=0.7
## SSE 62.3700053
## MSE 0.4725000
## MAPE 0.3627136
Berdasarkan nilai SSE, MSE, RMSE, dan MAPE di antara kedua parameter, nilai parameter \(\lambda=0,2\) menghasilkan akurasi yang lebih baik dibanding \(\lambda=0,7\) . Hal ini dilihat dari nilai masing-masing ukuran akurasi yang lebih kecil. Berdasarkan nilai MAPE-nya, hasil ini dapat dikategorikan sebagai peramalan sangat baik.
# jumlah observasi uji
n_test <- nrow(testing)
# error (ramalan - aktual), samakan panjang dan tipe numeric
e1 <- as.numeric(ramalan1$mean)[1:n_test] - as.numeric(testing$AI_Revenue_USD_Mn)
e2 <- as.numeric(ramalan2$mean)[1:n_test] - as.numeric(testing$AI_Revenue_USD_Mn)
eopt <- as.numeric(ramalanopt$mean)[1:n_test] - as.numeric(testing$AI_Revenue_USD_Mn)
# SSE / MSE / RMSE untuk masing-masing model (abaikan NA)
SSEtesting1 <- sum(e1^2, na.rm = TRUE)
MSEtesting1 <- mean(e1^2, na.rm = TRUE)
RMSEtesting1 <- sqrt(MSEtesting1)
SSEtesting2 <- sum(e2^2, na.rm = TRUE)
MSEtesting2 <- mean(e2^2, na.rm = TRUE)
RMSEtesting2 <- sqrt(MSEtesting2)
SSEtestingopt <- sum(eopt^2, na.rm = TRUE)
MSEtestingopt <- mean(eopt^2, na.rm = TRUE)
RMSEtestingopt <- sqrt(MSEtestingopt)
# Tabel ringkas
akurasitesting_SSE <- matrix(c(SSEtesting1, SSEtesting2, SSEtestingopt),
nrow = 3,
dimnames = list(c("SSE1","SSE2","SSEopt"), "Nilai"))
akurasitesting_MSE <- matrix(c(MSEtesting1, MSEtesting2, MSEtestingopt),
nrow = 3,
dimnames = list(c("MSE1","MSE2","MSEopt"), "Nilai"))
akurasitesting_RMSE <- matrix(c(RMSEtesting1, RMSEtesting2, RMSEtestingopt),
nrow = 3,
dimnames = list(c("RMSE1","RMSE2","RMSEopt"), "Nilai"))
akurasitesting_SSE
## Nilai
## SSE1 3.528234
## SSE2 10.118419
## SSEopt 2.800132
akurasitesting_MSE
## Nilai
## MSE1 0.3528234
## MSE2 1.0118419
## MSEopt 0.2800132
akurasitesting_RMSE
## Nilai
## RMSE1 0.5939894
## RMSE2 1.0059035
## RMSEopt 0.5291627
Berdasarkan hasil smoothing yang dilakukan, dapat disimpulkan bahwa metode smoothing menggunakan SMA (Single Moving Average) mendapatkan hasil MAPE yang lebih baik dibandingkan dengan metode SES (Single Exponential Smoothing).