やりたいこと
- 説明変数が複数あるSVRの実装
起きている問題
ウェブページを参考にやってみましたが、
計算結果が出てきませんでした。
結果が表示されない原因があれば教えてください。
また、以下についても教えていただければ嬉しいです。
- パラメータの表示
- 予測値をグラフに表す
使用したデータセットはUCIのBoston house-prices(米国ボストン市郊外における地域別の住宅価格のデータセット)です。
python
1import numpy as np 2from sklearn.svm import SVR 3from matplotlib import pyplot as plt 4from sklearn.datasets import load_boston 5boston = load_boston() 6import pandas as pd 7pd.DataFrame(boston.data, columns=boston.feature_names) 8 9#簡易的にトレーニングデータとテストデータを分けた 10X = boston.data[:354, :] 11y = boston.target[:354] 12 13svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1) 14svr_lin = SVR(kernel='linear', C=1e3) 15svr_poly = SVR(kernel='poly', C=1e3, degree=3) 16y_rbf = svr_rbf.fit(X, y).predict(X) 17y_lin = svr_lin.fit(X, y).predict(X) 18y_poly = svr_poly.fit(X, y).predict(X) 19 20test_X = boston.data[354:, :] 21test_y = boston.target[354:] 22 23test_rbf = svr_rbf.predict(test_X) 24test_lin = svr_lin.predict(test_X) 25test_poly = svr_poly.predict(test_X) 26 27from sklearn.metrics import mean_squared_error 28from math import sqrt 29 30# RMSEを計算 31rbf_rmse = sqrt(mean_squared_error(test_y, test_rbf)) 32lin_rmse = sqrt(mean_squared_error(test_y, test_lin)) 33poly_rmse = sqrt(mean_squared_error(test_y, test_poly)) 34
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/24 14:55