scikit python - SVR回归:预测多个点导致相同的重复输出

时间:2016-12-20 00:23:18

标签: python scikit-learn regression svm prediction

我试图用SVM训练和预测如下:

for i in range(numStocks):
    y_p = []
    X, y, X_p, scaler, stockUsed = randomStockData(stockList)
    clf = svm.SVR(kernel='rbf', C=1, gamma=0.1)
    clf.fit(X, y)
    reshapedX_p = X_p.reshape(1,-1)
    for j in range(5):
        y_p.append(clf.predict(reshapedX_p))
        reshapedX_p = np.append(reshapedX_p[0][1:],y_p[-1])
        reshapedX_p = reshapedX_p.reshape(1, reshapedX_p.shape[0])
    y_p = [x*scaler for x in y_p]
    rescaledX_p = [x*scaler for x in X_p]
    print(y_p)
    plt.plot(rescaledX_p, label='closep test')
    plt.plot(range(len(rescaledX_p),len(rescaledX_p)+len(y_p)), y_p, label='predicted')
    plt.legend(loc='lower left', shadow=True)
    pylab.savefig(homePath+'predictResults/'+stockUsed+'.png', facecolor='#ffffff', edgecolor='#ffffff')
    plt.close()

但情节都是这样的: enter image description here enter image description here

查看最后几个"预测输入" (reshapedX_p)在每次迭代时,也使用y_p:

内部for循环中的

print(reshapedX_p[0][-5:], y_p)

(array([ 0.00458431,  0.00465051,  0.00470016,  0.00466706,  0.00462568]), [])
(array([ 0.00465051,  0.00470016,  0.00466706,  0.00462568,  0.00415898]), [array([ 0.00415898])])
(array([ 0.00470016,  0.00466706,  0.00462568,  0.00415898,  0.00415898]), [array([ 0.00415898]), array([ 0.00415898])])
(array([ 0.00466706,  0.00462568,  0.00415898,  0.00415898,  0.00415898]), [array([ 0.00415898]), array([ 0.00415898]), array([ 0.00415898])])
(array([ 0.00462568,  0.00415898,  0.00415898,  0.00415898,  0.00415898]), [array([ 0.00415898]), array([ 0.00415898]), array([ 0.00415898]), array([ 0.00415898])])

很明显,每一步的预测输入实际上都在变化,但SVM只是吐出与第一次预测后的最后一步完全相同的值。

我是否每次都需要重新安装SVM?我不认为我会这么做。

0 个答案:

没有答案