liveBook · Manning

Equal-width binning

As explained in Outlier Detection in Python

Equal-width binning divides a numeric range into intervals having the same width.

Equal-width binning divides a numeric range into intervals with identical widths. For univariate outlier detection, each bin’s count estimates how rare its values are. section 9.6

Extreme values can distort the range: most observations may collapse into an edge bin, intermediate bins may become empty, and moderate outliers may become hidden. section 9.6

Use equal-width binning with these practical cautions:

  • Prefer it when rarity within individual numeric features matters; equal-count bins are generally used when searching for rare multivariate combinations. section 9.6
  • Treat the number of bins as a consequential parameter rather than assuming a fixed choice. section 9.8
  • Inspect the resulting histogram because an extreme value can place ordinary observations together and leave useful distinctions unresolved. section 9.6

Uniform data with extreme values

For values distributed between 0.0 and 1.0, adding an outlier at 3.0 can create a sparse bin. Adding another at 100.0 pushes most observations into the leftmost bins; with 20 bins, 3.0 may share an inlier bin, while 50 bins can separate both outliers. section 9.6

Figure 9.1 The effect of the number of bins. In the first row we see where 20 bins are used and in the second row, 50 bins. In each row we see a distribution of uniform data with no outliers (left pane), with a single outlier with value 3.0 (middle pane), and with a second outlier with value 100.0 (right pane). In the top-right pane we see, using 20 bins, the 3.0 value is placed in a bin with inliers. In the bottom-right pane we see, using 50 bins, the 3.0 value is in a separate bin with low count so will be recognized as an outlier.

Compare 20 and 50 bins across clean data and increasingly extreme outliers to see how bin count changes detectability. section 9.6

How Outlier Detection in Python covers it

How deep it goes
Explains bin-choice trade-offs and failure modes, but stops short of deriving a general bin-width formula.
Examples
Uses uniform data with values 0.0 to 1.0 and added outliers at 3.0 and 100.0 across 20- and 50-bin histograms.
What it assumes
Assumes numeric features and familiarity with histograms, while distinguishing univariate from multivariate outlier searches.
What you can do after
Apply bin-count comparisons and PyOD’s bin-estimation utility when configuring histogram-based outlier detection.
How it connects
Connects equal-count binning, histograms, numeric features, and univariate or multivariate outlier detection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.