Exercise

# Predicting the probability of defects

Any situation with exactly two possible outcomes can be modeled with **binomial** random variables. For example, you could model if someone likes or dislikes a product, or if they voted or not.

Let's model whether or not a component from a supplier comes with a defect. From the thousands of components that we got from a supplier, we are going to take a sample of 50, selected randomly. The agreed and accepted defect rate is 2%.

We import the `binom`

object from `scipy.stats`

.

Recall that:

`binom.pmf()`

calculates the probability of having exactly`k`

heads out of`n`

coin flips.`binom.cdf()`

calculates the probability of having`k`

heads or less out of`n`

coin flips.`binom.sf()`

calculates the probability of having more than`k`

heads out of`n`

coin flips.

Instructions 1/4

1

2

3

4

## Question

Let's answer a simple question before we start calculating probabilities:

- What is the probability of getting more than 20 heads from a fair coin after 30 coin flips?

### Possible answers

`binom.pmf(k=20, n=30, p=0.5)`

`1 - binom.pmf(k=20, n=30, p=0.5)`

`binom.sf(k=20, n=30, p=0.5)`

`binom.cdf(k=20, n=30, p=0.5)`