在Scikit学习支持向量回归中寻找混合次数多项式

2024-06-17 11:05:23 发布

您现在位置:Python中文网/ 问答频道 /正文

据我所知,Scikit learn中的支持向量回归采用整数表示度。然而,在我看来,似乎不考虑低阶多项式。在

运行以下示例:

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值有随机误差)。在

似乎不考虑低阶条件。我试图为degree参数传递一个列表[1, 2],但随后predict命令出现错误。有没有办法把它们包括在内?我错过了什么明显的东西吗?在


Tags: importnp整数randomscikit向量learnpredict
2条回答

我认为低阶多项式项包含在拟合模型中,但在绘图中不可见,因为C和{}参数不适合数据。通常可以通过使用GridSearchCV微调参数来获得更好的拟合。由于在这种情况下,数据不居中,coef0参数也有显著影响。在

以下参数应能更好地拟合数据:

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

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

相关问题 更多 >