Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 05 / Topic 7 of 7

Comparing models fairly

A fair bake-off fixes everything except the model: same split, same preprocessing, same metric.

# examples/02_comparing_three_models_with_the_same.py (abridged)
models = {
    "logistic regression": LogisticRegression(max_iter=1000),
    "random forest": RandomForestClassifier(n_estimators=200, random_state=42),
    "gradient boosting": HistGradientBoostingClassifier(random_state=42),
}
for name, clf in models.items():
    pipe = make_pipeline(prep, clf).fit(X_tr, y_tr)
    auc = roc_auc_score(y_te, pipe.predict_proba(X_te)[:, 1])
    print(f"{name:20s} ROC-AUC = {auc:.3f}")
# logistic regression ROC-AUC = 0.811
# random forest ROC-AUC = 0.755
# gradient boosting ROC-AUC = 0.765

The simple model wins here — the churn data was generated from a logistic formula, so a logistic model matches its true shape. The lesson generalises: always include a simple baseline in the bake-off. Complex models win often, not always, and you only know by measuring.

🧪 Quick quiz

  1. On the course churn data, which model scored the highest ROC-AUC?
Show the answer

Logistic regression: 0.811 vs 0.765 (gradient boosting) and 0.755 (random forest). The data follows a logistic shape, so the simple model fits best — which is exactly why a simple baseline belongs in every comparison.

Done here? The practice set for Part 5 — 4 exercises with solutions — is on the part page.

Search the guide