train.sort_values(by=['mass'], ascending=True, inplace=True)
x = train['mass']
y = train['pa']
# 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)
x_train = x.reshape(x.shape[0], 1)
x = x_train
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()
コードはhttp://scikit-learn.org/stable/auto_examples/svm/plot_svm_regression.htmlからコピーされます。 私が変えるのはデータセットだけです。私は何が問題なのか分かりません。データが線形でないときに、python scikit-learnによってSVRを使用して線形回帰を取得します。
あなたの質問のコードをよりよくフォーマットしてください。 –