Ask Claude about this

Counting Successes in Trials: The Binomial Distribution

What is it for? Fixed Number of Tries with Two Outcomes

Imagine you're doing something a certain number of times, and each time, there are only two possible outcomes: either it's a "success" or it's a "failure." The Binomial distribution helps us figure out the chances of getting a specific number of "successes."

For this to work, a few conditions must be met:

  • You have a fixed number of tries (or "trials"). For example, flipping a coin 10 times.
  • Each try is independent. This means the outcome of one try doesn't affect any other try (like one coin flip doesn't change the next).
  • Each try has only two possible outcomes (e.g., heads or tails, click or no click, defective or not defective). We call one outcome "success" and the other "failure."
  • The probability of success (p) is the same for every single try. (e.g., a fair coin always has a 50% chance of heads). The probability of failure is then (1-p).

Some everyday examples where this applies:

  • Number of heads when you flip a coin 10 times.
  • Number of free throws a basketball player makes in 5 attempts (if their chance of making each shot is constant).
  • Number of people who click on an online ad out of 100 people who see it.

The Magic Formula (Binomial PMF)

If 'X' is the number of successes we're counting, and X follows a Binomial distribution, the probability of getting exactly k successes in n trials is given by this formula (called the Probability Mass Function, or PMF):

P(X = k) = C(n, k) * pk * (1-p)n-k

Let's break this down:

  • P(X = k): This is what we want to find – "the probability that the number of successes X is exactly equal to k".
  • n: The total number of tries (e.g., 20 people shown the ad).
  • k: The specific number of successes we're interested in (e.g., exactly 2 clicks). This 'k' must be between 0 and 'n'.
  • p: The probability of getting a "success" in a single try (e.g., 0.10 or 10% chance a person clicks).
  • (1-p): The probability of getting a "failure" in a single try (e.g., 1 - 0.10 = 0.90 or 90% chance a person does NOT click).
  • pk: The probability of success 'p' multiplied by itself 'k' times. (Chance of 'k' successes happening).
  • (1-p)n-k: The probability of failure '(1-p)' multiplied by itself '(n-k)' times. (Chance of the remaining 'n-k' tries being failures).
  • C(n, k): This is called the "binomial coefficient" or "combinations." It tells us how many different ways you can choose 'k' successes from 'n' trials. The formula for it is:
    C(n, k) = n! / (k! * (n-k)!)
    where '!' means factorial (e.g., 5! = 5 × 4 × 3 × 2 × 1).
    For example, C(5, 2) means "how many ways can you choose 2 items from a set of 5?" It's 10.

So, the formula essentially says: (Number of ways to arrange k successes) × (Probability of k successes) × (Probability of n-k failures).

Ad Clicks - Binomial Distribution

MODERATE

An advertisement is shown to 20 unique users. Each user clicks on the ad with an independent probability of 10%.

  1. What is the probability that exactly 2 users click on the ad?
  2. What is the probability that at least 1 user clicks on the ad?

What's the Expected Number? On average, how many users would you expect to click the ad out of these 20 users? For a Binomial distribution, the expected number of successes (average number) is calculated very simply: E[X] = n × p. Can you calculate it?

Nerchuko Academy · Free DS Interview Prep