python - 使用支持向量回归进行时间序列预测

标签 python machine-learning time-series scikit-learn regression

我正在尝试使用支持向量回归执行简单的时间序列预测。

我正在尝试理解所提供的答案 here .

我改编了 Tom 的代码以反射(reflect)所提供的答案:

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 内核预测没有按预期工作?

谢谢。

最佳答案

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

如果您的示例使用线性核而不是 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。它的性能比您拥有的值要好得多。

关于python - 使用支持向量回归进行时间序列预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24517858/

相关文章:

r - R : parameter definitions/model specification missing? 中的 fGarch 包

python - 完整的 sklearn 管道示例

machine-learning - ValueError : Input 0 is incompatible with layer lstm_1: expected ndim=3, 发现 ndim=2 [keras]

r - 计算面板数据中一个时期到另一个时期的匹配观察百分比

r - 使用神经网络包进行多项分类

machine-learning - 文本挖掘中如何强调文章标题的重要性?

timestamp - C3.js - 绘制从 InfluxDB 获取的时间序列时如何指定时间戳格式

python - 是否有可用于 google calendar api 的管理员帐户?

python - 使用 Pandas 将多个列值一起比较

python - 从文件中删除在 Python 中没有特定单词的行