Benford's law: Difference between revisions

→‎{{header|Python}}: Print percentages and deviation.
m (→‎{{header|Python}}: Make Python 3.X as well as 2.7 compatable)
(→‎{{header|Python}}: Print percentages and deviation.)
Line 92:
res = [c/float(size) for c in f]
print("\n%s expectedBenfords deviation" % title)
for xr, e in zip(res, expected):
print("%5.4f1f%% %5.4f1f%% %5.1f%%" % x(r*100., e*100., abs(r - e)*100.))
def rand1000():
Line 106:
show_dist("random", islice(heads(rand1000()), 10000))</lang>
{{out}}
<pre>fibbed Benfords deviation
<pre>
30.1% 30.1% 0.0%
17.7% 17.6% 0.1%
12.5% 12.5% 0.0%
9.6% 9.7% 0.1%
8.0% 7.9% 0.1%
6.7% 6.7% 0.0%
5.6% 5.8% 0.2%
5.3% 5.1% 0.2%
4.5% 4.6% 0.1%
 
threes Benfords deviation
fibbed expected
30.0% 30.30101% 0.30101%
17.7% 17.6% 0.1%
0.1770 0.1761
12.3% 12.5% 0.2%
0.1250 0.1249
9.8% 9.7% 0.1%
0.0960 0.0969
7.9% 7.9% 0.0%
0.0800 0.0792
6.6% 6.7% 0.1%
0.0670 0.0669
5.9% 5.8% 0.1%
0.0560 0.0580
5.2% 5.1% 0.1%
0.0530 0.0512
4.6% 4.6% 0.0%
0.0450 0.0458
 
random Benfords deviation
threes expected
11.2% 30.1% 18.9%
0.3000 0.3010
10.9% 17.6% 6.7%
0.1770 0.1761
11.6% 12.5% 0.9%
0.1230 0.1249
11.1% 9.7% 1.4%
0.0980 0.0969
11.6% 7.9% 3.7%
0.0790 0.0792
11.4% 6.7% 4.7%
0.0660 0.0669
10.3% 5.8% 4.5%
0.0590 0.0580
11.0% 5.1% 5.9%
0.0520 0.0512
10.9% 4.6% 6.3%</pre>
0.0460 0.0458
 
random expected
0.1085 0.3010
0.1070 0.1761
0.1109 0.1249
0.1092 0.0969
0.1130 0.0792
0.1175 0.0669
0.1125 0.0580
0.1089 0.0512
0.1125 0.0458
</pre>
Anonymous user