liveBook · Manning

Threshold

As explained in Statistics Every Programmer Needs

A decision threshold is a feature-value boundary used by a decision tree to divide observations into branches.

A decision-tree threshold is a feature-value boundary at a node. An observation satisfying the condition, such as TO_GO ≤ 3.5, follows the left branch; one that does not follows the right. Following these conditions from the root toward a leaf reveals how the tree reaches a classification. section 6.3.6

The algorithm selects a feature and threshold for each node using the data that reaches it. It chooses the split that minimizes impurity for that subset, or maximizes information gain when entropy is the selected criterion. Because this choice is local, the same numeric feature can appear again with a different threshold farther down the tree. section 6.3.6

A fourth-down split

A split at TO_GO ≤ 3.5 separates plays with 268 successful conversions and 127 failures from plays with 67 successes and 156 failures. The contrasting class counts help explain why this boundary is useful. A threshold of 3.5 is valid even though TO_GO contains integers: the tree does not restrict its splits to integer values. section 6.3.6 section 6.3.5

>>> to_go_less_than_3_5 = \
>>>     train_data[train_data['TO_GO'] <= 3.5]    #1
>>> to_go_greater_than_3_5 = \
>>>     train_data[train_data['TO_GO'] > 3.5]     #2
>>> counts_less_than_3_5 = (to_go_less_than_3_5 \
>>>            .groupby('CONVERT').size())  #3
>>> print('Counts for TO_GO <= 3.5:')    #4
>>> print(counts_less_than_3_5)     #5
>>> counts_greater_than_3_5 = (to_go_greater_than_3_5 \
>>>            .groupby('CONVERT').size())     #6
>>> print('Counts for TO_GO > 3.5:')    #7
>>> print(counts_greater_than_3_5)  #8
Counts for TO_GO <= 3.5:
CONVERT
0    127
1    268
dtype: int64
Counts for TO_GO > 3.5:
CONVERT
0    156
1     67
dtype: int64

The pandas filters reproduce both sides of the TO_GO threshold and count the observed outcomes in each branch. section 6.3.6

Do not confuse this feature-value boundary with a logistic-regression probability cutoff, which turns a predicted probability into a class label, or a significance threshold, which supplies a criterion for a statistical test. Each threshold answers a different decision question. section 5.2.3 section 4.2.1

How Statistics Every Programmer Needs covers it

How deep it goes
Explains local threshold selection through impurity and walks through a split, without deriving the underlying mathematics.
Examples
Uses a TO_GO ≤ 3.5 split and conversion counts on either side of the boundary.
What it assumes
Assumes familiarity with features and class labels while explaining how threshold conditions route observations.
What you can do after
Evaluate/understand a plotted decision tree by following threshold conditions and checking the class counts they separate.
How it connects
Connects decision-tree thresholds to recursive splitting, Gini impurity, entropy, information gain, and pruning.

Also explained in

Compare how 13 books explain threshold →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.