TL;DR
Many random experiments have only two outcomes: a coin lands heads or tails, a part passes or fails, a click happens or does not. The Bernoulli distribution is the model for one such trial. It has a single parameter , the chance of success, and the chance of failure is then .
Its real power comes from building blocks. Count how many successes happen across many independent trials and you get a binomial count. Use it as the output of a classifier and you get the standard yes-or-no loss.
Where you'll see it: in dropout, where each neuron is kept or switched off by a coin flip, and in binary classifiers, which predict the probability that a label is 1.
Intuition
Only two answers
Take a single item off a production line and ask whether it is defective. There are two outcomes, and nothing in between. You can describe the situation completely with one number: the defect rate. If one item in five is defective, the defect rate is , and every other fact about the single item follows from it.
That is the Bernoulli model. It is the simplest possible random variable, a random variable that takes only the values 0 and 1. Calling 1 a success and 0 a failure is just a labelling choice. The number is the whole story.
Almost every binary question in machine learning reduces to a Bernoulli trial. Whether a user clicks, whether an email is spam, whether a neuron survives dropout, each is one coin flip with a bias that the model has to estimate.
- p = 0.2
- p = 0.5
The math
Definition
A random variable is Bernoulli with parameter , where , when
We write .
A compact way to write the same probability mass function is
Substitute and you get . Substitute and you get . The two rules from probability are satisfied: both values are between 0 and 1, and they sum to 1.
Mean and variance
The expected value is the probability-weighted average of the outcomes:
So the long-run fraction of successes equals , which is why is called the success probability.
The variance is the expected squared distance from the mean. Since when is 0 or 1, we have , and therefore
The variance is largest at , where the outcome is most uncertain, and it falls to zero at or , where the outcome is certain. The standard deviation is the square root of the variance.
Sums of independent trials
If are independent Bernoulli trials, each with the same , their sum counts the successes. Its distribution is the binomial distribution, with mean and variance . The variances add because the trials are independent.
Worked examples
Part one: a fair coin. Let .
- Mean: .
- Variance: .
- Standard deviation: .
Part two: a defective part. Let , the chance an item is defective.
- Mean: , so one item in five is expected to be defective.
- Variance: .
- Standard deviation: .
Interpretation: the fair coin is the most uncertain case, with a standard deviation of 0.5 that is as large as a Bernoulli can get. The defective-part model is more predictable, because most items succeed and the variance is smaller.
Using the defect rate from above, let each item be an independent trial, and ask for the chance that all 10 items are good, meaning every trial is a failure.
- The chance that one item is good is .
- Independence means the chances multiply: .
- , , , and .
- Expected number of defects in 10 items: .
Interpretation: a clean run of 10 happens only about 11% of the time, even though each item is good 80% of the time. Independent small chances compound quickly, which is why a batch test that looks fine item by item can still fail often at batch scale.
Tradeoffs and failure modes
The Bernoulli model is the right choice when each trial has exactly two outcomes and the trials are independent with a fixed success chance. It fails in predictable ways when those conditions break.
| Situation | Problem | Better choice |
|---|---|---|
| More than two outcomes, such as a die roll | One success probability cannot describe several categories | Categorical distribution |
| Trials that influence each other, such as draws without replacement | Independence is violated, so variances do not add | Hypergeometric or a model of the dependence |
| The success chance itself changes over time | A single fixed is wrong | A model where varies, or a sequence of separate estimates |
| A count of successes over many trials | Tracking each trial is unnecessary | Binomial distribution for the total |
| A continuous quantity such as a waiting time | Bernoulli only models yes or no | Exponential or Gaussian, depending on the shape |
One common mistake is to treat a rare-event rate as certain after seeing few trials. With 3 failures in 3 trials, a naive estimate of is 0, which says success is impossible. That is a symptom of too little data, not evidence.
History
The Bernoulli distribution is named after the Swiss mathematician Jacob Bernoulli. His book Ars Conjectandi, published in 1713 after his death, contains his law of large numbers for repeated binary trials. It shows that the observed fraction of successes approaches as the number of trials grows, which gave a mathematical basis for estimating a probability from frequencies.
The idea caught on because nearly every question about a yes-or-no outcome reduces to it. In the twentieth century it became the standard building block for statistical testing and for models of binary data. In modern machine learning, the Bernoulli likelihood underlies logistic regression and the binary cross-entropy loss used to train binary classifiers.
Check yourself
QuestionA coin has of landing heads. What are the mean and the variance of a single flip, where heads counts as 1?Show answer
The mean is . The variance is .
QuestionFor a Bernoulli with , the variance is 0.25. For , what is the variance, and why is it smaller?Show answer
The variance is . It is smaller because the outcome is more predictable: almost every trial is a success, so there is less spread around the mean.
QuestionTen independent trials each have success probability 0.3. What is the probability that all ten fail, and what is the expected number of successes?Show answer
Each trial fails with probability 0.7, so all ten fail with probability . The expected number of successes is .
QuestionA model predicts that an email is spam with probability . The true label is spam, so . Compute the binary cross-entropy loss . Then do the same if the true label is not spam, so .Show answer
If , the loss is . If , the loss is . The loss is small when the prediction matches the label and large when the model is confidently wrong. This is the Bernoulli likelihood turned into a training loss, which is the reason it appears in classifier training.
QuestionIn dropout, each neuron is kept with probability 0.8 and dropped otherwise. Why can each neuron's mask be modelled as a Bernoulli trial, and what does the number of kept neurons follow?Show answer
Each neuron's keep-or-drop decision is a single yes-or-no outcome with a fixed chance of 0.8, applied independently. That is a Bernoulli trial. The number of kept neurons out of is a sum of independent Bernoulli trials, so it follows a binomial distribution with mean .
Sources
- Bernoulli distribution (Wikipedia): https://en.wikipedia.org/wiki/Bernoulli_distribution
- Jacob Bernoulli (Wikipedia): https://en.wikipedia.org/wiki/Jacob_Bernoulli
- Bishop, Pattern Recognition and Machine Learning, §2.1: https://www.microsoft.com/en-us/research/publication/pattern-recognition-machine-learning/