使用支持向量回归进行时间序列预测 [英] Time series prediction using support vector regression

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

问题描述

我一直在尝试使用 Python 语言中的支持向量回归来实现时间序列预测工具.我使用 scikit-learn 的 SVR 模块进行非线性支持向量回归.但是我对未来事件的预测有严重的问题.回归线非常适合原始函数(来自已知数据),但是一旦我想预测未来的步骤,它就会返回最后一个已知步骤的值.

I've been trying to implement time series prediction tool using support vector regression in python language. I use SVR module from scikit-learn for non-linear Support vector regression. But I have serious problem with prediction of future events. The regression line fits the original function great (from known data) but as soon as I want to predict future steps, it returns value from the last known step.

我的代码如下所示:

import numpy as np
from matplotlib import pyplot as plt
from sklearn.svm import SVR

X = np.arange(0,100)
Y = np.sin(X)

svr_rbf = SVR(kernel='rbf', C=1e5, gamma=1e5)
y_rbf = svr_rbf.fit(X[:-10, np.newaxis], Y[:-10]).predict(X[:, np.newaxis])

figure = plt.figure()
tick_plot = figure.add_subplot(1, 1, 1)
tick_plot.plot(X, Y, label='data', color='green', linestyle='-')
tick_plot.axvline(x=X[-10], alpha=0.2, color='gray')
tick_plot.plot(X, y_rbf, label='data', color='blue', linestyle='--')
plt.show()

有什么想法吗?
提前致谢,汤姆

Any ideas?
thanks in advance, Tom

推荐答案

您并没有真正进行时间序列预测.您正在尝试从 X 的单个元素预测 Y 的每个元素,这意味着您只是在解决标准的核化回归问题.

You are not really doing time-series prediction. You are trying to predict each element of Y from a single element of X, which means that you are just solving a standard kernelized regression problem.

另一个问题是当计算向量范围内的 RBF 核时[[0],[1],[2],...],你会得到一个正值带核矩阵的对角线,而远离对角线的值将接近于零.内核矩阵的测试集部分远离对角线,因此将非常接近于零,这将导致所有 SVR 预测接近偏差项.

Another problem is when computing the RBF kernel over a range of vectors [[0],[1],[2],...], you will get a band of positive values along the diagonal of the kernel matrix while values far from the diagonal will be close to zero. The test set portion of your kernel matrix is far from the diagonal and will therefore be very close to zero, which would cause all of the SVR predictions to be close to the bias term.

对于时间序列预测,我建议将训练测试集构建为

For time series prediction I suggest building the training test set as

 x[0]=Y[0:K]; y[0]=Y[K]
 x[1]=Y[1:K+1]; y[1]=Y[K+1]
 ...

也就是说,尝试从先前元素的窗口中预测序列的未来元素.

that is, try to predict future elements of the sequence from a window of previous elements.

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

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