Model Evaluation — The Judge
A model that scores well on the wrong metric, validated with a leaky pipeline, and deployed without statistical rigor is worse than no model at all — it ships confident wrong answers. This skill covers the full evaluation lifecycle: picking the right metrics, validating honestly, comparing models with statistical discipline, checking calibration, and auditing for fairness before anything reaches production.
1. Metric Selection by Task
No single metric captures model quality. The right choice depends on task type, class balance, and what errors cost the business.
| Task |
Metric |
When to Prefer |
| Classification |
Accuracy |
Balanced classes, equal error costs |
|
Precision |
False positives are expensive (spam filters, fraud alerts) |
|
Recall (Sensitivity) |
False negatives are dangerous (disease screening, security threats) |
|
F1 Score |
Need a single number balancing precision and recall |
|
AUC-ROC |
Threshold-independent ranking ability, reasonably balanced data |
|
AUC-PR |
Imbalanced data — far more informative than AUC-ROC when positives are rare |
|
Log Loss |
Probability quality matters, not just ranking |
|
MCC |
Imbalanced data where you want a single balanced measure (-1 to +1) |
|
Cohen's Kappa |
Agreement beyond chance; useful when comparing to human labelers |
| Regression |
MSE / RMSE |
Large errors are disproportionately bad; RMSE for same-unit interpretability |
|
MAE |
Robust to outliers; median-focused performance |
|
MAPE |
Stakeholders want percentage-based error; fails when actuals near zero |
|
R² |
Explaining variance proportion; familiar to business audiences |
|
Adjusted R² |
Comparing models with different feature counts |
|
Median Absolute Error |
Highly robust summary when distribution of errors is skewed |
| Ranking |
NDCG |
Graded relevance; position-weighted quality |
|
MAP |
Binary relevance across queries |
|
MRR |
Only the first relevant result matters (e.g., question answering) |
|
Precision@k / Recall@k |
Fixed-size recommendation lists; top-k retrieval |
| Clustering |
Silhouette Score |
Cluster compactness vs separation when no ground truth exists |
|
Calinski-Harabasz |
Fast, favors convex clusters |
|
Davies-Bouldin |
Lower is better; penalizes overlapping clusters |
|
Adjusted Rand Index |
Ground truth labels available; chance-corrected agreement |
Key decision rules:
- Imbalanced classification: default to AUC-PR, MCC, or F1 on the minority class. Never report accuracy alone.
- When probabilities drive decisions (setting thresholds, expected value calculations): use log loss and calibration metrics.
- Regression with outliers: prefer MAE or median absolute error over MSE.
- Ranking with graded relevance: NDCG. Binary relevance: MAP.
See references/metrics-catalog.md for formulas, ranges, and detailed trade-off analysis.
2. Validation Strategies
The validation strategy must match the data structure. Using random k-fold on time-series data or grouped observations produces optimistic, misleading estimates.
| Data Characteristic |
Recommended Strategy |
Why |
| Sufficient data (>50k), no structure |
Hold-out (70/15/15 or 80/10/10) |
Simple, fast, stable estimates |
| Moderate data (<50k), i.i.d. |
5- or 10-fold CV |
Reduces variance of performance estimate |
| Imbalanced classes |
Stratified k-fold CV |
Preserves class distribution in every fold |
| Temporal ordering |
Time-series CV (expanding or sliding window) |
Prevents future data leaking into training |
| Grouped observations (patients, users) |
Group k-fold |
Prevents same group appearing in train and test |
| Hyperparameter tuning + evaluation |
Nested CV (inner loop tunes, outer loop evaluates) |
Prevents selection bias from tuning on test data |
| Very small data (<500) |
Leave-one-out CV or repeated k-fold |
Maximizes training data per split |
Expanding vs sliding window for time series: Expanding window grows the training set over time (mirrors production where you retrain on all history). Sliding window uses a fixed-size recent window (better when the data distribution drifts and old data hurts).
Nested CV protocol:
- Outer loop: k-fold split producing train/test pairs.
- Inner loop: for each outer fold, run k-fold CV on the training portion to select hyperparameters.
- Retrain with selected hyperparameters on the full outer training fold, evaluate on the outer test fold.
- Report: mean and standard deviation across outer folds.
This gives an unbiased estimate of generalization performance for the tuned model.
3. Statistical Model Comparison
Reporting "Model A: 0.85, Model B: 0.83" without a significance test is not a comparison — it is anecdote. Performance differences must survive statistical scrutiny.
| Method |
When to Use |
Notes |
| Paired t-test on CV folds |
k-fold CV results, roughly normal differences |
Fast but assumes independence of folds (violated in practice) |
| Corrected resampled t-test (Nadeau-Bengio) |
k-fold CV results |
Corrects for non-independence by adjusting variance estimate; preferred over naive paired t-test |
| McNemar's test |
Two classifiers on the same test set |
Tests whether disagreement patterns are symmetric; does not need CV |
| Wilcoxon signed-rank test |
Non-normal differences, small sample of datasets |
Non-parametric; robust when normality assumption fails |
| Bayesian comparison |
Want probability statements, not p-values |
Produces P(A > B), P(rope), P(B > A); more informative than frequentist tests |
Practical protocol:
- Run both models under identical CV splits (same random seed, same folds).
- Record per-fold performance differences.
- Apply the Nadeau-Bengio corrected t-test (or Wilcoxon if differences are non-normal).
- For multiple model comparison across multiple datasets, use the Friedman test followed by Nemenyi post-hoc.
- Report effect size alongside p-values — a statistically significant but tiny improvement may not justify deployment complexity.
4. Calibration
A model that outputs 0.7 probability for an event should be right about 70% of the time. Many models (gradient-boosted trees, SVMs, neural networks) produce scores that rank well but are not calibrated probabilities.
Why calibration matters: Any decision that uses predicted probabilities directly — expected cost calculations, threshold selection, risk stratification, uncertainty-aware downstream systems — requires calibration. A well-discriminating but poorly calibrated model will set thresholds incorrectly and misestimate expected outcomes.
Diagnostic tools:
- Reliability diagram: Bin predictions by predicted probability, plot mean predicted vs mean observed. A perfectly calibrated model follows the diagonal.
- Expected Calibration Error (ECE): Weighted average of per-bin |predicted - observed|. Lower is better. Typical target: ECE < 0.05.
Calibration methods:
- Platt scaling: Fit a logistic regression on the model's raw outputs using a held-out calibration set. Works well for sigmoid-shaped distortions. Two parameters.
- Isotonic regression: Non-parametric monotonic fit. More flexible than Platt scaling but needs more calibration data (risk of overfitting with <1,000 samples).
- Temperature scaling: Single parameter (temperature T) dividing logits before softmax. Popular for neural networks, especially in multi-class settings.
Protocol: Always calibrate on a held-out set, never on training data. After calibrating, re-check the reliability diagram and ECE to confirm improvement.
5. Fairness Auditing
Model quality means nothing if the model systematically harms protected groups. Fairness auditing is not optional — it is a deployment requirement.
Core fairness criteria:
| Criterion |
Definition |
Intuition |
| Demographic Parity |
P(positive prediction) is equal across groups |
Selection rates are the same regardless of group membership |
| Equalized Odds |
TPR and FPR are equal across groups |
The model makes errors at the same rate for all groups |
| Equal Opportunity |
TPR is equal across groups |
Among true positives, all groups have equal chance of being correctly identified |
| Predictive Parity |
Precision is equal across groups |
A positive prediction means the same thing regardless of group |
The impossibility theorem: Except in trivial cases (equal base rates across groups or perfect prediction), you cannot simultaneously satisfy demographic parity, equalized odds, and predictive parity. You must choose which criterion aligns with your application's values and legal context.
Practical audit workflow:
- Identify protected attributes (even if not used as features — proxy variables can encode them).
- Compute all four criteria above, disaggregated by group.
- Choose the criterion most appropriate to the domain (e.g., equal opportunity for lending, demographic parity for hiring screens).
- Quantify disparity: ratios (e.g., adverse impact ratio > 0.8 under the 4/5 rule) or absolute differences.
- If disparities exceed thresholds, intervene: re-sample training data, apply in-processing constraints, or post-process predictions.
- Document decisions and trade-offs. Fairness is a policy choice, not a purely technical one.
6. Beyond Single Metrics
Single-number metrics compress too much information. Supplement them with deeper analysis.
- Confusion matrix deep dives: Go beyond aggregate rates. Segment by subpopulation, feature range, or data source. A model with 95% overall accuracy can have 40% accuracy on a critical subgroup.
- Error analysis — systematic vs random: Cluster misclassifications. If errors concentrate on specific patterns (short texts, low-resolution images, a demographic), the model has a systematic blind spot that more data or architectural changes can fix. Random errors suggest you are near the irreducible error floor.
- Learning curves: Plot training and validation performance vs training set size. Diverging curves (high training, low validation) signal high variance — get more data or regularize. Converging low curves signal high bias — increase model capacity.
- Prediction interval coverage: For regression, check that your 90% prediction intervals actually contain 90% of observations. Under-coverage means your uncertainty estimates are overconfident.
Common Mistakes
Reporting accuracy on imbalanced data. A 95/5 class split gives 95% accuracy by predicting the majority class every time. Use AUC-PR, F1, or MCC instead.
Data leakage in cross-validation. Fitting a scaler, selecting features, or oversampling (SMOTE) on the full dataset before splitting. All preprocessing that uses statistics from data must happen inside each fold.
Optimizing a proxy metric that diverges from business value. Improving log loss by 0.01 means nothing if the business cares about precision at a specific operating threshold. Map ML metrics to business KPIs explicitly.
Comparing models without statistical tests. A 2-point difference on one random split is noise. Use corrected resampled t-tests or Bayesian comparison on multiple folds.
Ignoring calibration before deploying probability-based decisions. Ranking ability (AUC) does not guarantee calibrated probabilities. Platt scaling or isotonic regression is cheap insurance.
Treating fairness as a post-hoc checkbox. Auditing for fairness after the model is built limits your options. Build fairness considerations into the problem formulation, data collection, and metric selection from the start.
Implementation Libraries
| Task |
Python |
R |
| Classification/regression/clustering metrics |
sklearn.metrics |
yardstick (tidymodels) |
| Visual model diagnostics (learning curves, residuals) |
yellowbrick |
performance (easystats) |
| Cross-validation, train/test splitting |
sklearn.model_selection |
rsample (tidymodels) |
| Hyperparameter tuning |
optuna, hyperopt |
tune (tidymodels) |
| Calibration (Platt, isotonic) |
sklearn.calibration |
probably |
| Fairness evaluation |
fairlearn |
fairness |
| Statistical model comparison |
baycomp, scipy.stats |
tidyposterior |
| Imbalanced data handling (SMOTE, etc.) |
imbalanced-learn |
themis (tidymodels) |
Recommended starting stack (Python): sklearn.metrics + sklearn.model_selection for core evaluation, optuna for tuning, yellowbrick for visual diagnostics, fairlearn for fairness audits.
When This Applies
Reference this skill when you are:
- Choosing which metric(s) to report for a modeling project
- Designing a cross-validation strategy for a new dataset
- Deciding between two or more candidate models
- Preparing a model for deployment and need calibrated probabilities
- Conducting a fairness or bias review before launch
- Performing error analysis to diagnose why a model underperforms
- Writing a model card or evaluation report for stakeholders
For detailed metric formulas, ranges, and trade-off analysis, see references/metrics-catalog.md.
Cross-Domain Connections
- Investing/adaptive-monitoring/performance-attribution: Model evaluation metrics map to investment performance metrics — calibration (predicted probabilities = true outcomes) parallels risk model calibration (predicted VaR = realized losses). Cross-validation strategies (expanding window, sliding window) ARE walk-forward backtesting of trading strategies.
- Investing/risk-architecture/tail-risk: Evaluating model performance in tails is critical for financial risk — standard metrics (RMSE, accuracy) fail when the cost of errors is asymmetric. Tail-risk evaluation requires metrics that weight extreme outcomes appropriately.
Related Skills
- quality-assessment — Both formalize "how good is the output" at different levels: model-evaluation for ML model performance against ground truth; quality-assessment for tasting/sensory evaluation. Shared concept (rubric-grounded scoring), different domains.
1---2name: model-evaluation3description: Model evaluation and selection frameworks for machine learning. Reference when choosing performance metrics, designing validation strategies, comparing models statistically, assessing calibration, or auditing models for fairness. Use when deciding which model to deploy or how to measure model quality.4---56# Model Evaluation — The Judge78A model that scores well on the wrong metric, validated with a leaky pipeline, and deployed without statistical rigor is worse than no model at all — it ships confident wrong answers. This skill covers the full evaluation lifecycle: picking the right metrics, validating honestly, comparing models with statistical discipline, checking calibration, and auditing for fairness before anything reaches production.910---1112## 1. Metric Selection by Task1314No single metric captures model quality. The right choice depends on task type, class balance, and what errors cost the business.1516| Task | Metric | When to Prefer |17|---|---|---|18| **Classification** | Accuracy | Balanced classes, equal error costs |19| | Precision | False positives are expensive (spam filters, fraud alerts) |20| | Recall (Sensitivity) | False negatives are dangerous (disease screening, security threats) |21| | F1 Score | Need a single number balancing precision and recall |22| | AUC-ROC | Threshold-independent ranking ability, reasonably balanced data |23| | AUC-PR | Imbalanced data — far more informative than AUC-ROC when positives are rare |24| | Log Loss | Probability quality matters, not just ranking |25| | MCC | Imbalanced data where you want a single balanced measure (-1 to +1) |26| | Cohen's Kappa | Agreement beyond chance; useful when comparing to human labelers |27| **Regression** | MSE / RMSE | Large errors are disproportionately bad; RMSE for same-unit interpretability |28| | MAE | Robust to outliers; median-focused performance |29| | MAPE | Stakeholders want percentage-based error; fails when actuals near zero |30| | R² | Explaining variance proportion; familiar to business audiences |31| | Adjusted R² | Comparing models with different feature counts |32| | Median Absolute Error | Highly robust summary when distribution of errors is skewed |33| **Ranking** | NDCG | Graded relevance; position-weighted quality |34| | MAP | Binary relevance across queries |35| | MRR | Only the first relevant result matters (e.g., question answering) |36| | Precision@k / Recall@k | Fixed-size recommendation lists; top-k retrieval |37| **Clustering** | Silhouette Score | Cluster compactness vs separation when no ground truth exists |38| | Calinski-Harabasz | Fast, favors convex clusters |39| | Davies-Bouldin | Lower is better; penalizes overlapping clusters |40| | Adjusted Rand Index | Ground truth labels available; chance-corrected agreement |4142**Key decision rules:**43- Imbalanced classification: default to AUC-PR, MCC, or F1 on the minority class. Never report accuracy alone.44- When probabilities drive decisions (setting thresholds, expected value calculations): use log loss and calibration metrics.45- Regression with outliers: prefer MAE or median absolute error over MSE.46- Ranking with graded relevance: NDCG. Binary relevance: MAP.4748See `references/metrics-catalog.md` for formulas, ranges, and detailed trade-off analysis.4950---5152## 2. Validation Strategies5354The validation strategy must match the data structure. Using random k-fold on time-series data or grouped observations produces optimistic, misleading estimates.5556| Data Characteristic | Recommended Strategy | Why |57|---|---|---|58| Sufficient data (>50k), no structure | Hold-out (70/15/15 or 80/10/10) | Simple, fast, stable estimates |59| Moderate data (<50k), i.i.d. | 5- or 10-fold CV | Reduces variance of performance estimate |60| Imbalanced classes | Stratified k-fold CV | Preserves class distribution in every fold |61| Temporal ordering | Time-series CV (expanding or sliding window) | Prevents future data leaking into training |62| Grouped observations (patients, users) | Group k-fold | Prevents same group appearing in train and test |63| Hyperparameter tuning + evaluation | Nested CV (inner loop tunes, outer loop evaluates) | Prevents selection bias from tuning on test data |64| Very small data (<500) | Leave-one-out CV or repeated k-fold | Maximizes training data per split |6566**Expanding vs sliding window for time series:** Expanding window grows the training set over time (mirrors production where you retrain on all history). Sliding window uses a fixed-size recent window (better when the data distribution drifts and old data hurts).6768**Nested CV protocol:**691. Outer loop: k-fold split producing train/test pairs.702. Inner loop: for each outer fold, run k-fold CV on the training portion to select hyperparameters.713. Retrain with selected hyperparameters on the full outer training fold, evaluate on the outer test fold.724. Report: mean and standard deviation across outer folds.7374This gives an unbiased estimate of generalization performance for the tuned model.7576---7778## 3. Statistical Model Comparison7980Reporting "Model A: 0.85, Model B: 0.83" without a significance test is not a comparison — it is anecdote. Performance differences must survive statistical scrutiny.8182| Method | When to Use | Notes |83|---|---|---|84| Paired t-test on CV folds | k-fold CV results, roughly normal differences | Fast but assumes independence of folds (violated in practice) |85| Corrected resampled t-test (Nadeau-Bengio) | k-fold CV results | Corrects for non-independence by adjusting variance estimate; preferred over naive paired t-test |86| McNemar's test | Two classifiers on the same test set | Tests whether disagreement patterns are symmetric; does not need CV |87| Wilcoxon signed-rank test | Non-normal differences, small sample of datasets | Non-parametric; robust when normality assumption fails |88| Bayesian comparison | Want probability statements, not p-values | Produces P(A > B), P(rope), P(B > A); more informative than frequentist tests |8990**Practical protocol:**911. Run both models under identical CV splits (same random seed, same folds).922. Record per-fold performance differences.933. Apply the Nadeau-Bengio corrected t-test (or Wilcoxon if differences are non-normal).944. For multiple model comparison across multiple datasets, use the Friedman test followed by Nemenyi post-hoc.955. Report effect size alongside p-values — a statistically significant but tiny improvement may not justify deployment complexity.9697---9899## 4. Calibration100101A model that outputs 0.7 probability for an event should be right about 70% of the time. Many models (gradient-boosted trees, SVMs, neural networks) produce scores that rank well but are not calibrated probabilities.102103**Why calibration matters:** Any decision that uses predicted probabilities directly — expected cost calculations, threshold selection, risk stratification, uncertainty-aware downstream systems — requires calibration. A well-discriminating but poorly calibrated model will set thresholds incorrectly and misestimate expected outcomes.104105**Diagnostic tools:**106- **Reliability diagram:** Bin predictions by predicted probability, plot mean predicted vs mean observed. A perfectly calibrated model follows the diagonal.107- **Expected Calibration Error (ECE):** Weighted average of per-bin |predicted - observed|. Lower is better. Typical target: ECE < 0.05.108109**Calibration methods:**110- **Platt scaling:** Fit a logistic regression on the model's raw outputs using a held-out calibration set. Works well for sigmoid-shaped distortions. Two parameters.111- **Isotonic regression:** Non-parametric monotonic fit. More flexible than Platt scaling but needs more calibration data (risk of overfitting with <1,000 samples).112- **Temperature scaling:** Single parameter (temperature T) dividing logits before softmax. Popular for neural networks, especially in multi-class settings.113114**Protocol:** Always calibrate on a held-out set, never on training data. After calibrating, re-check the reliability diagram and ECE to confirm improvement.115116---117118## 5. Fairness Auditing119120Model quality means nothing if the model systematically harms protected groups. Fairness auditing is not optional — it is a deployment requirement.121122**Core fairness criteria:**123124| Criterion | Definition | Intuition |125|---|---|---|126| Demographic Parity | P(positive prediction) is equal across groups | Selection rates are the same regardless of group membership |127| Equalized Odds | TPR and FPR are equal across groups | The model makes errors at the same rate for all groups |128| Equal Opportunity | TPR is equal across groups | Among true positives, all groups have equal chance of being correctly identified |129| Predictive Parity | Precision is equal across groups | A positive prediction means the same thing regardless of group |130131**The impossibility theorem:** Except in trivial cases (equal base rates across groups or perfect prediction), you cannot simultaneously satisfy demographic parity, equalized odds, and predictive parity. You must choose which criterion aligns with your application's values and legal context.132133**Practical audit workflow:**1341. Identify protected attributes (even if not used as features — proxy variables can encode them).1352. Compute all four criteria above, disaggregated by group.1363. Choose the criterion most appropriate to the domain (e.g., equal opportunity for lending, demographic parity for hiring screens).1374. Quantify disparity: ratios (e.g., adverse impact ratio > 0.8 under the 4/5 rule) or absolute differences.1385. If disparities exceed thresholds, intervene: re-sample training data, apply in-processing constraints, or post-process predictions.1396. Document decisions and trade-offs. Fairness is a policy choice, not a purely technical one.140141---142143## 6. Beyond Single Metrics144145Single-number metrics compress too much information. Supplement them with deeper analysis.146147- **Confusion matrix deep dives:** Go beyond aggregate rates. Segment by subpopulation, feature range, or data source. A model with 95% overall accuracy can have 40% accuracy on a critical subgroup.148- **Error analysis — systematic vs random:** Cluster misclassifications. If errors concentrate on specific patterns (short texts, low-resolution images, a demographic), the model has a systematic blind spot that more data or architectural changes can fix. Random errors suggest you are near the irreducible error floor.149- **Learning curves:** Plot training and validation performance vs training set size. Diverging curves (high training, low validation) signal high variance — get more data or regularize. Converging low curves signal high bias — increase model capacity.150- **Prediction interval coverage:** For regression, check that your 90% prediction intervals actually contain 90% of observations. Under-coverage means your uncertainty estimates are overconfident.151152---153154## Common Mistakes1551561. **Reporting accuracy on imbalanced data.** A 95/5 class split gives 95% accuracy by predicting the majority class every time. Use AUC-PR, F1, or MCC instead.1571582. **Data leakage in cross-validation.** Fitting a scaler, selecting features, or oversampling (SMOTE) on the full dataset before splitting. All preprocessing that uses statistics from data must happen inside each fold.1591603. **Optimizing a proxy metric that diverges from business value.** Improving log loss by 0.01 means nothing if the business cares about precision at a specific operating threshold. Map ML metrics to business KPIs explicitly.1611624. **Comparing models without statistical tests.** A 2-point difference on one random split is noise. Use corrected resampled t-tests or Bayesian comparison on multiple folds.1631645. **Ignoring calibration before deploying probability-based decisions.** Ranking ability (AUC) does not guarantee calibrated probabilities. Platt scaling or isotonic regression is cheap insurance.1651666. **Treating fairness as a post-hoc checkbox.** Auditing for fairness after the model is built limits your options. Build fairness considerations into the problem formulation, data collection, and metric selection from the start.167168---169170## Implementation Libraries171172| Task | Python | R |173|------|--------|---|174| Classification/regression/clustering metrics | `sklearn.metrics` | `yardstick` (tidymodels) |175| Visual model diagnostics (learning curves, residuals) | `yellowbrick` | `performance` (easystats) |176| Cross-validation, train/test splitting | `sklearn.model_selection` | `rsample` (tidymodels) |177| Hyperparameter tuning | `optuna`, `hyperopt` | `tune` (tidymodels) |178| Calibration (Platt, isotonic) | `sklearn.calibration` | `probably` |179| Fairness evaluation | `fairlearn` | `fairness` |180| Statistical model comparison | `baycomp`, `scipy.stats` | `tidyposterior` |181| Imbalanced data handling (SMOTE, etc.) | `imbalanced-learn` | `themis` (tidymodels) |182183**Recommended starting stack (Python):** `sklearn.metrics` + `sklearn.model_selection` for core evaluation, `optuna` for tuning, `yellowbrick` for visual diagnostics, `fairlearn` for fairness audits.184185## When This Applies186187Reference this skill when you are:188- Choosing which metric(s) to report for a modeling project189- Designing a cross-validation strategy for a new dataset190- Deciding between two or more candidate models191- Preparing a model for deployment and need calibrated probabilities192- Conducting a fairness or bias review before launch193- Performing error analysis to diagnose why a model underperforms194- Writing a model card or evaluation report for stakeholders195196For detailed metric formulas, ranges, and trade-off analysis, see `references/metrics-catalog.md`.197198## Cross-Domain Connections199200- **Investing/adaptive-monitoring/performance-attribution**: Model evaluation metrics map to investment performance metrics — calibration (predicted probabilities = true outcomes) parallels risk model calibration (predicted VaR = realized losses). Cross-validation strategies (expanding window, sliding window) ARE walk-forward backtesting of trading strategies.201- **Investing/risk-architecture/tail-risk**: Evaluating model performance in tails is critical for financial risk — standard metrics (RMSE, accuracy) fail when the cost of errors is asymmetric. Tail-risk evaluation requires metrics that weight extreme outcomes appropriately.202203204205## Related Skills206207- **quality-assessment** — Both formalize "how good is the output" at different levels: model-evaluation for ML model performance against ground truth; quality-assessment for tasting/sensory evaluation. Shared concept (rubric-grounded scoring), different domains.