CS203 · DATA SCIENCE FUNDAMENTALS

How a decision tree learns

Will a delivery take more than 30 minutes? Follow a prediction, measure how mixed the outcomes are, then choose each question yourself.

Which question belongs at this node?

Choose a question to preview its two groups. Keep any split to grow your own tree. At the next node, only the orders that reached it take part.

● On time   ▲ Late

Training data and cutoff choices
OrderkmWeatherOutcome
A2DryOn time
B2RainOn time
C3DryOn time
D3RainLate
E4DryLate
F4RainLate
G5DryOn time
H5RainLate

Test one cutoff halfway between each pair of neighboring distances present at the selected node. These represent all distinct nonempty distance splits. Rain gives one further question when both weather values occur.

Root · Distance ≤ 2.5 km?
  • Yes → 0/2 late · on time
  • No → 4/6 late · late

Yes branch stops here. All 2 labels agree (Gini = 0).

Examine the No node · C, D, E, F, G, H

Before splitting · C, D, E, F, G, H · Gini = 2 × (4/6) × (2/6) = 4/9 (0.444)

Try a candidate question

Distance ≤ 3.5 km?

Yes · 2 orders
● C▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

No · 4 orders
▲ E▲ F● G▲ H
3 late · 1 on time

Gini = 2 × (3/4) × (1/4) = 3/8

Weighted Gini = (2/6) × 1/2 + (4/6) × 3/8 = 5/12 ≈ 0.417

Drop = 4/9 − 5/12 = 1/36 ≈ 0.028 · another question gives a larger drop

Keep this split →

Distance ≤ 4.5 km?

Yes · 4 orders
● C▲ D▲ E▲ F
3 late · 1 on time

Gini = 2 × (3/4) × (1/4) = 3/8

No · 2 orders
● G▲ H
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (4/6) × 3/8 + (2/6) × 1/2 = 5/12 ≈ 0.417

Drop = 4/9 − 5/12 = 1/36 ≈ 0.028 · another question gives a larger drop

Keep this split →

Rain at checkout?

Yes · 3 orders
▲ D▲ F▲ H
3 late · 0 on time

Gini = 2 × (3/3) × (0/3) = 0

No · 3 orders
● C▲ E● G
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

Weighted Gini = (3/6) × 0 + (3/6) × 4/9 = 2/9 ≈ 0.222

Drop = 4/9 − 2/9 = 2/9 ≈ 0.222 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 3.5 km?0.4170.028
Distance ≤ 4.5 km?0.4170.028
Rain at checkout?0.2220.222
Trace unseen orders through this tree

P · 4.2 km, rain · No → 4/6 late · late

Q · 3.2 km, dry · No → 4/6 late · late

Root · Distance ≤ 2.5 km?
  • Yes → 0/2 late · on time
  • No → Distance ≤ 3.5 km?
    • Yes → 1/2 late · late
    • No → 3/4 late · late

Yes branch stops here. All 2 labels agree (Gini = 0).

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → No → 3/4 late · late

Q · 3.2 km, dry · No → Yes → 1/2 late · late

Root · Distance ≤ 2.5 km?
  • Yes → 0/2 late · on time
  • No → Distance ≤ 4.5 km?
    • Yes → 3/4 late · late
    • No → 1/2 late · late

Yes branch stops here. All 2 labels agree (Gini = 0).

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → Yes → 3/4 late · late

Q · 3.2 km, dry · No → Yes → 3/4 late · late

Root · Distance ≤ 2.5 km?
  • Yes → 0/2 late · on time
  • No → Rain at checkout?
    • Yes → 3/3 late · late
    • No → 1/3 late · on time

Yes branch stops here. All 2 labels agree (Gini = 0).

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → Yes → 3/3 late · late

Q · 3.2 km, dry · No → No → 1/3 late · on time

Root · Distance ≤ 3.5 km?
  • Yes → 1/4 late · on time
  • No → 3/4 late · late
Examine the Yes node · A, B, C, D

Before splitting · A, B, C, D · Gini = 2 × (1/4) × (3/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 2 orders
● A● B
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

No · 2 orders
● C▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →

Rain at checkout?

Yes · 2 orders
● B▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

No · 2 orders
● A● C
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

Weighted Gini = (2/4) × 1/2 + (2/4) × 0 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.2500.125
Rain at checkout?0.2500.125
Examine the No node · E, F, G, H

Before splitting · E, F, G, H · Gini = 2 × (3/4) × (1/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 4.5 km?

Yes · 2 orders
▲ E▲ F
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

No · 2 orders
● G▲ H
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →

Rain at checkout?

Yes · 2 orders
▲ F▲ H
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

No · 2 orders
▲ E● G
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 4.5 km?0.2500.125
Rain at checkout?0.2500.125
Trace unseen orders through this tree

P · 4.2 km, rain · No → 3/4 late · late

Q · 3.2 km, dry · Yes → 1/4 late · on time

Root · Distance ≤ 3.5 km?
  • Yes → 1/4 late · on time
  • No → Distance ≤ 4.5 km?
    • Yes → 2/2 late · late
    • No → 1/2 late · late
Examine the Yes node · A, B, C, D

Before splitting · A, B, C, D · Gini = 2 × (1/4) × (3/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 2 orders
● A● B
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

No · 2 orders
● C▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →

Rain at checkout?

Yes · 2 orders
● B▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

No · 2 orders
● A● C
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

Weighted Gini = (2/4) × 1/2 + (2/4) × 0 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.2500.125
Rain at checkout?0.2500.125

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → Yes → 2/2 late · late

Q · 3.2 km, dry · Yes → 1/4 late · on time

Root · Distance ≤ 3.5 km?
  • Yes → 1/4 late · on time
  • No → Rain at checkout?
    • Yes → 2/2 late · late
    • No → 1/2 late · late
Examine the Yes node · A, B, C, D

Before splitting · A, B, C, D · Gini = 2 × (1/4) × (3/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 2 orders
● A● B
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

No · 2 orders
● C▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →

Rain at checkout?

Yes · 2 orders
● B▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

No · 2 orders
● A● C
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

Weighted Gini = (2/4) × 1/2 + (2/4) × 0 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.2500.125
Rain at checkout?0.2500.125

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → Yes → 2/2 late · late

Q · 3.2 km, dry · Yes → 1/4 late · on time

Root · Distance ≤ 3.5 km?
  • Yes → Distance ≤ 2.5 km?
    • Yes → 0/2 late · on time
    • No → 1/2 late · late
  • No → 3/4 late · late
Examine the No node · E, F, G, H

Before splitting · E, F, G, H · Gini = 2 × (3/4) × (1/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 4.5 km?

Yes · 2 orders
▲ E▲ F
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

No · 2 orders
● G▲ H
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →

Rain at checkout?

Yes · 2 orders
▲ F▲ H
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

No · 2 orders
▲ E● G
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 4.5 km?0.2500.125
Rain at checkout?0.2500.125

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → 3/4 late · late

Q · 3.2 km, dry · Yes → No → 1/2 late · late

Root · Distance ≤ 3.5 km?
  • Yes → Distance ≤ 2.5 km?
    • Yes → 0/2 late · on time
    • No → 1/2 late · late
  • No → Distance ≤ 4.5 km?
    • Yes → 2/2 late · late
    • No → 1/2 late · late

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → Yes → 2/2 late · late

Q · 3.2 km, dry · Yes → No → 1/2 late · late

Root · Distance ≤ 3.5 km?
  • Yes → Distance ≤ 2.5 km?
    • Yes → 0/2 late · on time
    • No → 1/2 late · late
  • No → Rain at checkout?
    • Yes → 2/2 late · late
    • No → 1/2 late · late

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → Yes → 2/2 late · late

Q · 3.2 km, dry · Yes → No → 1/2 late · late

Root · Distance ≤ 3.5 km?
  • Yes → Rain at checkout?
    • Yes → 1/2 late · late
    • No → 0/2 late · on time
  • No → 3/4 late · late
Examine the No node · E, F, G, H

Before splitting · E, F, G, H · Gini = 2 × (3/4) × (1/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 4.5 km?

Yes · 2 orders
▲ E▲ F
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

No · 2 orders
● G▲ H
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →

Rain at checkout?

Yes · 2 orders
▲ F▲ H
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

No · 2 orders
▲ E● G
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 4.5 km?0.2500.125
Rain at checkout?0.2500.125

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → 3/4 late · late

Q · 3.2 km, dry · Yes → No → 0/2 late · on time

Root · Distance ≤ 3.5 km?
  • Yes → Rain at checkout?
    • Yes → 1/2 late · late
    • No → 0/2 late · on time
  • No → Distance ≤ 4.5 km?
    • Yes → 2/2 late · late
    • No → 1/2 late · late

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → Yes → 2/2 late · late

Q · 3.2 km, dry · Yes → No → 0/2 late · on time

Root · Distance ≤ 3.5 km?
  • Yes → Rain at checkout?
    • Yes → 1/2 late · late
    • No → 0/2 late · on time
  • No → Rain at checkout?
    • Yes → 2/2 late · late
    • No → 1/2 late · late

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · No → Yes → 2/2 late · late

Q · 3.2 km, dry · Yes → No → 0/2 late · on time

Root · Distance ≤ 4.5 km?
  • Yes → 3/6 late · late
  • No → 1/2 late · late
Examine the Yes node · A, B, C, D, E, F

Before splitting · A, B, C, D, E, F · Gini = 2 × (3/6) × (3/6) = 1/2 (0.500)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 2 orders
● A● B
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

No · 4 orders
● C▲ D▲ E▲ F
3 late · 1 on time

Gini = 2 × (3/4) × (1/4) = 3/8

Weighted Gini = (2/6) × 0 + (4/6) × 3/8 = 1/4 ≈ 0.250

Drop = 1/2 − 1/4 = 1/4 ≈ 0.250 · largest drop here

Keep this split →

Distance ≤ 3.5 km?

Yes · 4 orders
● A● B● C▲ D
1 late · 3 on time

Gini = 2 × (1/4) × (3/4) = 3/8

No · 2 orders
▲ E▲ F
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

Weighted Gini = (4/6) × 3/8 + (2/6) × 0 = 1/4 ≈ 0.250

Drop = 1/2 − 1/4 = 1/4 ≈ 0.250 · largest drop here

Keep this split →

Rain at checkout?

Yes · 3 orders
● B▲ D▲ F
2 late · 1 on time

Gini = 2 × (2/3) × (1/3) = 4/9

No · 3 orders
● A● C▲ E
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

Weighted Gini = (3/6) × 4/9 + (3/6) × 4/9 = 4/9 ≈ 0.444

Drop = 1/2 − 4/9 = 1/18 ≈ 0.056 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.2500.250
Distance ≤ 3.5 km?0.2500.250
Rain at checkout?0.4440.056
Examine the No node · G, H

Before splitting · G, H · Gini = 2 × (1/2) × (1/2) = 1/2 (0.500)

Try a candidate question

Rain at checkout?

Yes · 1 orders
▲ H
1 late · 0 on time

Gini = 2 × (1/1) × (0/1) = 0

No · 1 orders
● G
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

Weighted Gini = (1/2) × 0 + (1/2) × 0 = 0 ≈ 0.000

Drop = 1/2 − 0 = 1/2 ≈ 0.500 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Rain at checkout?0.0000.500
Trace unseen orders through this tree

P · 4.2 km, rain · Yes → 3/6 late · late

Q · 3.2 km, dry · Yes → 3/6 late · late

Root · Distance ≤ 4.5 km?
  • Yes → 3/6 late · late
  • No → Rain at checkout?
    • Yes → 1/1 late · late
    • No → 0/1 late · on time
Examine the Yes node · A, B, C, D, E, F

Before splitting · A, B, C, D, E, F · Gini = 2 × (3/6) × (3/6) = 1/2 (0.500)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 2 orders
● A● B
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

No · 4 orders
● C▲ D▲ E▲ F
3 late · 1 on time

Gini = 2 × (3/4) × (1/4) = 3/8

Weighted Gini = (2/6) × 0 + (4/6) × 3/8 = 1/4 ≈ 0.250

Drop = 1/2 − 1/4 = 1/4 ≈ 0.250 · largest drop here

Keep this split →

Distance ≤ 3.5 km?

Yes · 4 orders
● A● B● C▲ D
1 late · 3 on time

Gini = 2 × (1/4) × (3/4) = 3/8

No · 2 orders
▲ E▲ F
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

Weighted Gini = (4/6) × 3/8 + (2/6) × 0 = 1/4 ≈ 0.250

Drop = 1/2 − 1/4 = 1/4 ≈ 0.250 · largest drop here

Keep this split →

Rain at checkout?

Yes · 3 orders
● B▲ D▲ F
2 late · 1 on time

Gini = 2 × (2/3) × (1/3) = 4/9

No · 3 orders
● A● C▲ E
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

Weighted Gini = (3/6) × 4/9 + (3/6) × 4/9 = 4/9 ≈ 0.444

Drop = 1/2 − 4/9 = 1/18 ≈ 0.056 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.2500.250
Distance ≤ 3.5 km?0.2500.250
Rain at checkout?0.4440.056

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → 3/6 late · late

Q · 3.2 km, dry · Yes → 3/6 late · late

Root · Distance ≤ 4.5 km?
  • Yes → Distance ≤ 2.5 km?
    • Yes → 0/2 late · on time
    • No → 3/4 late · late
  • No → 1/2 late · late
Examine the No node · G, H

Before splitting · G, H · Gini = 2 × (1/2) × (1/2) = 1/2 (0.500)

Try a candidate question

Rain at checkout?

Yes · 1 orders
▲ H
1 late · 0 on time

Gini = 2 × (1/1) × (0/1) = 0

No · 1 orders
● G
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

Weighted Gini = (1/2) × 0 + (1/2) × 0 = 0 ≈ 0.000

Drop = 1/2 − 0 = 1/2 ≈ 0.500 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Rain at checkout?0.0000.500

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 3/4 late · late

Q · 3.2 km, dry · Yes → No → 3/4 late · late

Root · Distance ≤ 4.5 km?
  • Yes → Distance ≤ 2.5 km?
    • Yes → 0/2 late · on time
    • No → 3/4 late · late
  • No → Rain at checkout?
    • Yes → 1/1 late · late
    • No → 0/1 late · on time

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 3/4 late · late

Q · 3.2 km, dry · Yes → No → 3/4 late · late

Root · Distance ≤ 4.5 km?
  • Yes → Distance ≤ 3.5 km?
    • Yes → 1/4 late · on time
    • No → 2/2 late · late
  • No → 1/2 late · late
Examine the No node · G, H

Before splitting · G, H · Gini = 2 × (1/2) × (1/2) = 1/2 (0.500)

Try a candidate question

Rain at checkout?

Yes · 1 orders
▲ H
1 late · 0 on time

Gini = 2 × (1/1) × (0/1) = 0

No · 1 orders
● G
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

Weighted Gini = (1/2) × 0 + (1/2) × 0 = 0 ≈ 0.000

Drop = 1/2 − 0 = 1/2 ≈ 0.500 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Rain at checkout?0.0000.500

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 2/2 late · late

Q · 3.2 km, dry · Yes → Yes → 1/4 late · on time

Root · Distance ≤ 4.5 km?
  • Yes → Distance ≤ 3.5 km?
    • Yes → 1/4 late · on time
    • No → 2/2 late · late
  • No → Rain at checkout?
    • Yes → 1/1 late · late
    • No → 0/1 late · on time

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 2/2 late · late

Q · 3.2 km, dry · Yes → Yes → 1/4 late · on time

Root · Distance ≤ 4.5 km?
  • Yes → Rain at checkout?
    • Yes → 2/3 late · late
    • No → 1/3 late · on time
  • No → 1/2 late · late
Examine the No node · G, H

Before splitting · G, H · Gini = 2 × (1/2) × (1/2) = 1/2 (0.500)

Try a candidate question

Rain at checkout?

Yes · 1 orders
▲ H
1 late · 0 on time

Gini = 2 × (1/1) × (0/1) = 0

No · 1 orders
● G
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

Weighted Gini = (1/2) × 0 + (1/2) × 0 = 0 ≈ 0.000

Drop = 1/2 − 0 = 1/2 ≈ 0.500 · largest drop here

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Rain at checkout?0.0000.500

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → Yes → 2/3 late · late

Q · 3.2 km, dry · Yes → No → 1/3 late · on time

Root · Distance ≤ 4.5 km?
  • Yes → Rain at checkout?
    • Yes → 2/3 late · late
    • No → 1/3 late · on time
  • No → Rain at checkout?
    • Yes → 1/1 late · late
    • No → 0/1 late · on time

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → Yes → 2/3 late · late

Q · 3.2 km, dry · Yes → No → 1/3 late · on time

Root · Rain at checkout?
  • Yes → 3/4 late · late
  • No → 1/4 late · on time
Examine the Yes node · B, D, F, H

Before splitting · B, D, F, H · Gini = 2 × (3/4) × (1/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 1 orders
● B
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

No · 3 orders
▲ D▲ F▲ H
3 late · 0 on time

Gini = 2 × (3/3) × (0/3) = 0

Weighted Gini = (1/4) × 0 + (3/4) × 0 = 0 ≈ 0.000

Drop = 3/8 − 0 = 3/8 ≈ 0.375 · largest drop here

Keep this split →

Distance ≤ 3.5 km?

Yes · 2 orders
● B▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

No · 2 orders
▲ F▲ H
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

Weighted Gini = (2/4) × 1/2 + (2/4) × 0 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · another question gives a larger drop

Keep this split →

Distance ≤ 4.5 km?

Yes · 3 orders
● B▲ D▲ F
2 late · 1 on time

Gini = 2 × (2/3) × (1/3) = 4/9

No · 1 orders
▲ H
1 late · 0 on time

Gini = 2 × (1/1) × (0/1) = 0

Weighted Gini = (3/4) × 4/9 + (1/4) × 0 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.0000.375
Distance ≤ 3.5 km?0.2500.125
Distance ≤ 4.5 km?0.3330.042
Examine the No node · A, C, E, G

Before splitting · A, C, E, G · Gini = 2 × (1/4) × (3/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 1 orders
● A
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

No · 3 orders
● C▲ E● G
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

Weighted Gini = (1/4) × 0 + (3/4) × 4/9 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →

Distance ≤ 3.5 km?

Yes · 2 orders
● A● C
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

No · 2 orders
▲ E● G
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →

Distance ≤ 4.5 km?

Yes · 3 orders
● A● C▲ E
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

No · 1 orders
● G
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

Weighted Gini = (3/4) × 4/9 + (1/4) × 0 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.3330.042
Distance ≤ 3.5 km?0.2500.125
Distance ≤ 4.5 km?0.3330.042
Trace unseen orders through this tree

P · 4.2 km, rain · Yes → 3/4 late · late

Q · 3.2 km, dry · No → 1/4 late · on time

Root · Rain at checkout?
  • Yes → 3/4 late · late
  • No → Distance ≤ 2.5 km?
    • Yes → 0/1 late · on time
    • No → 1/3 late · on time
Examine the Yes node · B, D, F, H

Before splitting · B, D, F, H · Gini = 2 × (3/4) × (1/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 1 orders
● B
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

No · 3 orders
▲ D▲ F▲ H
3 late · 0 on time

Gini = 2 × (3/3) × (0/3) = 0

Weighted Gini = (1/4) × 0 + (3/4) × 0 = 0 ≈ 0.000

Drop = 3/8 − 0 = 3/8 ≈ 0.375 · largest drop here

Keep this split →

Distance ≤ 3.5 km?

Yes · 2 orders
● B▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

No · 2 orders
▲ F▲ H
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

Weighted Gini = (2/4) × 1/2 + (2/4) × 0 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · another question gives a larger drop

Keep this split →

Distance ≤ 4.5 km?

Yes · 3 orders
● B▲ D▲ F
2 late · 1 on time

Gini = 2 × (2/3) × (1/3) = 4/9

No · 1 orders
▲ H
1 late · 0 on time

Gini = 2 × (1/1) × (0/1) = 0

Weighted Gini = (3/4) × 4/9 + (1/4) × 0 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.0000.375
Distance ≤ 3.5 km?0.2500.125
Distance ≤ 4.5 km?0.3330.042

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → 3/4 late · late

Q · 3.2 km, dry · No → No → 1/3 late · on time

Root · Rain at checkout?
  • Yes → 3/4 late · late
  • No → Distance ≤ 3.5 km?
    • Yes → 0/2 late · on time
    • No → 1/2 late · late
Examine the Yes node · B, D, F, H

Before splitting · B, D, F, H · Gini = 2 × (3/4) × (1/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 1 orders
● B
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

No · 3 orders
▲ D▲ F▲ H
3 late · 0 on time

Gini = 2 × (3/3) × (0/3) = 0

Weighted Gini = (1/4) × 0 + (3/4) × 0 = 0 ≈ 0.000

Drop = 3/8 − 0 = 3/8 ≈ 0.375 · largest drop here

Keep this split →

Distance ≤ 3.5 km?

Yes · 2 orders
● B▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

No · 2 orders
▲ F▲ H
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

Weighted Gini = (2/4) × 1/2 + (2/4) × 0 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · another question gives a larger drop

Keep this split →

Distance ≤ 4.5 km?

Yes · 3 orders
● B▲ D▲ F
2 late · 1 on time

Gini = 2 × (2/3) × (1/3) = 4/9

No · 1 orders
▲ H
1 late · 0 on time

Gini = 2 × (1/1) × (0/1) = 0

Weighted Gini = (3/4) × 4/9 + (1/4) × 0 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.0000.375
Distance ≤ 3.5 km?0.2500.125
Distance ≤ 4.5 km?0.3330.042

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → 3/4 late · late

Q · 3.2 km, dry · No → Yes → 0/2 late · on time

Root · Rain at checkout?
  • Yes → 3/4 late · late
  • No → Distance ≤ 4.5 km?
    • Yes → 1/3 late · on time
    • No → 0/1 late · on time
Examine the Yes node · B, D, F, H

Before splitting · B, D, F, H · Gini = 2 × (3/4) × (1/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 1 orders
● B
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

No · 3 orders
▲ D▲ F▲ H
3 late · 0 on time

Gini = 2 × (3/3) × (0/3) = 0

Weighted Gini = (1/4) × 0 + (3/4) × 0 = 0 ≈ 0.000

Drop = 3/8 − 0 = 3/8 ≈ 0.375 · largest drop here

Keep this split →

Distance ≤ 3.5 km?

Yes · 2 orders
● B▲ D
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

No · 2 orders
▲ F▲ H
2 late · 0 on time

Gini = 2 × (2/2) × (0/2) = 0

Weighted Gini = (2/4) × 1/2 + (2/4) × 0 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · another question gives a larger drop

Keep this split →

Distance ≤ 4.5 km?

Yes · 3 orders
● B▲ D▲ F
2 late · 1 on time

Gini = 2 × (2/3) × (1/3) = 4/9

No · 1 orders
▲ H
1 late · 0 on time

Gini = 2 × (1/1) × (0/1) = 0

Weighted Gini = (3/4) × 4/9 + (1/4) × 0 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.0000.375
Distance ≤ 3.5 km?0.2500.125
Distance ≤ 4.5 km?0.3330.042

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → 3/4 late · late

Q · 3.2 km, dry · No → Yes → 1/3 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 2.5 km?
    • Yes → 0/1 late · on time
    • No → 3/3 late · late
  • No → 1/4 late · on time
Examine the No node · A, C, E, G

Before splitting · A, C, E, G · Gini = 2 × (1/4) × (3/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 1 orders
● A
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

No · 3 orders
● C▲ E● G
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

Weighted Gini = (1/4) × 0 + (3/4) × 4/9 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →

Distance ≤ 3.5 km?

Yes · 2 orders
● A● C
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

No · 2 orders
▲ E● G
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →

Distance ≤ 4.5 km?

Yes · 3 orders
● A● C▲ E
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

No · 1 orders
● G
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

Weighted Gini = (3/4) × 4/9 + (1/4) × 0 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.3330.042
Distance ≤ 3.5 km?0.2500.125
Distance ≤ 4.5 km?0.3330.042

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 3/3 late · late

Q · 3.2 km, dry · No → 1/4 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 2.5 km?
    • Yes → 0/1 late · on time
    • No → 3/3 late · late
  • No → Distance ≤ 2.5 km?
    • Yes → 0/1 late · on time
    • No → 1/3 late · on time

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 3/3 late · late

Q · 3.2 km, dry · No → No → 1/3 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 2.5 km?
    • Yes → 0/1 late · on time
    • No → 3/3 late · late
  • No → Distance ≤ 3.5 km?
    • Yes → 0/2 late · on time
    • No → 1/2 late · late

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 3/3 late · late

Q · 3.2 km, dry · No → Yes → 0/2 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 2.5 km?
    • Yes → 0/1 late · on time
    • No → 3/3 late · late
  • No → Distance ≤ 4.5 km?
    • Yes → 1/3 late · on time
    • No → 0/1 late · on time

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 3/3 late · late

Q · 3.2 km, dry · No → Yes → 1/3 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 3.5 km?
    • Yes → 1/2 late · late
    • No → 2/2 late · late
  • No → 1/4 late · on time
Examine the No node · A, C, E, G

Before splitting · A, C, E, G · Gini = 2 × (1/4) × (3/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 1 orders
● A
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

No · 3 orders
● C▲ E● G
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

Weighted Gini = (1/4) × 0 + (3/4) × 4/9 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →

Distance ≤ 3.5 km?

Yes · 2 orders
● A● C
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

No · 2 orders
▲ E● G
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →

Distance ≤ 4.5 km?

Yes · 3 orders
● A● C▲ E
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

No · 1 orders
● G
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

Weighted Gini = (3/4) × 4/9 + (1/4) × 0 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.3330.042
Distance ≤ 3.5 km?0.2500.125
Distance ≤ 4.5 km?0.3330.042

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 2/2 late · late

Q · 3.2 km, dry · No → 1/4 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 3.5 km?
    • Yes → 1/2 late · late
    • No → 2/2 late · late
  • No → Distance ≤ 2.5 km?
    • Yes → 0/1 late · on time
    • No → 1/3 late · on time

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 2/2 late · late

Q · 3.2 km, dry · No → No → 1/3 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 3.5 km?
    • Yes → 1/2 late · late
    • No → 2/2 late · late
  • No → Distance ≤ 3.5 km?
    • Yes → 0/2 late · on time
    • No → 1/2 late · late

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 2/2 late · late

Q · 3.2 km, dry · No → Yes → 0/2 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 3.5 km?
    • Yes → 1/2 late · late
    • No → 2/2 late · late
  • No → Distance ≤ 4.5 km?
    • Yes → 1/3 late · on time
    • No → 0/1 late · on time

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → No → 2/2 late · late

Q · 3.2 km, dry · No → Yes → 1/3 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 4.5 km?
    • Yes → 2/3 late · late
    • No → 1/1 late · late
  • No → 1/4 late · on time
Examine the No node · A, C, E, G

Before splitting · A, C, E, G · Gini = 2 × (1/4) × (3/4) = 3/8 (0.375)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 1 orders
● A
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

No · 3 orders
● C▲ E● G
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

Weighted Gini = (1/4) × 0 + (3/4) × 4/9 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →

Distance ≤ 3.5 km?

Yes · 2 orders
● A● C
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

No · 2 orders
▲ E● G
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (2/4) × 0 + (2/4) × 1/2 = 1/4 ≈ 0.250

Drop = 3/8 − 1/4 = 1/8 ≈ 0.125 · largest drop here

Keep this split →

Distance ≤ 4.5 km?

Yes · 3 orders
● A● C▲ E
1 late · 2 on time

Gini = 2 × (1/3) × (2/3) = 4/9

No · 1 orders
● G
0 late · 1 on time

Gini = 2 × (0/1) × (1/1) = 0

Weighted Gini = (3/4) × 4/9 + (1/4) × 0 = 1/3 ≈ 0.333

Drop = 3/8 − 1/3 = 1/24 ≈ 0.042 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.3330.042
Distance ≤ 3.5 km?0.2500.125
Distance ≤ 4.5 km?0.3330.042

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → Yes → 2/3 late · late

Q · 3.2 km, dry · No → 1/4 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 4.5 km?
    • Yes → 2/3 late · late
    • No → 1/1 late · late
  • No → Distance ≤ 2.5 km?
    • Yes → 0/1 late · on time
    • No → 1/3 late · on time

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → Yes → 2/3 late · late

Q · 3.2 km, dry · No → No → 1/3 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 4.5 km?
    • Yes → 2/3 late · late
    • No → 1/1 late · late
  • No → Distance ≤ 3.5 km?
    • Yes → 0/2 late · on time
    • No → 1/2 late · late

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → Yes → 2/3 late · late

Q · 3.2 km, dry · No → Yes → 0/2 late · on time

Root · Rain at checkout?
  • Yes → Distance ≤ 4.5 km?
    • Yes → 2/3 late · late
    • No → 1/1 late · late
  • No → Distance ≤ 4.5 km?
    • Yes → 1/3 late · on time
    • No → 0/1 late · on time

This lesson allows two questions per path. At that depth the majority label is the prediction. An exact tie uses the 50% warning rule.

Trace unseen orders through this tree

P · 4.2 km, rain · Yes → Yes → 2/3 late · late

Q · 3.2 km, dry · No → Yes → 1/3 late · on time

Root · all eight orders · choose its first question below

Before splitting · A, B, C, D, E, F, G, H · Gini = 2 × (4/8) × (4/8) = 1/2 (0.500)

Try a candidate question

Distance ≤ 2.5 km?

Yes · 2 orders
● A● B
0 late · 2 on time

Gini = 2 × (0/2) × (2/2) = 0

No · 6 orders
● C▲ D▲ E▲ F● G▲ H
4 late · 2 on time

Gini = 2 × (4/6) × (2/6) = 4/9

Weighted Gini = (2/8) × 0 + (6/8) × 4/9 = 1/3 ≈ 0.333

Drop = 1/2 − 1/3 = 1/6 ≈ 0.167 · largest drop here

Keep this split →

Distance ≤ 3.5 km?

Yes · 4 orders
● A● B● C▲ D
1 late · 3 on time

Gini = 2 × (1/4) × (3/4) = 3/8

No · 4 orders
▲ E▲ F● G▲ H
3 late · 1 on time

Gini = 2 × (3/4) × (1/4) = 3/8

Weighted Gini = (4/8) × 3/8 + (4/8) × 3/8 = 3/8 ≈ 0.375

Drop = 1/2 − 3/8 = 1/8 ≈ 0.125 · another question gives a larger drop

Keep this split →

Distance ≤ 4.5 km?

Yes · 6 orders
● A● B● C▲ D▲ E▲ F
3 late · 3 on time

Gini = 2 × (3/6) × (3/6) = 1/2

No · 2 orders
● G▲ H
1 late · 1 on time

Gini = 2 × (1/2) × (1/2) = 1/2

Weighted Gini = (6/8) × 1/2 + (2/8) × 1/2 = 1/2 ≈ 0.500

Drop = 1/2 − 1/2 = 0 ≈ 0.000 · another question gives a larger drop

Keep this split →

Rain at checkout?

Yes · 4 orders
● B▲ D▲ F▲ H
3 late · 1 on time

Gini = 2 × (3/4) × (1/4) = 3/8

No · 4 orders
● A● C▲ E● G
1 late · 3 on time

Gini = 2 × (1/4) × (3/4) = 3/8

Weighted Gini = (4/8) × 3/8 + (4/8) × 3/8 = 3/8 ≈ 0.375

Drop = 1/2 − 3/8 = 1/8 ≈ 0.125 · another question gives a larger drop

Keep this split →
Compare all questions at this node
QuestionWeighted GiniDrop
Distance ≤ 2.5 km?0.3330.167
Distance ≤ 3.5 km?0.3750.125
Distance ≤ 4.5 km?0.5000.000
Rain at checkout?0.3750.125
Full lesson · Gini card draws, worked examples and delivery predictor

Read a finished tree

At checkout we know two features – distance and weather. After delivery we learn the label – late or on time. Each training order pairs its features with its known label.

  • Root · Is the distance ≤ 2.5 km?
    • Yes → Predict on time · A, B · 0 of 2 late
    • No → Is it raining?
      • Yes → Predict late · D, F, H · 3 of 3 late
      • No → Predict on time · C, E, G · 1 of 3 late

The root is the first question. A branch is a possible answer. A leaf is where we stop and predict using the training orders that reached it.

Ask the class

F was a 4 km delivery in rain. Which two answers lead to its prediction?

Reveal the path

No at the distance question, then Yes at the rain question. All three orders in this leaf were late, so it predicts late.

See the eight labeled training orders
OrderDistanceWeatherOutcome
A2 kmDryOn time
B2 kmRainOn time
C3 kmDryOn time
D3 kmRainLate
E4 kmDryLate
F4 kmRainLate
G5 kmDryOn time
H5 kmRainLate

What does Gini count?

Start with four training orders. A, B and C were on time. D was late. Pick a card, put it back, then pick again. A pair counts as different when one is late and the other is on time.

Pick A (on time), put it back, then pick D (late). Their outcomes differ. A followed by B gives the same outcome. You may draw the same card twice.

Pick the first card

Count all 16 equally likely pairs
First ↓ / Second →ABCD
ASameSameSameDifferent
BSameSameSameDifferent
CSameSameSameDifferent
DDifferentDifferentDifferentSame

Each row is a first pick. Each column is a second pick. Six cells contain different labels.

Gini = 6/16 = 0.375

With two labels, let p be the late fraction. The two ways to differ are late then on time, or on time then late. Their probabilities add to G = 2p(1 − p). Gini runs from 0 (all labels alike) to 0.5 (equal counts).

Before the first split

Return to all eight training orders. Four were late and four were on time, so G = 2 × (4/8) × (4/8) = 0.500. This is the starting point for every candidate root question.

A question divides the orders at this node into Yes and No groups. Open any candidate to see its counts and calculations. Weight each child’s Gini by its share of the orders. The question with the largest drop wins.

Compare the root questions

Before the split · A, B, C, D, E, F, G, H · 4 late, 4 on time. Gini = 2 × (4/8) × (4/8) = 1/2.

Distance ≤ 2.5 km? · drop 0.167

Yes · A, B · 0 late, 2 on time. Gini = 2 × (0/2) × (2/2) = 0.

No · C, D, E, F, G, H · 4 late, 2 on time. Gini = 2 × (4/6) × (2/6) = 4/9.

Weighted Gini = (2/8) × 0 + (6/8) × 4/9 = 1/3 ≈ 0.333.

Drop = 1/2 − 1/3 = 1/6 ≈ 0.167.

Distance ≤ 3.5 km? · drop 0.125

Yes · A, B, C, D · 1 late, 3 on time. Gini = 2 × (1/4) × (3/4) = 3/8.

No · E, F, G, H · 3 late, 1 on time. Gini = 2 × (3/4) × (1/4) = 3/8.

Weighted Gini = (4/8) × 3/8 + (4/8) × 3/8 = 3/8 ≈ 0.375.

Drop = 1/2 − 3/8 = 1/8 ≈ 0.125.

Distance ≤ 4.5 km? · drop 0.000

Yes · A, B, C, D, E, F · 3 late, 3 on time. Gini = 2 × (3/6) × (3/6) = 1/2.

No · G, H · 1 late, 1 on time. Gini = 2 × (1/2) × (1/2) = 1/2.

Weighted Gini = (6/8) × 1/2 + (2/8) × 1/2 = 1/2 ≈ 0.500.

Drop = 1/2 − 1/2 = 0 ≈ 0.000.

Rain at checkout? · drop 0.125

Yes · B, D, F, H · 3 late, 1 on time. Gini = 2 × (3/4) × (1/4) = 3/8.

No · A, C, E, G · 1 late, 3 on time. Gini = 2 × (1/4) × (3/4) = 3/8.

Weighted Gini = (4/8) × 3/8 + (4/8) × 3/8 = 3/8 ≈ 0.375.

Drop = 1/2 − 3/8 = 1/8 ≈ 0.125.

Choose distance ≤ 2.5 km. Both short trips were on time. Six longer trips go to the next node.

Compare questions for the six longer trips

Before the split · C, D, E, F, G, H · 4 late, 2 on time. Gini = 2 × (4/6) × (2/6) = 4/9.

Distance ≤ 3.5 km? · drop 0.028

Yes · C, D · 1 late, 1 on time. Gini = 2 × (1/2) × (1/2) = 1/2.

No · E, F, G, H · 3 late, 1 on time. Gini = 2 × (3/4) × (1/4) = 3/8.

Weighted Gini = (2/6) × 1/2 + (4/6) × 3/8 = 5/12 ≈ 0.417.

Drop = 4/9 − 5/12 = 1/36 ≈ 0.028.

Distance ≤ 4.5 km? · drop 0.028

Yes · C, D, E, F · 3 late, 1 on time. Gini = 2 × (3/4) × (1/4) = 3/8.

No · G, H · 1 late, 1 on time. Gini = 2 × (1/2) × (1/2) = 1/2.

Weighted Gini = (4/6) × 3/8 + (2/6) × 1/2 = 5/12 ≈ 0.417.

Drop = 4/9 − 5/12 = 1/36 ≈ 0.028.

Rain at checkout? · drop 0.222

Yes · D, F, H · 3 late, 0 on time. Gini = 2 × (3/3) × (0/3) = 0.

No · C, E, G · 1 late, 2 on time. Gini = 2 × (1/3) × (2/3) = 4/9.

Weighted Gini = (3/6) × 0 + (3/6) × 4/9 = 2/9 ≈ 0.222.

Drop = 4/9 − 2/9 = 2/9 ≈ 0.222.

Choose rain. All three rainy trips were late. Two of three dry trips were on time.

Build the delivery tree

Training orders · distance, weather and outcome
OrderDistanceWeatherOutcome

Predict an unseen delivery

Choose a delivery or enter its features. Compare a tree that stops after distance with one that can also ask about rain. The app warns when the estimated chance of delay is at least 50%.

P · 4.2 km in rain

One question gives 4/6 late. Two questions give 3/3 late. Both trees warn.

Q · 3.2 km and dry

One question gives 4/6 late and warns. Two questions give 1/3 late and stay silent.

Check your understanding

At exactly 2.5 km in rain, which leaf do we reach?

The ≤ sign includes exactly 2.5. We take Yes and stop with A and B. Both arrived on time, so the estimate is 0/2 late.

Why did distance win at the root and rain win next?

The root compares questions using all eight orders. The next node compares questions using only the six longer trips. Rain has the largest Gini drop within those six.

Does 3 out of 3 late guarantee the next rainy delivery will be late?

No. The fraction describes the three training orders in this leaf. Check predictions on unseen deliveries to learn how well the rule generalizes.

Teacher prompt · Why stop at the mixed dry leaf?

This lesson limits each path to two questions. Two of the three dry, longer orders were on time, so the leaf predicts on time. A deeper tree could split again. In practice, choose depth using validation data.