Velamuvi AIAcademy
Probability

Lesson 1 of 16 · Chance

What Is Probability?

Probability from scratch: a number from 0 to 1 that measures how likely something is. Simulate coin flips in Python and see the law of large numbers.

  • 6 min read
  • Intermediate
  • Reviewed
In this lesson you will learn
  • Explain probability as a number between 0 and 1
  • Describe the frequency and the belief views of probability
  • Estimate a probability by simulation in Python
  • See how proportions settle down as you repeat an experiment
  • Explain why AI models produce probabilities

Measuring uncertainty

Will it rain tomorrow? Will this customer cancel? Is this email spam? We rarely know for sure, but we can say how likely something is. Probability is the mathematics of that “how likely”.

You'll often see probabilities written as percentages: 0.25 is 25%. Probabilities are usually written with a capital P, so P(rain) = 0.3 reads “the probability of rain is 0.3”.

0          0.25        0.5         0.75         1
|-----------|-----------|-----------|-----------|
impossible  unlikely    even        likely      certain

Two ways to think about probability

As a long-run frequency. “The probability a fair coin lands heads is 0.5” means: flip it many, many times and it lands heads about half the time.

As a degree of belief. “There's a 30% chance it rains tomorrow” can't mean “tomorrow happens many times”. It means: given what we know, we're 30% confident. Beliefs like this should change when new evidence arrives, which is exactly what Bayes' theorem (lesson 6) describes.

Both views use the same rules, so you rarely have to choose. Data scientists use whichever helps.

Seeing probability emerge

Simulation is a powerful way to understand probability: make the computer repeat an experiment thousands of times and count. Here's a fair coin, flipped 10,000 times:

Try it yourselfPython
import random

random.seed(4)                       # fixed seed: the same "random" results every time you run it
heads = 0
for flips in range(1, 10_001):
    heads += random.random() < 0.5  # a fair coin: heads half the time
    if flips in (10, 100, 1_000, 10_000):
        print(f"after {flips:>6} flips: {heads / flips:.3f} heads")

After 10 flips, 70% heads: far from 0.5. After 10,000 flips, 50.5%. The proportion wobbles a lot at first and settles near the true probability as the number of flips grows.

random.seed(4) makes the “random” numbers the same every time you run the code, so results can be repeated and checked. Change the seed and you'll get different wobbles, but the same settling.

Why AI is full of probabilities

Machine learning models rarely give one certain answer. They give probabilities:

  • A spam filter says “this email is spam with probability 0.97”.
  • A medical-image model says “0.12 chance of this condition”.
  • A language model gives every possible next word a probability and then picks one (see the Large Language Models course).
Try it yourselfPython
# A model's output is a probability distribution: one probability per possible answer
next_word = {"Lisbon": 0.71, "Porto": 0.18, "Madrid": 0.06, "Paris": 0.05}
print("Sum of probabilities:", round(sum(next_word.values()), 10))
best = max(next_word, key=next_word.get)
print(f"Most likely next word: {best} ({next_word[best]:.0%})")
print(f"Chance it's NOT {best}: {1 - next_word[best]:.0%}")

The probabilities of all possible answers add up to 1, because exactly one of them will happen. And the chance of “not Lisbon” is simply 1 minus the chance of Lisbon: the complement rule, which lesson 3 covers.

Common mistakes

Practice exercise

Estimate a probability by simulation: roll a virtual die many times and see how often a six comes up.

Your solutionPython
import random
random.seed(7)

# Simulate rolling a fair six-sided die 6,000 times with random.randint(1, 6).
# Count how many rolls are a 6, then print the proportion of sixes rounded to 3 decimals.
Knowledge check

A fair coin has landed heads 5 times in a row. What is the probability the next flip is heads?

Summary

  • Probability is a number from 0 (impossible) to 1 (certain).
  • It can mean a long-run frequency or a degree of belief; both follow the same rules.
  • Simulation estimates probabilities by repeating an experiment and counting.
  • The law of large numbers: proportions settle near the true probability as repetitions grow.
  • AI models output probability distributions whose values add up to 1.

Next: events and sample spaces.

Finished reading? Tick it off to track your progress.