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?

The flexible models (forest, boosting, a network, an RBF SVM) can bend to any of these shapes, so they're rarely far behind; the simple ones (a line, naive Bayes, one tree) are either the best, when their assumption matches (the diagonal for the line), or far behind, when it doesn't (the checkerboard). Which one tops the list moves with the data and the noise.

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.

ModelBank calls
AUC ↑
Elevator outages
AUC ↑
Digits
accuracy ↑
Ridership
error ↓
Average rank
Logistic / linear (1)0.7790.8950.9690.3692.5
k-nearest neighbors (3)0.7380.8660.9420.6705.8
Naive Bayes (4)0.7700.8550.836n/a5.3
Decision tree (5)0.7620.7960.7870.3385.8
Random forest (6)0.7730.8610.9670.3784.1
Boosted trees (7)0.7600.8760.9730.3553.5
SVM, RBF (8)0.7110.8530.9820.2364.0
MLP (9)0.7730.7200.9620.2664.4

And what they cost (training seconds on a laptop · size of the saved model):

ModelBank calls (7,722 rows)Digits (1,347 rows, 64 columns)Readable?
Logistic / linear0.01 s · 4 kB0.01 s · 8 kBYes: a weight per column
k-NN0 s · 3.8 MB (it is the data)0 s · 0.7 MBPer prediction: "these neighbors"
Naive Bayes0 s · 4 kB0 s · 11 kBYes: evidence per feature
Decision tree0.02 s · 37 kB0.01 s · 12 kBYes, if shallow: print the rules
Random forest0.2 s · 25 MB0.2 s · 9 MBOnly through importance tools
Boosted trees0.6 s · 0.36 MB3.7 s · 2.3 MBOnly through importance tools
SVM, RBF2.7 s · 1.4 MB0.1 s · 0.4 MBNo
MLP0.1 s · 0.1 MB0.06 s · 0.12 MBNo

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?

Resampling the 321 test outages 1,000 times (probability lesson 4's bootstrap), the 95% interval for "logistic minus boosting" was −0.013 to +0.055; on the 2,575 bank test calls, 0.000 to 0.037. So the line is at least as good, and maybe better, but a single split can't rank models that are this close. Report intervals, use cross-validation, and decide on other grounds (readability, size, speed) when scores tie.

3. What the table says

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)
  1. 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.
  2. 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).
  3. 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).
  4. 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.
  5. 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 situationStart withThen try
Any table, first hourLogistic or linear regression (a baseline you'll compare everything to)Boosted trees
A table, thousands to millions of rows, interactionsBoosted trees (LightGBM, XGBoost, CatBoost) with early stoppingA forest as a low-effort check
Many categories with many valuesCatBoost, or out-of-fold target encodingAn MLP with embeddings, at scale
Must explain every decision (credit, health)Logistic regression or a shallow treeBoosted trees with monotone constraints and explanations
Few labeled examples, textNaive Bayes, then a linear SVM or logistic regression on tf-idfEmbeddings from a pretrained model (stage 6)
Meaningful distances, medium data (measurements, small images)k-NN as a baseline, an RBF SVMA CNN for real images (stage 5)
Images, audio, text, videoPretrained networks (stages 5 and 6)Fine-tuning
A time seriesSeasonal 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 phoneLinear model or a small treeSmall boosted model, quantized network (serving lesson)
No labels at allk-means or a Gaussian mixture for groups; PCA to see the structureIsolation 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

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