In [1]:
import numpy
from matplotlib import pyplot
from collections import Counter
import csv
In [2]:
def geom(k, p):
    return (1-p)**(k-1) * p
In [9]:
1 / geom(96, 0.05)
Out[9]:
2613.8911192008204
In [10]:
numpy.random.poisson(5, size=10)
Out[10]:
array([ 8,  4,  5,  6,  5, 11,  3,  4,  9,  6])
In [19]:
poissons = numpy.random.poisson(5, size=1000)
poissons.mean()
Out[19]:
4.961
In [20]:
poissons.var()
Out[20]:
5.049478999999999
In [14]:
poissons.std()
Out[14]:
2.229792591251482
In [22]:
pyplot.hist(poissons, bins=range(0, 15))
Out[22]:
(array([  9.,  29., 101., 143., 164., 169., 132., 125.,  67.,  34.,  16.,
          6.,   1.,   4.]),
 array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14]),
 <a list of 14 Patch objects>)
In [36]:
uniform_variates = numpy.random.random(size=2000)
integer_variates = numpy.floor(uniform_variates * 200)
binned_counts = Counter(integer_variates)
In [38]:
pyplot.hist(integer_variates, bins=range(0,201))
pyplot.show()
In [39]:
pyplot.hist(binned_counts.values(), bins=range(0, 20))
pyplot.show()
In [40]:
count_per_bin = numpy.array([n for n in binned_counts.values()])
count_per_bin.mean()
Out[40]:
10.0
In [41]:
count_per_bin.var()
Out[41]:
8.78
In [52]:
nets_games = []

with open("brooklyn_nets.txt") as file_reader:
    csv_reader = csv.DictReader(file_reader)
    for row in csv_reader:
        nets_games.append(row)
print(nets_games[0])

stats = numpy.array([ int(game["3P"]) for game in nets_games ])
print(stats[:10])
OrderedDict([('Rk', '1'), ('G', '1'), ('Date', '2018-10-17'), ('Away', '@'), ('Opp', '103'), ('W/L', 'L'), ('Tm', '100'), ('FG', '39'), ('FGA', '92'), ('FG%', '.424'), ('3P', '6'), ('3PA', '24'), ('3P%', '.250'), ('FT', '19'), ('FTA', '22'), ('FT%', '.864'), ('ORB', '14'), ('TRB', '46'), ('AST', '21'), ('STL', '5'), ('BLK', '5'), ('TOV', '14'), ('PF', '20'), ('', '')])
[ 6  9 16  3  9 11  9 11 15  4]
In [53]:
stats.mean()
Out[53]:
10.047619047619047
In [54]:
stats.var()
Out[54]:
15.188208616780049
In [49]:
len(stats)
Out[49]:
63
In [55]:
pyplot.hist(stats, bins=range(0, 45))
pyplot.show()