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