MACHINE LEARNING • LESSON 8

Prediction Probabilities

A classification model can tell us which class it predicts, but it can also tell us how probable each class is.

THE SIMPLEST IDEA

A prediction tells us the class. A probability tells us how likely each class is.

For example, instead of only saying "Pass", a classifier can tell us: "Pass = 90%" and "Fail = 10%".

01

What Is a Prediction Probability?

In classification, the model can estimate the probability that an input belongs to each class.

Suppose our model predicts whether a student will Pass or Fail.

FAIL 10%
PASS 90%

The model is saying that, based on the information it has learned, Pass is more likely than Fail.

Probability gives us more information than the predicted class alone.
02

predict() vs predict_proba()

Scikit-learn provides two useful methods for classification.

predict() Gives the predicted class

Example: Pass

predict_proba() Gives the probability of each class

Example: [0.10, 0.90]

INPUT 6 Study Hours
MODEL Classifier
predict() Pass
+
predict_proba() 90% Pass
03

A Simple Example

Imagine our classifier receives a new student who studied for 6 hours.

NEW STUDENT Study Hours 6 hours
MODEL OUTPUT Pass 90% probability

The model might produce probabilities such as:

Fail 10%
Pass 90%

Because the probability for Pass is much higher, the classifier predicts Pass.

04

Getting Probabilities With Python

We can use predict_proba() to get the probabilities from a trained classifier.

probability = model.predict_proba([[6]])

print(probability)

The result may look similar to:

[[0.10 0.90]]

These two numbers represent the probability of each class.

CLASS 0 0.10 10% → Fail
CLASS 1 0.90 90% → Pass
The order of these probabilities follows the model's class order. You should check model.classes_ rather than blindly assuming which position means which class.
05

Understanding model.classes_

How do we know which probability belongs to which class?

Scikit-learn provides classes_ so we can see the order used by the model.

print(model.classes_)

For our example, the output may be:

[0 1]

We defined:

CLASS 0 Fail
CLASS 1 Pass

Therefore:

0.10 belongs to Class 0 → Fail
0.90 belongs to Class 1 → Pass
06

Why Are Probabilities Useful?

A class prediction alone can hide important information.

Compare these two predictions:

STUDENT A Pass 51% probability
STUDENT B Pass 98% probability

Both students are classified as Pass, but the model is much more confident about Student B.

The class tells us the decision. The probability helps us understand how strongly the model favors that class.
07

Probability Is Not the Same as Certainty

A probability from a Machine Learning model should not automatically be interpreted as absolute certainty.

If the model returns:

FAIL 35%
PASS 65%

The model predicts Pass because 65% is higher than 35%. But this is not a very strong separation.

In contrast:

FAIL 2%
PASS 98%

Here the model's probabilities are much more separated.

08

Prediction Probability and the Threshold

For binary classification, we often use a threshold such as 0.5 to convert probability into a class.

BELOW 0.5 Class 0

Example: 0.30 → Fail

0.5
0.5 OR HIGHER Class 1

Example: 0.80 → Pass

So if the model gives:

Pass probability = 0.80

and our threshold is 0.50:

0.80 >= 0.50

Prediction = Pass
The threshold converts a probability into a final class decision. It does not create the probability.
09

Complete Python Example

Now let's combine training, prediction, and probability into one small example.

from sklearn.linear_model import LogisticRegression

# Training data
X = [
    [1],
    [2],
    [3],
    [5],
    [6],
    [7]
]

# Labels
y = [
    0,
    0,
    0,
    1,
    1,
    1
]

# Create the model
model = LogisticRegression()

# Train the model
model.fit(X, y)

# New student
new_student = [[6]]

# Predict the class
prediction = model.predict(new_student)

# Get probabilities
probability = model.predict_proba(new_student)

print("Classes:", model.classes_)
print("Prediction:", prediction)
print("Probabilities:", probability)

The important part is understanding the three outputs:

classes_ [0, 1] Shows class order
predict() [1] Predicts Pass
predict_proba() [0.10, 0.90] 10% Fail / 90% Pass
10

A Real-World Example

Prediction probabilities become especially useful when the decision is important.

FRAUD DETECTION Transaction

Fraud probability: 92%

SPAM DETECTION Email

Spam probability: 97%

Instead of treating every prediction as simply Yes or No, probabilities can provide more information about the model's output.

REMEMBER THIS

Prediction probabilities show how the model distributes probability across the possible classes.

For a binary classifier, you can think of the process as:

New Data Classifier Probabilities Class Decision
QUICK CHECK

Check Your Understanding

What does predict() return? The predicted class.
What does predict_proba() return? The probability for each class.
What does [0.10, 0.90] mean? Assuming the class order is [0, 1], it means 10% for Class 0 and 90% for Class 1.
Why do we check classes_? To know which probability belongs to which class.
NEXT TOPIC

Understand the Python Code

Next, we will break the classifier code down line by line so you understand exactly what each part does.