Scikit-learnでよく使う回帰モデルまとめ
回帰モデルの評価
MSE:平均二乗誤差
from sklearn.metrics import mean_squared_error scores = mean_squared_error(val_y, pred)
RMSE
import numpy as np from sklearn.metrics import mean_squared_error scores = np.sqrt(mean_squared_error(val_y, pred))
R^2:決定係数
from sklearn.metrics import r2_score scores = r2_score(val_y, pred)
参考
3.4. Metrics and scoring: quantifying the quality of predictions
...
sklearnの回帰モデル
LinearRegression
from sklearn.linear_model import LinearRegression lr = LinearRegression() lr.fit(train_X, train_y)
KNeighborsRegressor
from sklearn.neighbors import KNeighborsRegressor knr = KNeighborsRegressor() knr.fit(train_X, train_y)
Ridge
from sklearn.linear_model import Ridge ridge = Ridge() ridge.fit(train_X, train_y)
Lasso
from sklearn.linear_model import Lasso lasso = Lasso() lasso.fit(train_X, train_y)
ElasticNet
from sklearn.linear_model import ElasticNet elastic_net = ElasticNet(alpha = 0.5) elastic_net.fit(data_x, data_y)
DecisionTreeRegressor
from sklearn.tree import DecisionTreeRegressor dtr = DecisionTreeRegressor(random_state = 0) dtr.fit(train_X, train_y)
LinearSVR
from sklearn.svm import LinearSVR svr = LinearSVR() svr.fit(train_X, train_y)
GradientBoostingRegressor
from sklearn.ensemble import GradientBoostingRegressor GBR = GradientBoostingRegressor() GBR.fit(train_X, train_y)
BaggingRegressor
from sklearn.ensemble import BaggingRegressor br = BaggingRegressor() br.fit(train_X, train_y)
AdaBoostRegressor
from sklearn.ensemble import AdaBoostRegressor abr = AdaBoostRegressor() abr.fit(train_X, train_y)
参考
1. Supervised learning
...