import numpy as np
import scipy.stats as st
import matplotlib.pyplot as pltBinomial = st.binomB = Binomial(5, 0.5) # K, pB.rvs(size = 10) # random variables / random numbersarray([2, 4, 4, 1, 3, 2, 3, 5, 4, 4])B.pmf(2) # f( x = 2 |K, p) / probability mass function / density function0.3125B.pmf(3)0.31249999999999994x = np.arange(6)
f = B.pmf(x)
farray([0.03125, 0.15625, 0.3125 , 0.3125 , 0.15625, 0.03125])np.sum(f)0.9999999999999999plt.scatter(x, f)
# https://roualdes.us/lecturenotes/binomial
# Q2
# a.
X = Binomial(10, 0.95)
fx = X.pmf(10)
fx0.5987369392383787# b.
np.sum(X.pmf(np.array([8, 9, 10])))0.9884964426207032s = np.arange(11)
plt.scatter(s, X.pmf(s))