Skip to content

Instantly share code, notes, and snippets.

@armgilles
Created May 12, 2015 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armgilles/a0feddefc3d29c2f1a29 to your computer and use it in GitHub Desktop.
Save armgilles/a0feddefc3d29c2f1a29 to your computer and use it in GitHub Desktop.
Looking for optimal bin for a histogram

sturges = lambda n: int(log2(n) + 1) square_root = lambda n: int(sqrt(n)) from scipy.stats import kurtosis doanes = lambda data: int(1 + log(len(data)) + log(1 + kurtosis(data) * (len(data) / 6.) ** 0.5))

n = len(titanic) sturges(n), square_root(n), doanes(titanic.fare.dropna())

titanic.fare.hist(bins=doanes(titanic.fare.dropna()))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment