如何在R中制作ARIMA和SVM混合模型

时间:2018-09-12 10:21:31

标签: r svm hybrid arima

我想结合2种出色的模型进行数据预测/预测-ARIMA和SVMs模型,因此我想减少混合模型的标准误差。当前,这是一个图表,显示了它们的作用:

current ARIMA + SVM model

我不完全知道如何将两个模型结合在一起。我的方法是将ARIMA预测的结果适合SVM分类器。但是,我的方法在所有四个类别(MAE,MAPE,MSE和RMSE)中都会产生更高的误差:

errors

第1行-ARIMA适合

第2行-支持SVM

第3行-ARIMA + SVM组合(我的方法)

这是我的源代码:

# Time series data
data_ts <- ts(daily_data[, c('cnt')])

# ARIMA model
arima_seasonal <-
    Arima(
    data_ts,
    order = c(2, 1, 2),
    seasonal = c(1, 0, 1),
    include.drift = TRUE
    )
arima_seasonal_pred <- fitted(arima_seasonal)

# SVM model
svm_tune <- tune.svm(
    data_ts ~ daily_data$date,
    data = daily_data,
    gamma = 2 ^ (-1:1),
    cost = 2 ^ (2:8),
    epsilon = seq(0, 1, 0.1),
    kernel = "radial"
)
# - best parameters:
# gamma cost epsilon
# 2     256  0.4
svm_model <- svm_tune$best.model

svm_pred <- fitted(svm_model)

# ARIMA + SVM
arima_svm_tune <- tune.svm(
    arima_seasonal_pred ~ daily_data$date,
    data = daily_data,
    gamma = 2 ^ (-1:1),
    cost = 2 ^ (2:8),
    epsilon = seq(0, 1, 0.1),
    kernel = "radial"
)
arima_svm <- arima_svm_tune$best.model
arima_svm_pred <- fitted(arima_svm)

label1 <- "Actual data"
label2 <- "ARIMA model"
label3 <- "SVMs"
label4 <- "Hybrid model"

# Plot them
graph <- ggplot(daily_data) +
    geom_line(aes(x = date, y = cnt, colour = label1), size = .4) +
    geom_line(aes(x = date, y = arima_seasonal_pred, colour = label2)) +
    geom_point(aes(x = date, y = arima_seasonal_pred, colour = label2), size = 0.5) +
    geom_line(aes(x = date, y = svm_pred, colour = label3), size = .4) +
    geom_point(aes(x = date, y = svm_pred, colour = label3), size = 0.5) +
    geom_line(aes(x = date, y = arima_svm_pred, colour = label4), size = .4) +
    geom_point(aes(x = date, y = arima_svm_pred, colour = label4), size = 0.5) +
    scale_x_date("Date") +
    ylab("Bicycle Sales")
graph$labels$colour <- "Legend"

ggsave(
    filename = "arima_svm_pred_1.png",
    plot = graph,
    width = 10,
    height = 6
)

任何帮助将不胜感激。

0 个答案:

没有答案