Implement the Binomial distribution Probability Mass Function (PMF) and Cumulative Distribution Function (CDF). The Binomial distribution counts the number of successes in n independent Bernoulli trials with probability p.
Binomial Distribution:
Probability Mass Function:
P(X=k)=(kn)pk(1−p)n−kCumulative Distribution Function:
P(X≤k)=i=0∑k(in)pi(1−p)n−in: int - Number of trialsp: float - Success probability (0 ≤ p ≤ 1)k: int - Number of successes (0 ≤ k ≤ n)Input: n=5, p=0.5, k=2
Output: pmf=0.3125, cdf=0.5
Input: n=10, p=0.3, k=0
Output: pmf=0.0282, cdf=0.0282
Input: n=8, p=0.7, k=8
Output: pmf=0.0576, cdf=1.0
Use scipy.special.comb() for stable binomial coefficients instead of factorial.
For CDF, sum PMF values from i=0 to k using a loop.
Convert results to float: float(pmf), float(cdf).
Sign in to take notes on this problem
Accepts: number
Accepts: number
Accepts: number
Implement the Binomial distribution Probability Mass Function (PMF) and Cumulative Distribution Function (CDF). The Binomial distribution counts the number of successes in n independent Bernoulli trials with probability p.
Binomial Distribution:
Probability Mass Function:
P(X=k)=(kn)pk(1−p)n−kCumulative Distribution Function:
P(X≤k)=i=0∑k(in)pi(1−p)n−in: int - Number of trialsp: float - Success probability (0 ≤ p ≤ 1)k: int - Number of successes (0 ≤ k ≤ n)Input: n=5, p=0.5, k=2
Output: pmf=0.3125, cdf=0.5
Input: n=10, p=0.3, k=0
Output: pmf=0.0282, cdf=0.0282
Input: n=8, p=0.7, k=8
Output: pmf=0.0576, cdf=1.0
Use scipy.special.comb() for stable binomial coefficients instead of factorial.
For CDF, sum PMF values from i=0 to k using a loop.
Convert results to float: float(pmf), float(cdf).
Sign in to take notes on this problem
Accepts: number
Accepts: number
Accepts: number