我正在尝试预测依赖于时间(x ~ time)的周期性位置的未来值,使用支持向量回归进行单变量预测。该模型非常适合训练数据,但在对测试数据进行评估时会变成一条直线。在下面的代码中,我使用了 50 个观察值进行训练(红色周期曲线的前半部分,SVR 非常适合)和 50 个观察值进行测试(红色曲线的后半部分,SVR 无法预测)。
library(lubridate)
library(purrr)
library(ggplot2)
library(Metrics)
library(caret)
library(dplyr)
library(e1071)
# train_data has 50 observations
# eval_data has 100 observations (the first half is train_data)
func <- x ~ abs_time # position x dependent on time
svr_model <- svm(func, train_data, type = "eps-regression",
kernel="radial", gamma=13, cost=10, epsilon = 0.01)
k_hat <- predict(svr_model, eval_data)
plot(x = eval_data$abs_time, y = eval_data$x, type = "l", col="red") # true position
points(x = eval_data$abs_time, y = k_hat, col = "blue") # SVR predicted position
我查看了这篇文章: Time Series Forecasting using Support Vector Machine (SVM) in R并尝试了将训练数据和测试数据结合在一起并在其上评估模型的建议。
想知道这里发生了什么。我的预感是内核的选择在未来无法推广到周期性模式。我将如何构建一个内核,以便 SVR 模型能够预测未来的周期性数据?