在 R 中使用支持向量机 (SVM) 进行时间序列预测 [英] Time Series Forecasting using Support Vector Machine (SVM) in R

查看:32
本文介绍了在 R 中使用支持向量机 (SVM) 进行时间序列预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试搜索,但找不到此问题的具体答案.到目前为止,我能够意识到使用 SVM 可以进行时间序列预测.我浏览了几篇执行相同但没有提及任何代码的论文/文章,而是解释了算法(我不太明白).有些人使用python完成了它.我的问题是:我有一个公司 2010 年到 2017 年的销售额数据(比如单变量).我需要使用 R 中的 SVM 预测 2018 年的销售额.您能否通过一个小示例简单地介绍和解释 R 代码以执行相同的操作?我真的很感谢你的投入和努力!谢谢!!!

I've tried searching but couldn't find a specific answer to this question. So far I'm able to realize that Time Series Forecasting is possible using SVM. I've gone through a few papers/articles who've performed the same but didn't mention any code, instead explained the algorithm (which I didn't quite understand). And some have done it using python. My problem here is that: I have a company data(say univariate) of sales from 2010 to 2017. And I need to forecast the sales value for 2018 using SVM in R. Would you be kind enough to simply present and explain the R code to perform the same using a small example? I really do appreciate your inputs and efforts! Thanks!!!

推荐答案

假设您有月度数据,例如来自 Air Passengers 数据集.您不需要时间序列类型的数据,只需要包含时间步长和值的数据框.让我们将它们命名为 x 和 y.接下来,您开发一个 svm 模型,并指定您需要预测的时间步长.使用 predict 函数计算给定时间步长的预测值.而已.然而,支持向量机通常不被认为是时间序列预测的最佳方法,尤其是对于长序列数据.它可以在前面的少量观察中表现良好,但我不希望预测会有好的结果,例如.明年全年的每日数据(但显然取决于数据).基于 SVM 的预测的简单 R 代码:

let's assume you have monthly data, for example derived from Air Passengers data set. You don't need the timeseries-type data, just a data frame containing time steps and values. Let's name them x and y. Next you develop an svm model, and specify the time steps you need to forecast. Use the predict function to compute the forecast for given time steps. That's it. However, support vector machine is not commonly regarded as the best method for time series forecasting, especially for long series of data. It can perform good for few observations ahead, but I wouldn't expect good results for forecasting eg. daily data for a whole next year (but it obviously depends on data). Simple R code for SVM-based forecast:

# prepare sample data in the form of data frame with cols of timesteps (x) and values (y)  
data(AirPassengers) 
monthly_data <- unclass(AirPassengers)
months <- 1:144
DF <- data.frame(months,monthly_data)
colnames(DF)<-c("x","y")

# train an svm model, consider further tuning parameters for lower MSE
svmodel <- svm(y ~ x,data=DF, type="eps-regression",kernel="radial",cost=10000, gamma=10)
#specify timesteps for forecast, eg for all series + 12 months ahead
nd <- 1:156
#compute forecast for all the 156 months 
prognoza <- predict(svmodel, newdata=data.frame(x=nd))

#plot the results
ylim <- c(min(DF$y), max(DF$y))
xlim <- c(min(nd),max(nd))
plot(DF$y, col="blue", ylim=ylim, xlim=xlim, type="l")
par(new=TRUE)
plot(prognoza, col="red", ylim=ylim, xlim=xlim)

这篇关于在 R 中使用支持向量机 (SVM) 进行时间序列预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆