AI ProgrammingAcademy
Back to Samples

Probability and Statistics: Basic Level

Understand uncertainty, summarize data, and evaluate predictions.

About This Lesson

Probability describes how likely something is to happen. Statistics helps us learn from collected information, called data. AI uses both to make predictions and check whether they are useful. You will also see how chatbots pick their next word with temperature and random sampling, and how image-generating AI learns to remove noise.

Free preview — no account needed. This is the Basic level of a Mathematical Foundations lesson from the AI Professional Series. The Intermediate and Advanced levels, with 20 more practice exercises and a Concept Quiz, are part of AI Professional. Optional practice only: it does not affect course totals, exams or certificates.

See AI Professional plans

This is the Basic level. There are 10 practice exercises, each with a hint and a full worked solution.

Basic Level: Learning Objectives

Start here if probability is new to you. Explore chance, averages, spread, and simple combinations of events.

  • Express a chance as a number from 0 to 1.
  • Find the chance that something does not happen.
  • Calculate mean, median, mode, and range.
  • Combine independent events using AND and OR.

Basic Level: Core Concepts

1. Probability measures chance

An event is an outcome or group of outcomes we care about. Its probability is a number from 0 to 1: 0 means impossible and 1 means certain. Favourable outcomes are the ones that match the event. When all outcomes are equally likely, divide the number of favourable outcomes by the total number of outcomes.

In everyday words: Drawing a ticket from a well-mixed bag gives each ticket the same chance.

P(A) = favourable outcomes / total outcomes

Read it as: The probability of event A equals the number of favourable outcomes divided by the total number of equally likely outcomes.

Worked example: A bag contains 3 blue tickets and 7 yellow tickets. What is the probability of drawing blue?

  1. Count all tickets: 3 + 7 = 10.
  2. Count the favourable tickets: 3 are blue.
  3. Divide: 3 / 10 = 0.3.
  4. Multiply by 100 to express this as a percentage: 0.3 × 100 = 30%.

Answer: The probability is 0.3, or 30%.

Why it matters in AI: AI often reports a predicted probability rather than a definite answer. Understanding its scale helps you interpret that prediction.

2. Complements: the chance of not happening

The complement of an event means that the event does not happen. An event and its complement cover every possibility without overlap. Their probabilities therefore add to 1.

In everyday words: A delivery either arrives today or does not arrive today.

P(not A) = 1 − P(A)

Read it as: The probability of not A equals one minus the probability of A.

Worked example: The probability that a parcel arrives today is 0.8. What is the probability that it does not?

  1. Start with the total probability, 1.
  2. Subtract the arrival probability: 1 − 0.8 = 0.2.
  3. Convert to a percentage: 0.2 × 100 = 20%.

Answer: The probability of not arriving today is 0.2, or 20%.

Why it matters in AI: For a prediction with exactly two possible outcomes, knowing one probability gives you the other.

3. Mean, median, and mode: three kinds of typical

The mean is the sum of the values divided by how many values there are. The median is the middle value after sorting; with two middle values, take their mean. The mode is the most frequent value. There can be several modes, or no single most frequent value.

In everyday words: Typical spending could mean your average bill, your middle bill, or the bill amount you see most often.

mean = sum of values / number of values

Read it as: Add all the values, then divide by how many values there are.

Worked example: Find the mean, median, and mode of 2, 3, 3, 4, 8.

  1. The values are already sorted.
  2. Add them: 2 + 3 + 3 + 4 + 8 = 20.
  3. Divide by the count: 20 / 5 = 4, so the mean is 4.
  4. The third value is the middle of five values, so the median is 3.
  5. The value 3 appears twice; each other value appears once, so the mode is 3.

Answer: Mean = 4, median = 3, and mode = 3.

from statistics import mean, median, multimode
values = [2, 3, 3, 4, 8]
print(mean(values))
print(median(values))
print(multimode(values))

Why it matters in AI: These summaries help you inspect training data. A very large value can pull the mean upward while leaving the median nearly unchanged.

4. Range: a first measure of spread

Spread describes how far apart values are. The range is the largest value minus the smallest value. It is easy to calculate, but it ignores everything between those two values.

In everyday words: The difference between the hottest and coldest temperatures tells you how wide the day's temperature swing was.

range = largest value − smallest value

Read it as: Subtract the smallest value from the largest value.

Worked example: Daily order counts are 6, 9, 7, and 12. Find their range.

  1. The smallest count is 6.
  2. The largest count is 12.
  3. Subtract: 12 − 6 = 6.

Answer: The range is 6 orders.

Why it matters in AI: Range gives a quick check for unusually large or small data values. It is a starting point, not a complete picture of variation.

5. AND and OR for independent events

Events are independent when knowing one happened does not change the probability of the other. AND means both events happen. OR means at least one happens, including the possibility that both happen. For independent events, multiply for AND; for OR, add their probabilities and subtract the overlap.

In everyday words: Two separate fair coin tosses do not influence each other. Getting heads on either toss includes getting heads on both.

P(A AND B) = P(A) × P(B); P(A OR B) = P(A) + P(B) − P(A) × P(B)

Read it as: For independent events, multiply their probabilities for both. For at least one, add their probabilities and subtract their product.

Worked example: Two independent fair coins each have probability 0.5 of heads. Find the probability of two heads and of at least one head.

  1. For two heads, multiply: 0.5 × 0.5 = 0.25.
  2. Adding the separate probabilities gives 0.5 + 0.5 = 1.
  3. This counts two heads twice, so subtract that overlap: 1 − 0.25 = 0.75.

Answer: Two heads has probability 0.25. At least one head has probability 0.75.

Why it matters in AI: AI systems combine uncertain events. Multiplication is appropriate here only when the independence assumption is justified.

Basic Level: Practice Exercises

Try each one on paper first. Use the hint if you get stuck, then check the full solution.

  1. Exercise 1. A bag has 2 red balls and 6 blue balls. What is the probability of drawing red?

  2. Exercise 2. A fair six-sided die has faces numbered 1 through 6. What is the probability of rolling more than 4?

  3. Exercise 3. The chance of rain is 0.35. What is the chance of no rain?

  4. Exercise 4. Find the mean of 4, 6, and 8.

  5. Exercise 5. Find the median of 9, 2, 4, and 7.

  6. Exercise 6. Find the mode and range of 2, 2, 3, 5, and 8.

  7. Exercise 7. For 1, 2, 2, 3, and 12, find the mean and median. Which is larger?

  8. Exercise 8. Independent events A and B have probabilities 0.4 and 0.5. What is the probability of both?

  9. Exercise 9. Independent events A and B have probabilities 0.4 and 0.5. What is the probability of at least one?

  10. Exercise 10. Each of three independent sensors misses an object with probability 0.2. What is the probability that at least one sensor detects it?

Hide Icons