LoginSignup
0
0

More than 1 year has passed since last update.

回帰モデルの評価

Last updated at Posted at 2021-07-05

MSE(Mean Squared Error: 平均二乗誤差)

予測値と正解値の差の二乗の総和を残差平方和(SSE: Sum of Squared Errors)と言います。
その総和をデータ数で割った値がMSEです。

MSE = \frac{1}{n}\sum_{i=1}^{n}(y_i-\hat{y_i})^2
  • n: データ数
  • i: 各データのインデックス
  • $ y_i $: i番目データの正解値
  • $ \hat{y_i} $: i番目データの予測値
from sklearn.metrics import mean_squared_error

# y_true:正解値 y_pred:予測値
mean_squared_error(y_true, y_pred)
Kaggle Competition

RMSE(Root Mean Squared Error: 平均平方二乗誤差)

MSEの結果に対するルートがRMSEです。
MSEで二乗した単位が元に戻るので、MSEよりも人間が理解しやすい。

RMSE = \sqrt{\frac{1}{n}\sum_{i=1}^{n}(y_i-\hat{y_i})^2}
  • n: データ数
  • i: 各データのインデックス
  • $ y_i $: i番目データの正解値
  • $ \hat{y_i} $: i番目データの予測値
from sklearn.metrics import mean_squared_error

# y_true:正解値 y_pred:予測値
np.sqrt(mean_squared_error(y_true, y_pred))
Kaggle Competition
Elo Merchant Category Recommendation

RMSLE(Root Mean Squared Logarithmic Error)

予測値と正解値の対数をそれぞれとったあとの差の二乗の平方根がRMSLEです。

RMSLE = \sqrt{\frac{1}{n}\sum_{i=1}^{n}(\log (1+y_i)-\log (1+\hat{y_i}))^2}
  • n: データ数
  • i: 各データのインデックス
  • $ y_i $: i番目データの正解値
  • $ \hat{y_i} $: i番目データの予測値
from sklearn.metrics import mean_squared_log_error

# y_true:正解値 y_pred:予測値
mean_squared_log_error(y_true, y_pred)
Kaggle Competition
Recruit Restaurant Visitor Forecasting

RMSPE(Root Mean Square Percentage Error)

RMSPE = \sqrt{\frac{1}{n}\sum_{i=1}^{n}((y_i-\hat{y_i})/y_i)^2}
  • n: データ数
  • i: 各データのインデックス
  • $ y_i $: i番目データの正解値
  • $ \hat{y_i} $: i番目データの予測値
from sklearn.metrics import mean_absolute_percentage_error

# y_true:正解値 y_pred:予測値
mean_absolute_percentage_error(y_true, y_pred)
Kaggle Competition
Optiver Realized Volatility Prediction

MAE(Mean Absolute Error: 平均絶対誤差)

予測値と正解値の差の絶対値の平均がMAEです。

MAE = \frac{1}{n}\sum_{i=1}^{n}|y_i-\hat{y_i}|
  • n: データ数
  • i: 各データのインデックス
  • $ y_i $: i番目データの正解値
  • $ \hat{y_i} $: i番目データの予測値
from sklearn.metrics import mean_absolute_error

# y_true:正解値 y_pred:予測値
mean_absolute_error(y_true, y_pred)
Kaggle Competition
Allstate Claims Severity

MedAE(Median Absolute Error)

予測値と正解値の差の絶対値の中央値がMedAEです。

MedAE = median(|y_1-\hat{y_1}|,...,|y_n-\hat{y_n}|)
  • n: データ数
  • i: 各データのインデックス
  • $ y_i $: i番目データの正解値
  • $ \hat{y_i} $: i番目データの予測値
from sklearn.metrics import median_absolute_error

# y_true:正解値 y_pred:予測値
median_absolute_error(y_true, y_pred)
Kaggle Competition

R2(決定係数)

検証データの平均値で予測をした場合の残差平方和STT(Sum of Squared Total)と、モデルの残差平方和SSE(Sum of Squared Errors)の比率で、R2 = 1 - SSE / SST です。

R^2 = 1-\frac{\sum_{i=1}^{n}(y_i-\hat{y_i})^2}{\sum_{i=1}^{n}(y_i-\bar{y})^2}
  • n: データ数
  • i: 各データのインデックス
  • $ y_i $: i番目データの正解値
  • $ \hat{y_i} $: i番目データの予測値
  • $ \bar{y} $: 正解値の平均値
from sklearn.metrics import r2_score

# y_true:正解値 y_pred:予測値
r2_score(y_true, y_pred)
Kaggle Competition
Mercedes-Benz Greener Manufacturing
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0