在 Scikit 中查找混合次数多项式学习支持向量回归
Finding mixed degree polynomials in Scikit learn support vector regression
据我了解,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
命令的错误。有什么办法可以包括它们吗?我错过了一些明显的东西吗?
我认为低阶多项式项包含在拟合模型中,但在图中不可见,因为 C
和 epsilon
参数不太适合数据。通常可以通过使用 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
据我了解,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
命令的错误。有什么办法可以包括它们吗?我错过了一些明显的东西吗?
我认为低阶多项式项包含在拟合模型中,但在图中不可见,因为 C
和 epsilon
参数不太适合数据。通常可以通过使用 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