Which one stat best splits Legendary Pokémon from the rest?
Lesson 16.2 · 20 Questions, Played by a Computer
Felix · Rosa
“Is attack over 100?” splits the pile. “Is HP over 50?” barely does.
Felix is playing 20 Questions with Pokémon.
Is its attack over 100? Its speed over 90? Each question splits the pile in two.
Rosa notices that some questions split it cleanly and some barely help.
There’s a best first question, and the data can tell you which.
The short answer
Attack, with a cutoff around the low 100s, in this table. It alone sorts most Pokémon correctly. Add a second question on speed inside the high-attack branch and the tree gets nearly all of them. Felix feels like he’s cheating at 20 Questions. He is.
Try it yourself
Pick a stat. The app finds the best cutoff for it and shows how well that one question separates Legendary from regular. Try to find the best stat.
What you just did has a name
Decision tree
A decision tree is a classifier made of yes/no questions arranged like a flowchart.
Each question splits the data; the leaves at the bottom give the answer.
It’s trained by picking, at every step, the question that separates the categories best.
You can read the whole thing, which is rare for a model.
A few more things
The best question first
The tree tries every column and every cutoff and keeps the split that sorts the most examples correctly. That’s the root. Then it does it again inside each branch.
You can read it
“If attack is over 105 and speed is over 90, probably Legendary.” A person can follow that. Neural networks (Module 20) don’t offer this, which is why trees stay popular anywhere someone has to explain a decision.
One question is rarely enough
The best single stat gets most Legendaries but misses some and catches a few strong regulars. A second question inside each branch cleans up. Trees grow until the leaves are pure, or until you stop them.
Go deeper
The longer version, if you want it.
Forests
A single tree grown until every leaf is pure memorizes the training data (Module 18’s problem, exactly). The fix that dominates real-world tabular data: grow hundreds of trees, each on a random slice of the rows and a random subset of the columns, and let them vote. That’s a random forest. Each tree is a little wrong in its own way, and the vote cancels the noise.
Forests and their cousins (gradient-boosted trees) win most competitions on spreadsheet-shaped data. Neural networks win on images, sound and text. Knowing which is which is a big part of choosing a model.
Quick check
A garden app decides “will this plant survive the winter” like this: Is it tropical? Yes. Does it live indoors? No. Won’t survive. What did you just walk through?
Let’s take it slower
Think of it as a flowchart the data drew for itself. Start at the top with one yes/no question. Each answer sends you down a different branch to the next question, and you keep going until you hit a box with no more questions, just an answer. That bottom box is a leaf. Training the tree means, at every fork, testing every possible question and keeping the one that sorts the past examples most cleanly. Because the whole thing is questions and answers, a person can trace exactly why it decided what it decided.
More examples
The triage flowchart
An emergency room app asks: chest pain? Over 50? Short of breath? and lands on a priority level. A tree built from past visits chose those questions and cutoffs. A nurse can read every branch, which is why hospitals like trees for this.
The loan officer’s sentence
A bank has to tell you why it said no. A tree can: “income under $40,000 and two missed payments.” A model that can’t be read into a sentence can’t do that, so trees keep the job.
Back to the question
So which stat splits best?
Show the answer
Attack, with a cutoff around the low 100s, in this table. It alone sorts most Pokémon correctly. Add a second question on speed inside the high-attack branch and the tree gets nearly all of them. Felix feels like he’s cheating at 20 Questions. He is.
One last question
Build how a decision tree picks its first question.
Tap the pieces in order. Tap one again to take it back.
Talk Card
Talk Card · 16.2
A decision tree plays 20 Questions with the data, asking one yes/no question at a time, each chosen because it splits the examples best. You can read the whole thing.
Data to AI · pettigrewlab.com/learn

