liveBook · Manning

Margin distribution

As explained in Timeless Algorithms, The Foundational Ideas

A margin distribution is the distribution of classification-margin values across labeled observations.

Classification accuracy counts correct predictions; a margin measures how decisively a forest favors an observation’s known class over its strongest incorrect competitor. For B trees and a labeled observation (x, y), it is the fraction voting for y minus the largest fraction voting for any other class. section 9.4.1

margin(x,y)=1B∑b=1BI(Tb(x)=y)-maxk≠y⁡[1B∑b=1BI(Tb(x)=k)]

The first term counts votes for the known class; the second subtracts the strongest competing class’s vote share. section 9.4.1

A positive margin means the known class leads; zero means a tie; a negative margin means a misclassification. Magnitude indicates how far the vote is from reversing the result. Across labeled observations, the distribution of margins links individual vote patterns to forest-wide error. section 9.4.1

PE*=PX, Y(margin(X, Y)<0)

The forest’s classification error is the probability that a labeled observation has a negative margin. section 9.4.1

Two correct predictions, different confidence

With 100 trees, votes of 82 for A, 12 for B, and 6 for C give a margin of 0.70. Votes of 51 for A and 49 for B give 0.02: both predictions are correct, but the latter is much closer to reversal. section 9.4.1

How Timeless Algorithms, The Foundational Ideas covers it

How deep it goes
Defines the vote-share formula, interprets its sign and magnitude, and relates negative margins to error.
Examples
Contrasts margins of 0.70 and 0.02 from two 100-tree vote distributions.
What it assumes
Requires known observation labels; permits margins from training, validation, or test votes but not unlabeled new observations.
What you can do after
Evaluate how close a labeled observation’s forest prediction is to reversal and relate negative margins to error.
How it connects
Connects random forests, classification accuracy, out-of-bag votes, and classification error.

This explainer was generated by Manning's knowledge graph from the text of Timeless Algorithms, The Foundational Ideas. The section links point to the parts of the book it draws on.