在Scikit中查找混合度多项式学习支持向量回归

时间:2017-10-05 09:55:55

标签: python scikit-learn regression svm non-linear-regression

据我所知,Scikit中的支持向量回归学习程度取整数。但是,在我看来,似乎不考虑低次多项式。

运行以下示例:

import numpy
from sklearn.svm import SVR
X = np.sort(5 * np.random.rand(40, 1), axis=0)
Y=(2*X-.75*X**2).ravel()
Y[::5] += 3 * (0.5 - np.random.rand(8))
svr_poly = SVR(kernel='poly', C=1e3, degree=2)
y_poly = svr_poly.fit(X, Y).predict(X)

(从此处复制并稍加修改http://scikit-learn.org/stable/auto_examples/svm/plot_svm_regression.html

绘制数据给出了相当差的拟合(即使跳过第5行,其中Y值的随机误差)。

似乎不考虑低阶条款。我尝试为[1, 2]参数传递列表degree,但后来我的predict命令出错了。有没有办法包括它们?我错过了一些明显的东西吗

2 个答案:

答案 0 :(得分:2)

我认为低阶多项式项包含在拟合模型中,但在图中不可见,因为Cepsilon参数不适合数据。通过使用GridSearchCV微调参数,通常可以获得更好的拟合。由于在这种情况下数据不居中,coef0参数也具有显着效果。

以下参数应该更适合数据:

svr_poly = SVR(kernel='poly', degree=2, C=100, epsilon=0.0001, coef0=5)

答案 1 :(得分:1)

scikit-learn.SVR运行低阶多项式。对原始示例的修改清楚地表明了这一点。

X = np.sort(2*np.random.rand(40,1)-1,axis=0)
Y = np.sin(6*X).ravel()
svr_poly1 = SVR(kernel='poly', C=1e3, degree=3)
y_poly1 = svr_poly1.fit(X, Y).predict(X)
svr_poly2 = SVR(kernel='poly', C=100, epsilon=0.0001, coef0=5, degree=3)
y_poly2 = svr_poly2.fit(X, Y).predict(X)
svr_poly3 = SVR(kernel='poly', C=100, epsilon=0.0001, coef0=5, degree=5)
y_poly3 = svr_poly3.fit(X, Y).predict(X)

绘制图给出了

Result of the different SVR algorithms with two models using order 3 but different hyperparameters and one model using order 5