在训练SVM回归时,通常建议在训练之前对输入特征进行缩放。
但是如何缩放目标?通常情况下,这不被认为是必要的,我也没有看到为什么需要这样做的好理由。
然而,在scikit-learn中SVM回归的示例中: http://scikit-learn.org/stable/auto_examples/svm/plot_svm_regression.html 仅在训练之前引入y=y/1000这一行代码,预测值就会崩溃为一个常数。在训练之前缩放目标变量将解决此问题,但我不明白为什么这是必要的。
这个问题是什么原因造成的?
但是如何缩放目标?通常情况下,这不被认为是必要的,我也没有看到为什么需要这样做的好理由。
然而,在scikit-learn中SVM回归的示例中: http://scikit-learn.org/stable/auto_examples/svm/plot_svm_regression.html 仅在训练之前引入y=y/1000这一行代码,预测值就会崩溃为一个常数。在训练之前缩放目标变量将解决此问题,但我不明白为什么这是必要的。
这个问题是什么原因造成的?
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt
# Generate sample data
X = np.sort(5 * np.random.rand(40, 1), axis=0)
y = np.sin(X).ravel()
# Add noise to targets
y[::5] += 3 * (0.5 - np.random.rand(8))
# Added line: this will make the prediction break down
y=y/1000
# Fit regression model
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_lin = SVR(kernel='linear', C=1e3)
svr_poly = SVR(kernel='poly', C=1e3, degree=2)
y_rbf = svr_rbf.fit(X, y).predict(X)
y_lin = svr_lin.fit(X, y).predict(X)
y_poly = svr_poly.fit(X, y).predict(X)
# look at the results
plt.scatter(X, y, c='k', label='data')
plt.hold('on')
plt.plot(X, y_rbf, c='g', label='RBF model')
plt.plot(X, y_lin, c='r', label='Linear model')
plt.plot(X, y_poly, c='b', label='Polynomial model')
plt.xlabel('data')
plt.ylabel('target')
plt.title('Support Vector Regression')
plt.legend()
plt.show()