Popular recipes tagged "benford"http://code.activestate.com/recipes/tags/benford/popular/2010-10-19T10:56:51-07:00ActiveState Code RecipesBenford's Law demo (Python)
2010-10-19T10:56:51-07:00Glenn Hutchingshttp://code.activestate.com/recipes/users/4175415/http://code.activestate.com/recipes/577431-benfords-law-demo/
<p style="color: grey">
Python
recipe 577431
by <a href="/recipes/users/4175415/">Glenn Hutchings</a>
(<a href="/recipes/tags/benford/">benford</a>, <a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/plotting/">plotting</a>).
</p>
<p>Here's a simple program to demonstrate <a href="http://en.wikipedia.org/wiki/Benford%27s_law">Benford's Law</a>, which also shows the simple power of <a href="http://matplotlib.sourceforge.net">matplotlib</a>. It reads from a bunch of files (or stdin, if none specified), extracts the leading digits of all number-like strings found, and plots the distribution in a window together with the expected result if Benford's law applies.</p>