Skip to main content
QUICK REVIEW

[Paper Review] Optimal Data-Based Binning for Histograms

Kevin H. Knuth|arXiv (Cornell University)|May 23, 2006
Neural Networks and ApplicationsComputer Science22 references135 citations
TL;DR

This paper proposes a Bayesian method for determining the optimal number of bins in a histogram by maximizing the posterior probability of the bin count given the data. Using a multinomial likelihood and non-informative prior, it derives a data-driven rule that adapts to sample size and distribution shape, outperforming classical rules like Scott’s and Freedman-Diaconis in multimodal settings.

ABSTRACT

Histograms are convenient non-parametric density estimators, which continue to be used ubiquitously. Summary quantities estimated from histogram-based probability density models depend on the choice of the number of bins. We introduce a straightforward data-based method of determining the optimal number of bins in a uniform bin-width histogram. By assigning a multinomial likelihood and a non-informative prior, we derive the posterior probability for the number of bins in a piecewise-constant density model given the data. In addition, we estimate the mean and standard deviations of the resulting bin heights, examine the effects of small sample sizes and digitized data, and demonstrate the application to multi-dimensional histograms.

Motivation & Objective

  • To address the lack of a principled, data-driven method for selecting the number of bins in a histogram that avoids arbitrary rules of thumb.
  • To develop a Bayesian framework that objectively determines the optimal number of bins by computing the posterior probability of the bin count.
  • To improve upon classical bin width rules (e.g., Scott, Freedman-Diaconis) that assume specific distributional forms and fail for multimodal densities.
  • To provide a robust, non-parametric method for histogram-based density estimation that minimizes reliance on assumptions about the underlying distribution.
  • To extend the method to multi-dimensional histograms and offer practical implementations in MATLAB and Python.

Proposed method

  • Model the histogram as a piecewise-constant probability density function with M equal-width bins, where bin heights represent probability densities.
  • Assign a multinomial likelihood to the observed bin counts, assuming data are i.i.d. samples from the true density.
  • Use a non-informative Jeffreys prior over the bin probabilities to ensure objective inference.
  • Derive the posterior probability of the number of bins M by marginalizing over all possible bin probability configurations.
  • Compute the posterior using the logarithm of the marginal likelihood, involving the multivariate gamma function and bin counts.
  • Select the optimal M as the value that maximizes the posterior probability, implemented via brute-force search over possible M values.

Experimental results

Research questions

  • RQ1What is the optimal number of bins for a histogram that best represents the underlying data distribution without overfitting or underfitting?
  • RQ2How can the number of bins be selected in a way that is independent of prior assumptions about the shape of the underlying density?
  • RQ3How does the Bayesian posterior probability for the number of bins behave under small sample sizes or digitized data?
  • RQ4In what scenarios do classical binning rules (e.g., Scott, Freedman-Diaconis) fail, and how does the proposed method overcome these limitations?
  • RQ5Can the method be generalized to multi-dimensional histograms and applied effectively in real-world data analysis?

Key findings

  • The method selects the optimal number of bins by maximizing the posterior probability, which is derived from a Bayesian model with a non-informative prior.
  • For Gaussian-distributed data, approximately 150 data points are required to reliably estimate the density model using this method.
  • The posterior probability for the number of bins lacks a well-defined mode when data are too sparse, signaling insufficient information to infer bin structure.
  • The method outperforms classical rules like Scott’s and Freedman-Diaconis in multimodal settings, where those rules fail due to assumptions about unimodal or smooth densities.
  • The algorithm is implemented in MATLAB and Python (AstroML), with the Python function named `knuth_nbins`, enabling broad accessibility and application.
  • The method accounts for uncertainty in bin count by using the marginal posterior, though variance in bin heights is slightly underestimated due to fixed optimal M.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.