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 |
The split and the matrix
- Split the data into a training set 训练集, a validation set 验证集 and a test set 测试集. The test set is used only once, at the end.
- The confusion matrix 混淆矩阵 counts true positives (TP), false positives (FP), false negatives (FN) and true negatives (TN). Accuracy 准确率, precision 精确率 and recall 召回率 are read from it.

The test set is —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Spent once: it becomes a second validation set otherwise.
The metrics, from the matrix
- The course matrix for 200 test parcels, with "late" as the positive class:
| Actually late | Actually on time | |
|---|---|---|
| Predicted late | TP 36 | FP 10 |
| Predicted on time | FN 6 | TN 148 |
| Metric | Formula | Value |
|---|---|---|
| accuracy | (TP + TN) / all | 0.92 |
| precision | TP / (TP + FP) | 36/46 = 0.783 |
| recall | TP / (TP + FN) | 36/42 = 0.857 |
| $F_1$ | harmonic mean of the two | 0.818 |
- Since only $21\%$ of parcels are late, a model that always says "on time" already scores 0.79, so the recall figure is the one that carries the meaning.
- 5-fold cross-validation 交叉验证 on the Overnight data gives 0.905, 0.925, 0.915, 0.900 and 0.935: mean 0.916, standard deviation 0.013. A rival model scoring 0.921 is within the noise.
From TP 36, FP 10, FN 6, TN 148: precision is —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
36 / (36 + 10) = 0.783; recall 36/42 = 0.857.
Leakage is a plumbing fault
- A status code written at midnight secretly contains the answer. Training accuracy is 0.99, but honest held-out accuracy is 0.90: the label was leaking in through the feature. This is data leakage 数据泄漏, and the source column of the data card is the defence.
- Classic traps: using the test set to choose the model; scaling before splitting; averaging fold accuracies over folds of different sizes. A score without a resampling method behind it is only a story.
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.
Thresholds and the ROC curve
- A classifier outputs a score, and the threshold 阈值 turns it into a label. Lowering the threshold catches more lates (recall rises) but gives more false alarms. On the course matrix the false positive rate 假阳性率 is $10/158 = 0.063$ against a recall of $0.857$.
- The ROC curve ROC曲线 plots recall against the false positive rate for every threshold. The area under it (the AUC) is the chance that a random late parcel scores above a random on-time one: $0.5$ is guessing, $1$ is perfect. Choose the threshold from the cost of each kind of error.
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.
Accuracy against the base rate
- In the course test set, 42 of 200 parcels are late. A model that always says "on time" scores $158/200 = \mathbf{0.79}$ accuracy and catches none of them.
- Balanced accuracy 平衡准确率 averages the recall of each class. For the course model: recall 0.857 on lates and $148/158 = 0.937$ on on-time parcels, so $(0.857 + 0.937)/2 = 0.897$. The always-on-time model scores only 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$.
Worked example: what cross-validation costs
- Tuning one setting over 3 values with 5-fold cross-validation 交叉验证 trains $3 \times 5 = 15$ models, plus one more on all the training data for the chosen value: $\mathbf{16}$ fits.
- The test set is still untouched. It is opened once, for the final model, so its score is an honest estimate rather than a tuned one.
3 candidate values, 5-fold CV, then one final fit: total model fits?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
$3 \times 5 + 1$.
Marks that slip away
- Choosing the model on the test set 测试集. Then it is no longer a test; choose on validation data and test once.
- Accuracy on unbalanced classes. Always predicting the bigger class can score high and find no positives.
- Calling a gap inside the noise a win. $0.921$ against $0.916 \pm 0.013$ is within the spread of the folds.
Recap
- Use the test set once; read TP, FP, FN and TN from the confusion matrix 混淆矩阵.
- Course: accuracy $0.92$, precision $0.783$, recall $0.857$, $F_1 = 0.818$.
- Leakage inflates scores: $0.99$ in training against an honest $0.90$.
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.