Evaluation Metrics
[markdown] content available only on the platform
[markdown] content available only on the platform
Flashcards · Evaluation Metrics
Confusion matrix — A 2x2 table of TP, FN, FP, TN from which all classification metrics are computed.
confusion_matrix(y_test, y_pred)
Precision — TP / (TP + FP): how often a positive prediction is correct.
TP 36, FP 4 -> 0.90
Recall — TP / (TP + FN): the share of truly positive cases the model finds.
TP 36, FN 24 -> 0.60
F1 — 2PR / (P + R): the harmonic mean of precision and recall, low if either is low.
P = 1.0, R = 0 -> F1 = 0
Which error is more expensive? — The deciding question for choosing between precision, recall and F1.
Cancer screening: FN is worse -> recall.
MAE vs RMSE — MAE treats all errors proportionally; RMSE squares them and penalises large errors heavily.
Choose RMSE when one big miss is dangerous.
R-squared — Compares the model with always predicting the mean: 1 is perfect, 0 is no better than the mean.
r2_score(y_test, y_pred)
classification_report() — Prints precision, recall, F1 and support for each class, plus accuracy and averages.
print(classification_report(y_test, y_pred))
