Last active
November 23, 2018 17:58
-
-
Save colobas/c06e1bb0bcdef554067f6f9cc6f9bc8f to your computer and use it in GitHub Desktop.
Compute the recommended bin size for a histogram, according to the Freedman-Diaconis rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bin_size(x): | |
""" | |
https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule | |
""" | |
return (2 * (np.nanquantile(x, 0.75) - np.nanquantile(x, 0.25)) / | |
np.cbrt(len(x[~np.isnan(x)]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the quantiles are in the wrong order :)