Learn machine learning · part 2 · session 1

Cuts by hand

How can a sequence of simple questions sort examples? Start with one parcel, then build a tree and test its answers on loan examples.

After this session you will be able to read a decision tree as rectangles on a picture, and cut one by hand.

tree.handSession 2.1About 30 minutesYour check: reach the stated target

The gate is held-out accuracy strictly above 0.720. No 1.1 score is in your notebook, so the target is the floor, 0.720. You need to beat that number on the rows held back. The floor is 0.720, high enough to require real cuts, and the cap is 0.760, low enough to stay reachable with two columns and three cuts.

01 · The question

How can one question sort a parcel?

illustrative

A parcel weighs 2.5 kg. A sorting rule asks whether it weighs at most 2 kg. Predict which route it takes before changing the limit.

Same parcel

2.5 kg

One question

At most 2 kg?

Route taken

No → heavier-parcel route

2.5 is above 2, so the parcel follows the “No” branch.

A decision tree repeats this pattern: ask a question, follow a branch, then ask another question or give an answer. This hand-written sorting rule illustrates the structure; it was not learned from data. The loan exercise below uses examples to give each final group its most common outcome.

Essential takeaway: a question separates cases using one property. Weight alone cannot tell you whether a parcel is fragile.

Explain it back: two fruit of the same colour

A red apple and a red cherry both take the “red” branch. What other question could help separate them, and why does colour alone fail?

Compare with one explanation

Both satisfy the same colour question, so they stay together. A question about size could separate these two examples. It would still need checking on other fruit: one useful split does not guarantee every answer is right.

This first look does not record a prediction or pass the course gate. Continue below to build and test your tree.

A is not mysterious once you have drawn one. Two columns on the axes, one straight cut across the picture, then one more cut inside each half. That is a depth-2 tree, and three cuts is all you get here. Choose a column and a value at each node from the lists, and the rectangles redraw. Nothing is searching on your behalf yet; every cut is yours.

The first cut is the root. Each half it makes is a child. A child you do not cut again is a leaf: every application landing there gets the same answer, the commonest outcome among the rows inside it. One cut, one question about one column, is a .

The target is the score you reached with rules in session 1.1, because the point is to see the same idea in a shape you can look at.

Data: synthetic loan applications, seed 7, split 1,200 training and 400 validation rows. debt_ratio on x, years_employed on y. 600 of 1,200 training rows drawn; all 1,200 scored.

syntheticseed 7

02 · Predict

Before anything runs

Three straight cuts, each one parallel to an axis, on two columns, against your own rules from 1.1. Which wins on held-out rows?

Three straight cuts, each one parallel to an axis, on two columns, against your own rules from 1.1. Which wins on held-out rows?

Choose something first.

03 · Try it

From a row to a dot

computed in this browserseed 7 · your current root cut

Three rows, and the two columns the picture uses.

Every dot is one application. A cut is one rule, drawn.

Step 1 · the root cut

Root node

0.02 to 0.83

What that cut does to the training rows

Root cut, debt_ratio at or below 0.40. Left 648 rows, 552 repaid, Gini 0.252. Right 552 rows, 286 repaid, Gini 0.499.

Step 2 · one cut inside each half

Left child, at or below the root cut

This node stays a leaf. Every row that reaches it takes the majority class of the rows inside it.

Right child, above the root cut

This node stays a leaf. Every row that reaches it takes the majority class of the rows inside it.

Step 3 · score it

Scored trees: 0

Your regions over the training rows

computed in this browserseed 7

This picture is drawn in your browser from the seed, so it appears once the page is running.

Hollow circle: repaid. Filled square: did not repay. A shaded region is one the tree scores as did not repay.

Root cut, debt_ratio at or below 0.40. Left 648 rows, 552 repaid, Gini 0.252. Right 552 rows, 286 repaid, Gini 0.499. Nothing is scored on held-out rows until you press the button.

Synthetic, seed 7. 600 of 1,200 training rows drawn; all 1,200 scored.

( is a mixedness score: 0 means the rows on that side are all one outcome, 0.5 means an even mix. It is the subject of the next session.)

Ask for a hint

Rungs open as you run the session, not as time passes. You have run it 0 times.

1. A question: available after 3 evaluated runs.

2. A narrowing: available after 5 evaluated runs.

3. A worked fragment, on a different example: available after 7 evaluated runs.

4. The answer, with a working configuration: available after 9 evaluated runs.

04 · Compare

Place your cuts and press "Score on held-out". The verdict appears with the number.

05 · Check your understanding

Your check: reach the stated target

not yet

Held-out accuracy strictly above 0.720. No 1.1 score is in your notebook, so the target is the floor, 0.720. You need to beat that number on the rows held back. The floor is 0.720, high enough to require real cuts, and the cap is 0.760, low enough to stay reachable with two columns and three cuts.

Not met yet. Keep working the session.

Save your takeaway

Your takeaway

Edit it into your own words, or keep the line as it is.