【发布时间】:2014-08-22 11:04:44
【问题描述】:
我正在尝试使用支持向量回归执行简单的时间序列预测。
我试图理解here提供的答案。
我修改了 Tom 的代码以反映所提供的答案:
import numpy as np
from matplotlib import pyplot as plt
from sklearn.svm import SVR
X = np.arange(0,100)
Y = np.sin(X)
a = 0
b = 10
x = []
y = []
while b <= 100:
x.append(Y[a:b])
a += 1
b += 1
b = 10
while b <= 90:
y.append(Y[b])
b += 1
svr_rbf = SVR(kernel='rbf', C=1e5, gamma=1e5)
y_rbf = svr_rbf.fit(x[:81], y).predict(x)
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[10:], y_rbf[:-1], label='data', color='blue', linestyle='--')
plt.show()
但是,我仍然得到相同的行为——预测只是返回最后一个已知步骤的值。奇怪的是,如果我将内核设置为linear,结果会好得多。为什么rbf 内核预测没有按预期工作?
谢谢。
【问题讨论】:
标签: python machine-learning time-series scikit-learn regression