AI ProgrammingAcademy
Back to Samples

Optional Math: Statistics and Probability

Summarize small datasets and describe uncertainty using everyday examples. Optional support only—not a prerequisite for exams or certificates.

Learning Objectives

  • Compare mean and median

    Understand why an unusually large value can change an average.

  • Measure simple spread

    Use the range to describe how far apart the smallest and largest observations are.

  • Interpret probability

    Read values between zero and one without treating predictions as guarantees.

Core Concepts

1. Calculate the mean

The mean is the sum divided by the number of observations. For 2, 4 and 6, the sum is 12 and the count is 3, giving a mean of 4. An empty dataset has no mean; never divide by a count of zero.

values = [2, 4, 6]
mean = sum(values) / len(values)
print(mean)  # 4.0

2. Find the median and notice outliers

Sort the values and take the middle one. For an even count, average the two middle values. The median of 2, 4 and 30 is 4, while the mean is 12. The large observation pulls the mean up; it may be valid data or an error worth checking.

from statistics import mean, median
values = [2, 4, 30]
print(mean(values))    # 12
print(median(values))  # 4
print(median([2, 4, 6, 8]))  # 5.0

3. Describe spread

The range is the maximum minus the minimum. Datasets can have the same mean but very different spread. Standard deviation is a more detailed measure you will meet later; the range is enough for this first comparison.

steady = [4, 5, 6]
variable = [0, 5, 10]
print(max(steady) - min(steady))      # 2
print(max(variable) - min(variable))  # 10

4. Read a probability

A probability of 0 means impossible under the stated model; 1 means certain under that model. If a bag contains 3 blue counters and 1 red counter, the chance of a blue counter on one random draw is 3/4 = 0.75. Drawing without replacement changes the next probability. Multiplying probabilities is valid for independent events, not all events.

blue = 3
red = 1
p_blue = blue / (blue + red)
print(p_blue)  # 0.75

AI scores need context: A model score of 0.75 is not automatically a reliable 75% chance. Calibration, representative data and evaluation matter.

Practice Exercise

Summarize response times

For response times of 1, 2, 2, 3 and 12 seconds, calculate the mean, median and range. Then calculate the observed share finishing within 3 seconds. This observed share is not a guarantee about the next request.
times = [1, 2, 2, 3, 12]
# Print mean, median, range and share at or below 3

Concept Quiz

Test your understanding with this quiz. Select the best answer for each question.

1. Which summary is less affected by one very large observation?

2. A bag has 2 red and 3 blue counters. What is the probability of red on one random draw?

Are there any issues that Customer Support should be aware of?

Help optimize our AI programming lessons to ensure student success!

Sign in to send a comment to Customer Support.

Hide Icons