December 2017
Intermediate to advanced
386 pages
10h 42m
English
The pmf of a binomial outcome is obtained in Python using a set of functions in the binom module within scipy.stats.
The steps to plot the probability mass function of a discrete random variable are as follows:
from scipy.stats import binomimport matplotlib.pyplot as pltimport numpy as np
n=5p=0.4
Define x. In our case, x can take values from 0 to the maximum (which is n):
x=np.arange(0,(n+1))print(x)[0 1 2 3 4 5]
Pass x through the pmf function. Note that the pmf function calculates the f(x) value as discussed in the previous ...
Read now
Unlock full access