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

查看:175
本文介绍了在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!!!

推荐答案

让我们假设您有月度数据,例如从航空乘客数据集中获得的数据.您不需要时间序列类型的数据,只需一个包含时间步长和值的数据框.我们将它们命名为x和y.接下来,您将开发一个svm模型,并指定需要预测的时间步长.使用预测功能可以计算给定时间步长的预测.就是这样.但是,支持向量机通常不被认为是时间序列预测的最佳方法,特别是对于长序列的数据.对于未来的少量观察,它可能会表现良好,但是例如,我预计不会有很好的预测结果.明年全年的每日数据(但显然取决于数据).用于基于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天全站免登陆