Evaluation and leakage
Introducido
6:33
Inteligencia Artificial y Aprendizaje Automático
This course covers the classical core of artificial intelligence, honestly measured. The first three units are the spine: search, logical reasoning and…
Narración en inglés · subtítulos en inglés y 中文 que puedes cambiar
En esta lección
| English | Significado |
|---|---|
| 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/ | matriz de confusión |
| 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/ | sensibilidad |
| 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 |
La división y la matriz
- Entrenamiento/validación/prueba; el conjunto de prueba se gasta una sola vez. La matriz de confusión cuenta TP, FP, FN, TN; exactitud, precisión, sensibilidad se leen de ella.


The test set is —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Spent once: it becomes a second validation set otherwise.
Las métricas, desde la matriz
- Matriz de curso (prueba 200): TP 36, FP 10, FN 6, TN 148 — exactitud $(36+148)/200 = 0.92$; precisión $36/46 = 0.783$; sensibilidad $36/42 = 0.857$; $F_1 = 0.818$. Tasa base $21\%$ significa que el predictor trivial siempre activo puntúa 0.79: el número de sensibilidad es donde reside el significado.
- CV de 5-vez en Noche: 0.905, 0.925, 0.915, 0.900, 0.935 — media 0.916, desviación estándar 0.013: un competidor 0.921 está dentro del ruido.
From TP 36, FP 10, FN 6, TN 148: precision is —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
36 / (36 + 10) = 0.783; recall 36/42 = 0.857.
La filtración es fontanería
- Una característica de código de estado a medianoche codifica la etiqueta: entrenamiento 0.99, honesto retenido 0.90 — la etiqueta estaba susurrando a través de la característica. La columna de procedencia de la ficha de datos es la defensa.
- Trampas clásicas: gastar el conjunto de prueba para elegir modelo; escalar antes de dividir; promediar exactitudes de pliegue sobre pliegues desiguales. Una puntuación sin una historia de remuestreo es una anécdota.
A midnight status-code feature causes —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
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.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
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.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
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?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
12 / (12 + 188) = 12 / 200 = 0.06.
Lowering the decision threshold usually makes —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
More cases are called positive: more true positives are caught, but more false ones slip in too.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
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?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
$158/200 = 0.79$.
Recall 0.857 on lates and 0.937 on on-time parcels: balanced accuracy (three decimals)?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
$(0.857 + 0.937)/2 = 0.897$.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
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?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
$3 \times 5 + 1$.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
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.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
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$.
¿Qué salió mal? Solo el equipo del sitio ve esta información.