AI from scratch · Model zoo 10 of 10 · Which model when
Which model when: the bake-off
Nine pages, nine models, each with its picture, its math and its failure modes. This page puts them side by side: first on the same toy maps, where you can see each model's built-in assumptions as shapes, then on four real datasets from this course, with scores, training times and sizes. The results are less tidy than the folklore, and the reasons why are the most useful thing on the page.
1. The whole zoo on one map
Each panel is one model with sensible settings, trained on the same 200 dots. The shapes are the models' assumptions made visible: straight edges for logistic regression, axis-aligned clouds for naive Bayes, boxes for trees, smooth bubbles for the SVM.
Try every dataset. Is there one model that's never more than a few points behind the best?
- Logistic regression
- The forest, boosting and the MLP come close on every one; no single model is always first
- Naive Bayes
2. The bake-off: four real datasets
Every model with sensible defaults (scaled inputs where they matter, early stopping for the network, a standardized target for regression), no tuning, one split each: bank calls (AUC, 2,575 test calls), this site's elevator outages (will it last over 4 hours? AUC on the last days, 321 outages), handwritten digits (accuracy, 450 test digits) and subway ridership (mean error in millions of riders a day over 2024). The practice notebook runs it all.
| Model | Bank calls AUC ↑ | Elevator outages AUC ↑ | Digits accuracy ↑ | Ridership error ↓ | Average rank |
|---|---|---|---|---|---|
| Logistic / linear (1) | 0.779 | 0.895 | 0.969 | 0.369 | 2.5 |
| k-nearest neighbors (3) | 0.738 | 0.866 | 0.942 | 0.670 | 5.8 |
| Naive Bayes (4) | 0.770 | 0.855 | 0.836 | n/a | 5.3 |
| Decision tree (5) | 0.762 | 0.796 | 0.787 | 0.338 | 5.8 |
| Random forest (6) | 0.773 | 0.861 | 0.967 | 0.378 | 4.1 |
| Boosted trees (7) | 0.760 | 0.876 | 0.973 | 0.355 | 3.5 |
| SVM, RBF (8) | 0.711 | 0.853 | 0.982 | 0.236 | 4.0 |
| MLP (9) | 0.773 | 0.720 | 0.962 | 0.266 | 4.4 |
And what they cost (training seconds on a laptop · size of the saved model):
| Model | Bank calls (7,722 rows) | Digits (1,347 rows, 64 columns) | Readable? |
|---|---|---|---|
| Logistic / linear | 0.01 s · 4 kB | 0.01 s · 8 kB | Yes: a weight per column |
| k-NN | 0 s · 3.8 MB (it is the data) | 0 s · 0.7 MB | Per prediction: "these neighbors" |
| Naive Bayes | 0 s · 4 kB | 0 s · 11 kB | Yes: evidence per feature |
| Decision tree | 0.02 s · 37 kB | 0.01 s · 12 kB | Yes, if shallow: print the rules |
| Random forest | 0.2 s · 25 MB | 0.2 s · 9 MB | Only through importance tools |
| Boosted trees | 0.6 s · 0.36 MB | 3.7 s · 2.3 MB | Only through importance tools |
| SVM, RBF | 2.7 s · 1.4 MB | 0.1 s · 0.4 MB | No |
| MLP | 0.1 s · 0.1 MB | 0.06 s · 0.12 MB | No |
Logistic regression beat boosted trees on the elevator outages by 0.019 AUC on 321 test outages. How confident should you be that it's really better there?
- Very: 0.019 is a clear win
- Not at all: they're identical
- Not very: a bootstrap of the test outages puts the difference anywhere from −0.013 to +0.055
3. What the table says
- No model wins everywhere. The line won two datasets, the SVM the other two, and boosting, the folklore champion, won none, while never being far off (2nd, 2nd, 4th, 6th).
- Small data favors strong assumptions. All four datasets are small (300 to 8,000 training rows). Simple models with the right built-in assumption (effects add up for the bank calls; distance between images means similarity for digits) need less data to learn it. Boosting's edge grows with rows and interactions, which these sets don't have much of.
- The data's shape picks the winner. Ridership has a level that keeps shifting: trees and forests can't predict outside the levels they saw (0.34 to 0.38), the line overshoots its trend (0.37), and the models that combine smoothly (SVM 0.24, MLP 0.27) adapted best.
- Costs differ by 1,000×. A forest weighs 25 MB where a line weighs 4 kB; k-NN carries its whole training set. When scores tie, that decides.
Choose by the data's shape, its size and what you need besides accuracy, start with a simple baseline, and don't trust a ranking from one split when the scores are close.
Why no model can win everywhere (no free lunch)
- A model only sees the training rows. For any row it hasn't seen, the training data alone doesn't say what the label is: many rules fit the same training data and disagree off it.
- Every model breaks that tie with built-in assumptions: "nearby points share labels" (k-NN, SVM), "effects add up" (linear), "the answer changes in steps along columns" (trees).
- Average over every possible way the unseen labels could go, and each assumption is right exactly as often as it's wrong: every model has the same average accuracy off the training data (Wolpert, 1996).
- So "the best model" only means something for a kind of problem. Real problems aren't random, they have structure, and a model wins when its assumptions match that structure.
- That's the practical method: look at the data (is it a table, an image, a time series? how many rows? are effects additive?) and pick the models whose assumptions fit, then let validation data decide among them.
4. A guide to choosing
| Your situation | Start with | Then try |
|---|---|---|
| Any table, first hour | Logistic or linear regression (a baseline you'll compare everything to) | Boosted trees |
| A table, thousands to millions of rows, interactions | Boosted trees (LightGBM, XGBoost, CatBoost) with early stopping | A forest as a low-effort check |
| Many categories with many values | CatBoost, or out-of-fold target encoding | An MLP with embeddings, at scale |
| Must explain every decision (credit, health) | Logistic regression or a shallow tree | Boosted trees with monotone constraints and explanations |
| Few labeled examples, text | Naive Bayes, then a linear SVM or logistic regression on tf-idf | Embeddings from a pretrained model (stage 6) |
| Meaningful distances, medium data (measurements, small images) | k-NN as a baseline, an RBF SVM | A CNN for real images (stage 5) |
| Images, audio, text, video | Pretrained networks (stages 5 and 6) | Fine-tuning |
| A time series | Seasonal naive baseline, then boosted trees on lag features (the time-series elective) | Predict the change, not the level |
| Must run in 1 ms on a phone | Linear model or a small tree | Small boosted model, quantized network (serving lesson) |
| No labels at all | k-means or a Gaussian mixture for groups; PCA to see the structure | Isolation forest for anomalies |
The unsupervised members of the zoo already have their pages: k-means, Gaussian mixtures and anomaly detection (groups and odd ones out, when there are no labels), and PCA with the SVD behind it (the few directions that hold most of the variation: for plots, compression, and fewer columns before k-NN or an SVM).
Where it breaks: how bake-offs mislead
- One split. As measured above, differences of 0.02 AUC on a few hundred test rows are within noise. Use cross-validation and report intervals (probability lesson 4).
- Defaults against tuned. XGBoost went from 0.744 to 0.774 with tuning (page 7), more than the gap between most models here. Compare models at equal tuning effort, or say you didn't tune.
- Test reuse. Every look at the test set to pick a model leaks a little of it into your choice. Pick on validation data; touch the test set once.
- The wrong metric. AUC ranks; it doesn't check calibration (naive Bayes ranks well with bad probabilities) or cost (chapter 12). Score what the decision needs.
- Leaderboards. Many teams trying many models on one public test set will find one that's lucky on it. A model that ranks first by 0.002 usually isn't first on the next data.
That's the zoo. From here, the path continues with what networks do that no model on these pages can: seeing.
All chapters: AI from scratch. Bank marketing: Moro, Cortez and Rita (2014), UCI, CC BY 4.0. Elevator outages: this site's MTA archive. Digits: UCI, via scikit-learn. Ridership: MTA, data.ny.gov.
Last updated