Scikit-learnでよく使う回帰モデルまとめ

機械学習




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.3. Model evaluation: quantifying the quality of predictions — scikit-learn 0.21.3 documentation

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 — scikit-learn 0.21.3 documentation

参考

[amazonjs asin=”4873117984″ locale=”JP” title=”Pythonではじめる機械学習 ―scikit-learnで学ぶ特徴量エンジニアリングと機械学習の基礎”]
[amazonjs asin=”4295003379″ locale=”JP” title=”第2版Python 機械学習プログラミング 達人データサイエンティストによる理論と実践 (impress top gear)”]

タイトルとURLをコピーしました