# 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. Metrics and scoring: quantifying the quality of predictions
There are 3 different APIs for evaluating the quality of a model’s predictions: Estimator score method: Estimators have a score method providing a default evalu...

## 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)
```

```from sklearn.ensemble import GradientBoostingRegressor

GBR.fit(train_X, train_y)
```

### BaggingRegressor

```from sklearn.ensemble import BaggingRegressor

br = BaggingRegressor()

br.fit(train_X, train_y)
```

```from sklearn.ensemble import AdaBoostRegressor

abr.fit(train_X, train_y)
```

### 参考

1. Supervised learning
Linear Models- Ordinary Least Squares, Ridge regression and classification, Lasso, Multi-task Lasso, Elastic-Net, Multi-task Elastic-Net, Least Angle Regression...

## 参考

シェアする
βshortをフォローする βshort Lab
タイトルとURLをコピーしました