0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【メモ】scikit-learnの決定係数の範囲を確認しました

Posted at
  • 製造業出身のデータサイエンティストがお送りする記事
  • 今回はメモとして、scikit-learnの決定係数$R^2$の取り得る範囲について整理しました。

はじめに

過去に評価指標については整理しておりますが、今回は決定係数の取り得る範囲について確認しましたので、メモとして残しておきます。

決定係数

決定係数$R^2$では、推定された回帰モデルの当てはまりの良さを評価します。
scikit-learnの計算式は下記の通りです。

\begin{eqnarray}
R^2 = 1 - \sum \frac{(y_i - \hat{y_i})^2}{(y_i - \bar{y})^2}
\end{eqnarray}

$y_i$ : $i$番目サンプルの実測値
$\hat{y_i}$ : $i$番目サンプルの予測値
$\bar{y}$ : 実測値の平均

決定係数の取り得る範囲を確認してみた

scikit-learnのExamplesを参考に決定係数の取り得る範囲を実際に確認してみました。

from sklearn.metrics import r2_score
y_true = [1, 2, 3, 4]
y_pred = [1.1, 2, 3, 3.9]
r2_score(y_true, y_pred)
# 0.996

y_true = [1, 2, 3, 4]
y_pred = [3, 2.5, 3, 4]
r2_score(y_true, y_pred)
# 0.15000000000000002

y_true = [1, 2, 3, 4]
y_pred = [100, 2.5, 3, 4]
r2_score(y_true, y_pred)
# -1959.25

決定係数$R^2$は、あまりにも精度が悪いと大きなマイナスの値を取るんですね。実際に確認できると、今後、関係者へ説明する際に自信持って言えますね。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?