Evaluation and leakage
導入済み
6:33
人工知能と機械学習
This course covers the classical core of artificial intelligence, honestly measured. The first three units are the spine: search, logical reasoning and…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| training set/ˈtreɪnɪŋ set/ | the data used to fit the model |
| validation set/ˌvælɪˈdeɪʃn set/ | data used to choose settings and compare models during development |
| test set/test set/ | data kept aside and used once to estimate final performance |
| confusion matrix/kənˈfjuːʒn ˈmeɪtrɪks/ | 混同行列 |
| Accuracy/ˈækjʊrəsi/ | the share of all predictions that are correct |
| precision/prɪˈsɪʒn/ | of the cases predicted positive, the share that really are positive |
| recall/ˈriːkɔːl/ | 再現率 |
| cross-validation/krɒs ˌvælɪˈdeɪʃn/ | training and testing on several different splits of the data and averaging the results |
| data leakage/ˈdeɪtə ˈliːkɪdʒ/ | Exposure of information to people or systems that are not authorised to receive it. |
| threshold/ˈθreʃəʊld/ | A boundary value at which a specified effect begins or a decision changes. |
| ROC curve/ˌɑː əʊ ˈsiː kɜːv/ | the true positive rate plotted against the false positive rate as the threshold changes |
| false positive rate/fɒls ˈpɒzɪtɪv reɪt/ | of the real negatives, the share wrongly predicted positive |
| Balanced accuracy/ˈbælənst ˈækjʊrəsi/ | the average of the accuracy on each class |
データの分割と混同行列
- データを訓練セット、検証セット、テストセットに分割します。テストセットは最後に1回だけ使います。
- 混同行列には、真陽性(TP)、偽陽性(FP)、偽陰性(FN)、真陰性(TN)の数を記録します。ここから正解率、適合率、再現率を読み取れます。

The test set is —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Spent once: it becomes a second validation set otherwise.
混同行列から求める評価指標
- 200個のテスト用荷物について、「遅延」を陽性クラスとした、このコースの混同行列です。
| 実際に遅延 | 実際に定刻 | |
|---|---|---|
| 遅延と予測 | TP 36 | FP 10 |
| 定刻と予測 | FN 6 | TN 148 |
| 評価指標 | 計算式 | 値 |
|---|---|---|
| 正解率 | (TP + TN) / 全体 | 0.92 |
| 適合率 | TP / (TP + FP) | 36/46 = 0.783 |
| 再現率 | TP / (TP + FN) | 36/42 = 0.857 |
| $F_1$ | 2つの調和平均 | 0.818 |
- 遅延する荷物は全体の$21\%$にすぎないため、常に「定刻」と予測するモデルでも0.79の正解率になります。そのため、重要な意味を持つのは再現率の値です。
- 翌日配達データで5分割の交差検証を行うと、0.905、0.925、0.915、0.900、0.935となります。平均は0.916、標準偏差は0.013です。別のモデルのスコア0.921は、このばらつきの範囲内です。
From TP 36, FP 10, FN 6, TN 148: precision is —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
36 / (36 + 10) = 0.783; recall 36/42 = 0.857.
データ漏洩は配管の不具合
- 真夜中に記録されたステータスコードには、ひそかに答えが含まれています。訓練時の正解率は0.99ですが、学習に使わずに取り分けたデータで正しく評価した正解率は0.90です。正解ラベルが特徴量を通じて漏れていたのです。これをデータ漏洩といい、データカードの出典欄が防止に役立ちます。
- 典型的な落とし穴には、テストセットを使ってモデルを選ぶこと、分割前にスケーリングすること、サイズが異なる分割の正解率を単純に平均することがあります。再標本化の方法に裏付けられていないスコアは、単なる話にすぎません。
A midnight status-code feature causes —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The feature secretly contains the label; checking where each feature comes from is the defence.
Scaling the features on the whole dataset before splitting is harmless, because scaling does not look at the labels.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The scaler's mean and spread now include the test rows, so test information leaks into training. Fit the scaler on the training split only, then apply it to the rest.
しきい値とROC曲線
- 分類器はスコアを出力し、しきい値を使ってそれをラベルに変換します。しきい値を下げると、より多くの遅延を検出できますが(再現率が上がる)、誤警報も増えます。このコースの混同行列では、再現率が$0.857$であるのに対し、偽陽性率は$10/158 = 0.063$です。
- ROC曲線は、すべてのしきい値について、偽陽性率に対する再現率をプロットしたものです。曲線の下の面積(AUC)は、無作為に選んだ遅延荷物のスコアが、無作為に選んだ定刻の荷物のスコアを上回る確率を表します。$0.5$は当てずっぽう、$1$は完全な予測です。それぞれの種類の誤りにかかるコストを考えて、しきい値を選びます。
A matrix has FP = 12 and TN = 188. What is the false positive rate?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
12 / (12 + 188) = 12 / 200 = 0.06.
Lowering the decision threshold usually makes —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
More cases are called positive: more true positives are caught, but more false ones slip in too.
正解率と基本発生率
- このコースのテストセットでは、200個の荷物のうち42個が遅延しています。常に「定刻」と予測するモデルの正解率は$158/200 = \mathbf{0.79}$ですが、遅延は1つも検出できません。
- バランス正解率は、各クラスの再現率を平均したものです。このコースのモデルでは、遅延荷物の再現率が0.857、定刻の荷物の再現率が$148/158 = 0.937$なので、バランス正解率は$(0.857 + 0.937)/2 = 0.897$です。常に定刻と予測するモデルのスコアは、わずか0.5です。
42 of 200 parcels are late. Accuracy of always predicting on time?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$158/200 = 0.79$.
Recall 0.857 on lates and 0.937 on on-time parcels: balanced accuracy (three decimals)?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$(0.857 + 0.937)/2 = 0.897$.
計算例:交差検証にかかるコスト
- 1つの設定について3つの値を、5分割の交差検証で調整すると、$3 \times 5 = 15$個のモデルを訓練します。さらに、選んだ値について訓練データ全体でもう1つ訓練するので、モデルの学習は合計$\mathbf{16}$回です。
- テストセットはまだ使っていません。最終モデルに対して1回だけ使うため、そのスコアは調整に使われた値ではなく、正当な推定値になります。
3 candidate values, 5-fold CV, then one final fit: total model fits?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$3 \times 5 + 1$.
失いやすい得点
- テストセットでモデルを選ぶこと。 それではテストとして使えなくなります。検証データでモデルを選び、テストは1回だけ行います。
- クラスに偏りがあるときの正解率。 常に数の多いクラスを予測すると、スコアは高くても陽性を1つも見つけられないことがあります。
- ばらつきの範囲内の差を勝利と呼ぶこと。 $0.921$と$0.916 \pm 0.013$の差は、各分割のスコアのばらつきの範囲内です。
まとめ
- テストセットは1回だけ使い、混同行列からTP、FP、FN、TNを読み取ります。
- このコースでは、正解率$0.92$、適合率$0.783$、再現率$0.857$、$F_1 = 0.818$です。
- データ漏洩はスコアを水増しします。訓練時は$0.99$ですが、正しく評価すると$0.90$です。
何が問題でしたか?この内容はサイトの運営チームだけが確認します。