liveBook · Manning

Threshold

As explained in Grokking Machine Learning

A boundary value of a numerical feature that determines how data points are divided by a decision-tree split.

Suppose you want to predict whether a person will use an app often based on their age. You could start with a question: “Are they younger than 35?” The number 35 is a threshold, also called a cutoff. It divides the data into two groups, one on each side of the boundary. section 9.6

A decision tree asks a question like this at each decision node. For a numerical feature, it compares possible thresholds and chooses a split that works best for the predictions. It can then ask new questions within each resulting group. section 9.4 section 9.6

Choosing a boundary

In a two-feature classification example, a vertical boundary at x₀ = 5 separates squares from triangles and correctly classifies 8 of 10 points. Further boundaries split the groups on either side. You can compare candidate lines using accuracy, Gini impurity, or entropy. section 9.4

Choosing an age cutoff

For app engagement, try age cutoffs such as 25, 35, and 65. At each cutoff, predict each group’s average engagement and calculate mean squared error. A cutoff of 35 gives the smallest error among those compared, so it becomes the tree’s first question. The same process can continue within each group. section 9.6

Table 9.7 The nine possible ways to split the dataset by age using a cutoff. Each cutoff splits the dataset into two smaller datasets, and for each of these two, the prediction is given by the average of the labels. The mean square error (MSE) is calculated as the average of the squares of the differences between the labels and the prediction. Notice that the splitting with the smallest MSE is obtained with a cutoff of 35. This gives us the root node in our decision tree. (view table figure)

Cutoff

Labels left set

Labels right set

Prediction left set

Prediction right set

MSE

0

{}

{7,5,7,1,2,1,5,4}

None

4.0

5.25

15

{7}

{5,7,1,2,1,5,4}

7.0

3.571

3.964

25

{7,5}

{7,1,2,1,5,4}

6.0

3.333

3.917

35

{7,5,7}

{1,2,1,5,4}

6.333

2.6

1.983

45

{7,5,7,1}

{2,1,5,4}

5.0

3.0

4.25

55

{7,5,7,1,2}

{1,5,4}

4.4

3.333

4.983

65

{7,5,7,1,2,1}

{5,4}

3.833

4.5

5.167

75

{7,5,7,1,2,1,5}

{4}

4.0

4.0

5.25

100

{7,5,7,1,2,1,5,4}

{}

4.0

none

5.25

Compare the groups, predictions, and errors for the candidate age cutoffs to see why 35 is selected. section 9.6

A threshold can also act on a classifier’s score rather than on one feature. For example, a sentence scored by adding word counts is classified as happy when its score is at least 3.5; writing the rule with a bias instead uses −3.5. When selecting a model’s prediction threshold, raising it decreases sensitivity and increases specificity. That is a different choice from selecting a decision-tree split. section 5.1 section 7.4

Try plotting two numerical features, drawing a candidate vertical or horizontal boundary, and counting its classification mistakes. Could another threshold do better? section 9.4

How Grokking Machine Learning covers it

How deep it goes
Works through graphical split selection and a regression cutoff comparison using group averages and mean squared error.
Examples
Uses square-and-triangle plots and an age-versus-app-engagement dataset to compare candidate boundaries.
What it assumes
Introduces split selection through plotted numerical features and simple averages before applying named error metrics.
What you can do after
Practice/perform threshold comparisons by checking classification mistakes or calculating group averages and mean squared error.
How it connects
Connects decision trees to accuracy, Gini impurity, entropy, mean squared error, and recursive splitting.

Also explained in

Compare how 13 books explain threshold →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning. The section links point to the parts of the book it draws on.