liveBook · Manning

Binom.pmf

As explained in Statistics Every Programmer Needs

binom.pmf is a SciPy statistics API method that evaluates the probability mass function of a binomial distribution.

binom.pmf evaluates the probability mass function for a binomial distribution: given k successes, n independent trials, and success probability p, it returns the corresponding probability. It replaces direct factorial-and-power arithmetic with a SciPy statistics API call. section 3.1.2

Probability of seven successes

With n = 20 trials, k = 7 successes, and p = 0.2, calculate and format the result: `probability = binom.pmf(7, 20, 0.2)`; multiplying by 100 gives approximately 5.455%. The same inputs can be compared with the direct binomial formula. section 3.1.2

>>> from scipy.stats import binom
>>> pmf = binom.pmf(k, n, p[i])

Use the compact vectorized call `binom.pmf(k, n, p[i])` to evaluate probabilities across success counts and compare distributions with plotting code. section 3.1.2

How Statistics Every Programmer Needs covers it

How deep it goes
Explains the API call, its parameters, and outputs, while stopping short of implementation internals.
Examples
Uses twenty trials with success probabilities 0.20, 0.50, 0.75, and 0.90, including seven successes at p=0.20.
What it assumes
Assumes binomial trials, success counts, and success probabilities while relating the mean to n multiplied by p.
What you can do after
Apply it via SciPy to calculate binomial probabilities and compare how success probabilities shift distribution means.
How it connects
Connects binom.pmf with binomial distribution, probability mass function, independent trials, and normal distribution.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.