简体   繁体   English

使用支持向量回归的时间序列预测

[英]Time series prediction using support vector regression

I've been trying to implement time series prediction tool using support vector regression in python language. 我一直在尝试使用python语言中的支持向量回归来实现时间序列预测工具。 I use SVR module from scikit-learn for non-linear Support vector regression. 我使用scikit-learn的SVR模块进行非线性支持向量回归。 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. 回归线非常适合原始函数(从已知数据中得出),但是一旦我要预测未来的步骤,它就会从最后一个已知步骤中返回值。

My code looks like this: 我的代码如下所示:

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 预先感谢,汤姆

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. 您试图从X的单个元素预测Y每个元素,这意味着您仅在解决标准的内核化回归问题。

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. 另一个问题是,在一系列矢量[[0],[1],[2],...]计算RBF内核时,沿着内核矩阵的对角线会得到一个正值带,而值远对角线将接近零。 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. 内核矩阵的测试集部分远离对角线,因此将非常接近零,这将导致所有SVR预测都接近偏差项。

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. 也就是说,尝试从先前元素的窗口中预测序列的未来元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM