02.09 Lesson 9 of 12

1 h

Random 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

Exercise

Simulate uncertain outcomes

Generate samples from a Bernoulli and a normal distribution, then describe what the parameters control.

  1. Use np.random.default_rng(42) to create a reproducible random generator.
  2. Draw 1,000 Bernoulli samples with probability 0.3.
  3. Calculate the observed proportion of ones and compare it with 0.3.
  4. Draw 1,000 normal values with mean 20 and standard deviation 4.
  5. Calculate the sample mean and standard deviation and explain why they are not exactly the parameters.
Done when

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

3 links
  1. 01
    The Main Ideas behind Probability Distributions Video

    Watch the individual overview of distributions and connect possible values to their probabilities.

  2. 02
    The Normal Distribution, Clearly Explained Video

    Watch the explanation of the normal curve, mean, standard deviation and z-scores.

  3. 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

2 questions
  1. Question 1

    What is the difference between a random variable and a distribution?

  2. Question 2

    What does the standard deviation parameter control in a normal distribution?

Completion check

Move on when

You can identify discrete and continuous variables, describe the purpose of common distributions and simulate samples reproducibly.

Quick find

Search Michi

Type to search every stage, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels