The E-commerce Conversions (Bernoulli) case study modeled one part with the Bernoulli. Stack 50 of them into a batch and count the defects, and you have the binomial, the most important discrete distribution in quality control. It turns a per-part defect rate into a full forecast of batch outcomes.
manufacturing_qc_inspections.csv records 1,000 inspections, each a batch of
batch_size = 50 with a defective_count. We treat each batch as 50 Bernoulli trials
and model the count of defects.
From the Part Rate to the Batch Count
The per-part defect rate is total defects over total parts: p = 0.0385. That single rate, plugged into the binomial, predicts the whole distribution of defects per batch, mean np = 1.93, variance np(1−p) = 1.85, both matching the data exactly.
The term C(50, k) counts the ways k defects can land among 50 parts, the combinatorics of Counting & Combinatorics made concrete. Multiply by the probability of any one such arrangement, pk(1−p)50−k, and the binomial PMF drops right onto the observed batches.
The Risk of a Bad Batch
Quality rules are thresholds, and the CDF P(X ≤ k) prices them. Reading it off the model tells the plant exactly how much production a given accept/reject rule will scrap.
| Rule | P(X ≤ k) accept | P(X > k) reject |
|---|---|---|
| at most 0 defects | 0.140 | 0.860 |
| at most 1 defect | 0.421 | 0.579 |
| at most 2 defects | 0.697 | 0.303 |
| at most 3 defects | 0.874 | 0.126 |
| at most 5 defects | 0.988 | 0.012 |
A "reject if more than 2 defects" rule accepts 70% of batches, so it scraps about 30%, a costly bar. Loosening it to "more than 3" cuts scrap to 13%. The hand-computed P(X = 2) = C(50, 2) p²(1−p)⁴⁸ matches SciPy to four decimals, confirming the model is exactly the binomial.
Simulating a Production Run
Scale a single batch up to a full shift. The defect-free rate is P(X = 0) = (1−p)50 ≈ 14%, and a 30-batch day produces a total that is a sum of binomials, centered near 58 defects and, by the Central Limit Theorem, approximately normal.
Every binomial is just n Bernoulli trials added together, which is why np is the mean (n trials, each contributing p) and np(1−p) is the variance (n independent variances). Simulating 200,000 batches reproduces the mean 1.93 and the 14% defect-free rate, and a simulated day lets the plant budget rework from the distribution, not a guess.
Run the QC analysis
The companion notebook estimates the defect rate, overlays the fitted Binomial(50, 0.0385) on the observed batch counts, validates the fit with a chi-square goodness-of-fit test, tabulates the accept/reject CDF, confirms P(X = 2) by hand with C(50, 2), and simulates a production run, every figure reproduced in code.
View opens the rendered notebook instantly (no setup). Open in Colab runs &
edits it live in your browser. To run locally, install numpy, pandas, scipy,
and matplotlib and launch jupyter notebook.
🎓 Key Takeaways
- ✓Defects per fixed batch are binomial: n = 50 trials, defect rate p; PMF C(n, k) pk(1−p)n−k.
- ✓One rate p = 0.0385 gives mean np = 1.93 and variance np(1−p) = 1.85, both matching the data.
- ✓The CDF prices accept/reject rules: P(X ≤ 2) = 0.70, so a "more than 2" rule scraps 30% of batches.
- ✓C(50, k) counts the arrangements of k defects among 50 parts, combinatorics turning a part rate into a batch forecast.
- ✓A binomial is a sum of Bernoullis, and a day of batches is approximately normal by the CLT.
Quiz: Test Yourself
Eight quick questions on the binomial case study. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved, so you can hop back to the chapter and return anytime.