AlgoDaily

Getting To Know Probability

Read at your own pace. Code execution, quizzes, progress tracking, and the AI tutor are available in the interactive view with JavaScript enabled.

Chance Joins Data

Welcome back, tiny data scientist!

In Introduction to Statistics - Using Bubbles, you learned that data can describe what happened. In Telling the Story with Data, you learned that data can help us explain what happened.

Now we meet probability: a friendly math tool for talking about what might happen next.

Think like this:

  • Statistics says: “I saw 10 bubbles, and 6 were big.”
  • Probability asks: “If I blow one more bubble, how likely is it to be big?”

Data science, AI, and machine learning use probability because computers often need to make smart guesses when they are not 100% sure.

Chance Joins Data

Probability Words

The chance vocabulary

Probability has a few important words. They are simple, but powerful.

Experiment

Something we try.

Example: flip a coin, roll a die, pick a candy from a bag.

Outcome

One thing that can happen.

Example: a coin can land on heads or tails.

Event

The outcome we care about.

Example: “I want heads” or “I want a red candy.”

Probability

A number that tells us how likely an event is.

Probability lives between:

0 = impossible
1 = certain

So probability is like a “chance meter.”

Probability Words

Pick The Event

A bag has red, blue, and yellow candies.

You close your eyes and pick one candy.

Which sentence describes an event?

Chance As Fraction

Counting chance

When all outcomes are equally fair, probability can be counted like this:

probability = wanted outcomes / total outcomes

You already practiced division in Understanding Multiplication and Division, so this is your division superpower returning!

Example:

A bag has 5 candies:

  • 2 red
  • 3 blue

If you want red:

wanted = 2
total = 5
probability of red = 2 / 5 = 0.4

That means red has a 0.4 chance, or 40% chance.

```python
red_candies = 2
total_candies = 5

probability_red = red_candies / total_candies
percent_red = probability_red * 100

print("Probability of red:", probability_red)
print("Percent chance of red:", percent_red, "%")
```

Certain Or Not

True or false?

A probability of 1 means the event is certain to happen.

The Chance Line

Reading probability numbers

Probability numbers feel small at first, but they tell a clear story.

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

Examples:

  • 0: impossible — a regular die rolls a 7
  • 0.5: equally likely — a fair coin lands heads
  • 1: certain — a number from 1 to 6 appears when rolling a regular die

In AI, a model might say:

“I am 0.82 sure this picture contains a cat.”

That does not mean magic. It means the model is using probability to show confidence.

The Chance Line

Try Many Times

Probability can be estimated

Sometimes we know the exact chance. A fair coin has 2 equal outcomes: heads or tails.

But sometimes the world is messy. Then we can try something many times and estimate the probability from data.

This is where probability connects back to statistics:

  • Probability asks: “What might happen?”
  • Data records: “What did happen?”
  • Statistics summarizes the recorded results.

Let’s simulate coin flips in Python. The more trials we run, the closer our estimate usually gets to the true chance.

```python
import random

flips = 1000
heads = 0

for _ in range(flips):
    coin = random.choice(["heads", "tails"])
    if coin == "heads":
        heads += 1

estimated_probability = heads / flips

print("Flips:", flips)
print("Heads:", heads)
print("Estimated probability of heads:", estimated_probability)
```

Coin Chance

A fair coin has two equally likely outcomes: heads and tails.

What is the probability of getting heads?

Write the answer as a decimal.

Fill in the blank: _____________

Learning From Data

Probability from past data

Imagine we watched 10 playground days.

On 3 days, it rained. On 7 days, it did not rain.

A simple data-based estimate is:

probability of rain = rainy days / total days

This does not promise rain tomorrow. It says, “Based on what we saw, rain happened 3 out of 10 times.”

This idea is important for machine learning. A model often learns from examples, then gives a probability-style guess for a new case.

```python
weather_days = ["sun", "rain", "sun", "sun", "rain", "sun", "sun", "rain", "sun", "sun"]

rainy_days = weather_days.count("rain")
total_days = len(weather_days)

probability_rain = rainy_days / total_days

print("Rainy days:", rainy_days)
print("Total days:", total_days)
print("Estimated probability of rain:", probability_rain)
```

Best Probability

A jar has 10 balls.

  • 7 are green
  • 3 are purple

You pick one ball without looking.

What is the probability of picking a purple ball?

Open interactive view →