import numpy as np from scipy import stats import matplotlib.pyplot as plt import matplotlib.mlab as mlab %pylab inline #distribution of random process mean=.5 stddev=np.sqrt(.5*.5/162) samples=30 coinflips=np.random.normal(loc=mean, scale=stddev, size=samples) plt.plot(coinflips,ones(len(coinflips)),'.',markersize=40, alpha=.4) plt.xlim(mean-3.5*stddev,mean+3.5*stddev) plt.yticks([]) plt.xlabel("% heads") plt.show() #probability distribution for random process mean=.5 stddev=np.sqrt(.5*.5/162) #/162) x = np.linspace(mean-4*stddev,mean+4*stddev,100) plt.plot(x,mlab.normpdf(x,mean,stddev)) plt.xlim(mean-3.5*stddev,mean+3.5*stddev) plt.xlabel("% heads") plt.show() #distribution of baseball winning percentage mean=.5 stddev=.072 x = np.linspace(mean-4*stddev,mean+4*stddev,100) plt.plot(x,mlab.normpdf(x,mean,stddev)) plt.xlim(mean-3.5*stddev,mean+3.5*stddev) plt.xlabel("% wins") plt.show() mean=.5 stddev=np.sqrt(.5*.5/162) x = np.linspace(mean-6*stddev,mean+6*stddev,100) plt.plot(x,mlab.normpdf(x,mean,stddev),label="random") mean=.5 stddev=.072 x = np.linspace(mean-4*stddev,mean+4*stddev,100) plt.plot(x,mlab.normpdf(x,mean,stddev),label="baseball") plt.xlim(mean-3.5*stddev,mean+3.5*stddev) plt.yticks([]) plt.legend() plt.show()