The Freedman-Diaconis histogram bin estimator. The Freedman-Diaconis rule uses interquartile range (IQR) to estimate binwidth. It is considered a variation of the Scott rule with more robustness as the IQR is less affected by outliers than the standard deviation. However, the I
(x, range)
| 198 | |
| 199 | |
| 200 | def _hist_bin_fd(x, range): |
| 201 | """ |
| 202 | The Freedman-Diaconis histogram bin estimator. |
| 203 | |
| 204 | The Freedman-Diaconis rule uses interquartile range (IQR) to |
| 205 | estimate binwidth. It is considered a variation of the Scott rule |
| 206 | with more robustness as the IQR is less affected by outliers than |
| 207 | the standard deviation. However, the IQR depends on fewer points |
| 208 | than the standard deviation, so it is less accurate, especially for |
| 209 | long tailed distributions. |
| 210 | |
| 211 | If the IQR is 0, this function returns 0 for the bin width. |
| 212 | Binwidth is inversely proportional to the cube root of data size |
| 213 | (asymptotically optimal). |
| 214 | |
| 215 | Parameters |
| 216 | ---------- |
| 217 | x : array_like |
| 218 | Input data that is to be histogrammed, trimmed to range. May not |
| 219 | be empty. |
| 220 | |
| 221 | Returns |
| 222 | ------- |
| 223 | h : An estimate of the optimal bin width for the given data. |
| 224 | """ |
| 225 | del range # unused |
| 226 | iqr = np.subtract(*np.percentile(x, [75, 25])) |
| 227 | return 2.0 * iqr * x.size ** (-1.0 / 3.0) |
| 228 | |
| 229 | |
| 230 | def _hist_bin_auto(x, range): |
no outgoing calls
no test coverage detected
searching dependent graphs…