【问题标题】:Time series forecasting with support vector regression支持向量回归的时间序列预测
【发布时间】: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


    【解决方案1】:

    我知道这是一个老问题,但我会回答它,因为其他人可能会从这个答案中受益。

    如果您的示例使用线性内核而不是 rbf,则您用于 C 和 gamma 的值很可能是问题所在。 C 和 gamma 是用于非线性内核的 SVM 参数。要直观地了解 C 和 gamma 是什么,请看这里:http://scikit-learn.org/stable/auto_examples/svm/plot_rbf_parameters.html?

    为了预测正弦曲线的值,请尝试 C = 1 和 gamma = 0.1。它的性能比您拥有的值要好得多。

    【讨论】:

      猜你喜欢
      • 2013-03-24
      • 2019-06-07
      • 2018-12-23
      • 2017-07-05
      • 2015-06-19
      • 2017-05-29
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      相关资源
      最近更新 更多