PA Lab · Module 01 · A visual introduction

The data finds its own forks in the road

Decision trees, learned with your eyes — not with formulas or code. Scroll along as housing data from San Francisco and New York grows into a single tree.

SCROLL
01 · The problem

Which city is this home in?

Here are home listings. Each dot is one home: ● San Francisco or ● New York. Hide the city names, and all that's left is numbers.

The goal of machine learning is to find a rule — from the data alone — that guesses the city using only those numbers.

02 · One dimension

Start with elevation

Take just one recorded value per home — elevation — and line the dots up vertically.

See a pattern? San Francisco, city of hills, spreads its homes far up the slope, while New York's homes crowd the low ground. If a home sits very high, it's very likely San Francisco.

03 · Add a dimension

Add price, and the picture sharpens

Now spread the dots horizontally by price per m² to make a scatter plot.

Even at low elevations the two cities start to separate: on the same low ground, New York homes tend to be clearly more expensive. Every added dimension is more material for drawing boundaries.

04 · The first boundary

Draw one line

Let's find the line that splits the data most cleanly in two. After sweeping every candidate, the algorithm's best cut is at m of elevation.

Above the line: almost entirely San Francisco. This one line is our first splitting rule.

05 · A fork = a node

Turn the line into a question, and you get a tree

That line reads as a question: “Is elevation ≥ m?” — a fork (node) that splits into yes / no.

But one line leaves plenty of misclassifications. The dots ringed in red are the homes still sorted into the wrong city.

06 · Recursion

Split again, inside each region

The trick is simple: repeat the same process inside each region. The lowlands split next on price; inside that, on elevation again… questions beget questions, and the tree grows.

Watch the red-ringed errors thin out as the boundaries multiply.

07 · Training complete

Training accuracy:

Keep adding splits, and the model can get the training data almost perfectly right — the regions have been carved fine enough to wrap around nearly every single dot.

But — can we actually trust this report card?

08 · The real exam

Meeting data it has never seen

Drop test homes — which the model has never seen — onto the same boundaries. Accuracy falls to .

The model memorized the training data's little accidents as if they were rules. This is overfitting — the most fundamental dilemma in machine learning.

Finale

Test data, flowing down the tree

Now send the test set through the finished tree. Each home answers the question at every fork, rides the branches down, and is judged by the majority vote of the leaf where it lands.

Classified 0/0
Correct 0
Wrong 0
Test accuracy

To recap

  1. Machine learning means the rules are not hand-coded by a person — they are built by finding statistical patterns in data.
  2. A decision tree asks “which variable, split at which value?” over and over, recursively carving the data into ever-purer regions.
  3. Deeper splits improve the score on training data — but can make it worse on data the model has never seen. That gap is overfitting.
  4. So the mark of a good model is not its training score, but its generalization to unseen data.
For SOA Exam PA candidates: this module covers the intuition behind tree-based models — recursive binary splitting, decision boundaries, and the train/test gap that motivates pruning and cross-validation. Next modules will build on this: bagging & random forests, boosting, and GLMs. Back to PA Lab →