skfolio.utils.stats.n_bins_knuth#
- skfolio.utils.stats.n_bins_knuth(x)[source]#
Compute the optimal histogram bin size using Knuth’s rule [1].
The number of bins is bounded to \([1, n]\), where \(n\) is the number of observations. Data with many repeated values, such as zero-filled returns, push the estimate toward the upper bound.
- Parameters:
- xndarray of shape (n_observations,)
The input array.
- Returns:
- n_binsint
The optimal bin size.
References
[1]“Optimal Data-Based Binning for Histograms”. Knuth.