02.09 Lesson 9 of 12
1 hRandom Variables & Distributions
Understand random variables as numeric outcomes and distributions as descriptions of how probability is assigned across possible values.
By the end of this lesson
You will be able to
- Explain the difference between an event and a random variable.
- Distinguish probability mass and density at a high level.
- Recognize Bernoulli, binomial and normal distributions.
- Explain the difference between a distribution and one sample from it.
A random variable assigns a number to an uncertain outcome
A random variable maps an outcome to a numeric value. It is discrete when its possible values can be counted, such as the number of rentals in an hour. It is continuous when values lie on a continuum, such as temperature. A discrete distribution assigns probability mass to individual values; a continuous distribution uses a density, and probability is the area over an interval rather than the height at a single point.
rng = np.random.default_rng(7)
# A Bernoulli-like variable: 1 with probability 0.3
arrivals = rng.binomial(n=1, p=0.3, size=12)
print(arrivals) Recognize a few useful distributions
A Bernoulli variable represents one binary outcome, such as success or failure. A binomial variable counts successes across a fixed number of independent Bernoulli trials with the same success probability. A normal distribution is a continuous, symmetric distribution described by its mean and standard deviation. These are useful models, not guarantees that real data follows the shape exactly.
samples = rng.normal(loc=20.0, scale=4.0, size=1000)
print(samples.mean())
print(samples.std()) Apply what you learned
ExerciseSimulate uncertain outcomes
Generate samples from a Bernoulli and a normal distribution, then describe what the parameters control.
- Use
np.random.default_rng(42)to create a reproducible random generator. - Draw 1,000 Bernoulli samples with probability
0.3. - Calculate the observed proportion of ones and compare it with
0.3. - Draw 1,000 normal values with mean
20and standard deviation4. - Calculate the sample mean and standard deviation and explain why they are not exactly the parameters.
The random generator is seeded, both sample arrays have the requested size, and your explanation distinguishes a distribution parameter from statistics measured on one finite sample.
Free references
Study resources
- 01 The Main Ideas behind Probability Distributions Video
Watch the individual overview of distributions and connect possible values to their probabilities.
- 02 The Normal Distribution, Clearly Explained Video
Watch the explanation of the normal curve, mean, standard deviation and z-scores.
- 03 Sampling from a Distribution, Clearly Explained Video
Watch the standalone sampling explanation to connect a distribution with repeated draws.
Check your understanding
Self-test
-
Question 1
What is the difference between a random variable and a distribution?
The random variable maps uncertain outcomes to numbers. The distribution describes the probabilities associated with those possible values. -
Question 2
What does the standard deviation parameter control in a normal distribution?
It controls the spread of values around the mean; a larger standard deviation makes the distribution wider.
Completion check
Move on when
You can identify discrete and continuous variables, describe the purpose of common distributions and simulate samples reproducibly.