Learn / ML & Data Foundations / Module 02

ML & Data Foundations · Module 02

Choosing Metrics on Imbalanced Data and Tree Ensembles

Understand why accuracy fails on rare events like fraud or equipment faults, how to read PR-AUC vs. ROC-AUC, and why tree ensembles shine on tabular data.

13 min Foundations Updated 2026-12-03 MetricsPR-AUCImbalanced DataTrees

<!-- Thompson Axiomata LLC — Brent Alexander Thompson -->

Why 99.8% accuracy can be completely useless

Imagine a credit-card fraud dataset (or an inverter fault log) where 0.2% of rows are actual incidents and 99.8% are normal.

A broken model that predicts "normal" for every single row gets 99.8% accuracy—and catches zero fraud.

Whenever positive events are rare, switch immediately to Precision, Recall, and PR-AUC:

MetricPlain-English QuestionWhen to prioritize it
PrecisionWhen the model raises an alarm, how often is it actually right?False alarms are expensive (wasted field crew dispatches, blocked legitimate users).
RecallOut of all real incidents, how many did the model catch?Missing an incident is dangerous or costly (safety faults, severe fraud).
F1 ScoreHarmonic mean balancing Precision and Recall at one threshold.Quick single-threshold summary.
PR-AUC (Average Precision)Area under the Precision–Recall curve across all thresholds.Best single curve summary for heavily imbalanced classes.

Separate ranking from thresholding

Most classifiers output a probability score (predict_proba) between 0 and 1. The default cutoff of 0.50 is arbitrary.

  1. Evaluate model quality across thresholds using PR-AUC.
  2. Pick the operating threshold on your validation set to hit your real operational constraint (for example, "catch at least 85% of faults while keeping false alarms under 5 per day").
  3. Report final Precision and Recall once on the untouched test set.
python
from sklearn.metrics import average_precision_score, precision_recall_curve

probs = model.predict_proba(X_val)[:, 1]
pr_auc = average_precision_score(y_val, probs)
precision, recall, thresholds = precision_recall_curve(y_val, probs)

print(f"Validation PR-AUC: {pr_auc:.3f}")

Why tree ensembles dominate tabular baselines

For structured tables (mixed numeric features, missing values, non-linear thresholds), Decision Trees, Random Forests, and Gradient Boosted Trees (such as HistGradientBoostingClassifier or XGBoost) are hard to beat:

  • Single Decision Tree: easy to read and explain, but prone to overfitting if left deep and unpruned.
  • Random Forest: trains many deep trees on random subsets of rows and features and averages them—dramatically cutting variance.
  • Gradient Boosting: trains shallow trees sequentially, where each new tree corrects the residual mistakes of the ensemble so far—often delivering top accuracy with strong regularization (max_depth, learning_rate, min_samples_leaf).

<!-- Thompson Axiomata LLC — Brent Alexander Thompson -->

Finished this module?

Mark it complete to update your browser-local progress bar for ML & Data Foundations.