knuth_bin_count#
- scikitplot.feature_selection.knuth_bin_count(values, min_bins=1, max_bins=100)[source]#
Return the equal-width bin count that maximises Knuth’s posterior.
- Parameters:
- valuesarray-like of float
Finite sample values.
- min_bins, max_binsint, default=1, 100
Inclusive search range.
- Returns:
- int
The count with the largest log posterior; the smallest such count on an exact tie.
- Raises:
- ValueError
For an empty sample, non-finite values or an invalid range.
- Parameters:
- Return type:
Notes
The log posterior of
Mequal-width bins with countsn_koverNvalues is (Knuth 2006, eq. 31):N log M + lgamma(M/2) - M lgamma(1/2) - lgamma(N + M/2) + sum_k lgamma(n_k + 1/2)
Examples
>>> import numpy as np >>> from scikitplot.feature_selection import knuth_bin_count >>> knuth_bin_count(np.random.default_rng(0).normal(size=1000), 1, 50) 9