Preview

A lesson from Essential Probability & Statistics for ML

£29/month

£29/month£29/month or £249/year · 30-day money-back guarantee

Get full access

Our content is best on a larger screen

The Bernoulli distribution

The Bernoulli story

Explanation

The PMF of a discrete random variable gives its distribution: from it we can find the probability of any event about the random variable. Random variables from quite different experiments often have PMFs of the same form, and the forms that come up most often are given names.

It helps to remember each one by a story: a simple experiment that gives rise to it. The simplest story is a single trial in which some event happens with probability pp and otherwise does not, such as a coin landing heads.

We call it a success if the event happens and a failure if it does not, and let X=1X = 1 on a success and X=0X = 0 on a failure. Then P(X=0)=1−pP(X = 0) = 1 - p, so the one number pp fixes the whole PMF.

The Bernoulli distribution

Definition

A random variable XX that takes only the values 00 and 11 has the Bernoulli distribution with parameter pp, where 0<p<10 < p < 1, when

P(X=1)=pandP(X=0)=1−pP(X = 1) = p \quad \text{and} \quad P(X = 0) = 1 - p

We write X∼Bern⁡(p)X \sim \operatorname{Bern}(p), and read ∼\sim as "is distributed as".

Key Point

Each value of pp gives a different Bernoulli distribution. Saying that XX is Bernoulli does not fix its PMF until pp is given.

The bar chart below shows how the PMF changes with pp.

0
1
0.2
0.4
0.6
0.8
1
x
P(X=x)
0.7
0.3
X∼Bern(0.3)P(X=1)=0.3P(X=0)=0.7

The bar at 1 has height p and the bar at 0 has height 1−p.

Practice questions

4 questions

Which of these random variables has a Bernoulli distribution?

Select the correct answer:

+ 3 more questions · unlocked with a subscription

The mean of a Bernoulli

Explanation

For a named distribution we usually find two summaries first. The mean tells us where its values are centred, and the variance tells us how far they tend to lie from that centre. Together they give a quick picture of the distribution without its full PMF.

For X∼Bern⁡(p)X \sim \operatorname{Bern}(p), we find the mean in terms of pp with the expected value formula, which multiplies each value by its probability and adds:

E[X]=∑xx P(X=x)\mathbb{E}[X] = \sum_x x\,P(X = x)

A Bernoulli random variable has two values, so the sum has two terms:

E[X]=0×(1−p)+1×p=p\begin{align*} \mathbb{E}[X] &= 0 \times (1 - p) + 1 \times p \\[6pt] &= p \end{align*}

The value 00 contributes nothing, so the mean is the success probability.

The mean of a Bernoulli

Theorem

If X∼Bern⁡(p)X \sim \operatorname{Bern}(p), then

E[X]=p\mathbb{E}[X] = p

This matches the mean as a long-run average: over many trials, the average of XX is the proportion of trials that are successes, which is close to pp.

Example

A random variable XX takes only the values 00 and 11, and E[X]=0.18\mathbb{E}[X] = 0.18. Find the PMF of XX.

Solution

XX takes only the values 00 and 11, so XX has a Bernoulli distribution, X∼Bern⁡(p)X \sim \operatorname{Bern}(p) for some pp.

The mean of a Bernoulli is its success probability, so the stated mean gives the parameter:

p=P(X=1)=E[X]=0.18p = P(X = 1) = \mathbb{E}[X] = 0.18

The value 00 has the remaining probability:

P(X=0)=1−0.18=0.82P(X = 0) = 1 - 0.18 = 0.82

The PMF of XX is

xx0011
P(X=x)P(X = x)0.820.820.180.18

so XX is distributed as Bern⁡(0.18)\operatorname{Bern}(0.18).

Practice questions

4 questions

A factory part fails its check with probability 0.040.04, and X=1X = 1 if the part passes and X=0X = 0 if it fails. What is E[X]\mathbb{E}[X]?

Select the correct answer:

+ 3 more questions · unlocked with a subscription

The variance of a Bernoulli

Explanation

Like its mean, the variance of a Bernoulli depends only on pp.

The variance of a Bernoulli

Theorem

If X∼Bern⁡(p)X \sim \operatorname{Bern}(p), then

Var⁡(X)=p(1−p)\operatorname{Var}(X) = p(1 - p)

That is, the variance of a Bernoulli is its success probability times its failure probability. The steps below show how it depends on pp.

0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0.05
0.1
0.15
0.2
0.25
0.3
0
p
Var(X)
0.16

Step 1: One point for each p

Each point on the curve is the variance of Bern(p) for one value of p. At p=0.2 it is 0.2×0.8=0.16.

Step 2: Near 0 and 1

Near p=0 or p=1, one result is almost certain. X almost always takes the same value and rarely strays from its mean, so the variance is close to 0.

Step 3: Symmetry about p=12

The curve is symmetric about p=12. Swapping p and 1−p swaps the two factors of p(1−p), so p=0.2 and p=0.8 give the same variance, 0.16.

Step 4: The largest variance

The variance is largest at p=12, where its value is 14. Neither result is favoured, as with a fair coin toss, so we are least sure which value X will take, and it varies most about its mean.

Why is the variance p(1−p)p(1 - p)?

Details

Example

Machine AA makes a faulty part with probability 0.10.1, and machine BB with probability 0.40.4. For one part from each machine, X=1X = 1 if the part from AA is faulty and 00 otherwise, and Y=1Y = 1 if the part from BB is faulty and 00 otherwise. Which of XX and YY has the larger variance?

Solution

XX takes only the values 00 and 11, with X=1X = 1 when the part from machine AA is faulty. That happens with probability 0.10.1, so XX is Bernoulli with parameter 0.10.1. In the same way, YY is Bernoulli with parameter 0.40.4:

X∼Bern⁡(0.1)andY∼Bern⁡(0.4)X \sim \operatorname{Bern}(0.1) \quad \text{and} \quad Y \sim \operatorname{Bern}(0.4)

The variance of a Bernoulli is its success probability times its failure probability:

Var⁡(X)=0.1×0.9=0.09Var⁡(Y)=0.4×0.6=0.24\begin{align*} \operatorname{Var}(X) &= 0.1 \times 0.9 = 0.09 \\[6pt] \operatorname{Var}(Y) &= 0.4 \times 0.6 = 0.24 \end{align*}

So YY has the larger variance.

This fits the shape of p(1−p)p(1 - p): the variance is largest at p=12p = \dfrac{1}{2}, and 0.40.4 is nearer 12\dfrac{1}{2} than 0.10.1 is.

Practice questions

5 questions

A bulb lasts a year with probability 0.90.9, and X=1X = 1 if it does and X=0X = 0 if it does not. What is Var⁡(X)\operatorname{Var}(X)?

Select the correct answer:

+ 4 more questions · unlocked with a subscription

Memory is built by recalling, not by reading.

Every time you pull an answer from memory, the memory gets stronger. Reading doesn't do that. Nodeledge asks you questions on every step of every lesson, then asks again after days, weeks and months.

Get full access

£29/month or £249/year · 30-day money-back guarantee

See the learning path