MACHINE LEARNING • LESSON 8

Binary Classification

Binary Classification is a type of classification where a machine learning model chooses between exactly two possible classes.

THE SIMPLEST DEFINITION

Binary Classification means choosing between two possible classes.

The model learns patterns from training examples and then predicts which of the two classes a new input belongs to.

01

What Does "Binary" Mean?

The word binary means there are exactly two possible choices.

CLASS 1 Pass
OR
CLASS 2 Fail

The model must choose one of these two classes when it receives new data.

Binary Classification = Classification with exactly two possible classes.
02

Simple Example — Pass or Fail

Suppose we want to predict whether a student will pass an exam based on how many hours they studied.

Study Hours Result
1 Fail
2 Fail
3 Fail
5 Pass
6 Pass
8 Pass

The model learns from these examples.

NEW STUDENT 6 Study Hours
MODEL Classification
PREDICTION Pass
The model predicts a category — Pass or Fail — rather than an exact exam score.
03

How Does Binary Classification Work?

The model first learns from training examples where the correct class is already known.

TRAINING DATA Features + Known Classes
TRAINING Model learns patterns
NEW DATA Features
PREDICTION Class 0 or Class 1

The important part is that the model has only two possible classes to choose from.

04

Example — Spam or Not Spam

Email spam detection is another common Binary Classification problem.

The model can look at information such as:

Number of links
Number of suspicious words
Email length
Sender information
INPUT Email Data
MODEL Classification
CLASS 1 Spam
OR
CLASS 2 Not Spam
Spam and Not Spam are two possible classes, so this is Binary Classification.
05

Binary Classification Can Use 0 and 1

Machine learning models often represent two classes using numerical labels such as 0 and 1.

CLASS 0 0

Fail

CLASS 1 1

Pass

The numbers are simply labels representing the categories.

0 and 1 are class labels. They do not automatically mean "bad" and "good".

Another problem could use the same idea differently:

CLASS 0 0

Not Spam

CLASS 1 1

Spam

06

Another Example — Fraud Detection

A bank may want to determine whether a transaction is fraudulent.

Transaction amount
Transaction location
Transaction time
Previous transaction history
INPUT Transaction Data
MODEL Classification
CLASS 1 Fraud
OR
CLASS 2 Not Fraud

Because there are exactly two possible outcomes, this is another Binary Classification problem.

07

Binary vs Multi-Class Classification

The difference is simply the number of possible classes.

BINARY CLASSIFICATION Exactly 2 classes

Example: Spam / Not Spam

MULTI-CLASS CLASSIFICATION More than 2 classes

Example: Cat / Dog / Horse

Binary = exactly 2 classes. Multi-Class = more than 2 classes.
08

Simple Python Example

Here is a simple example using scikit-learn. The student result is represented using two labels: 0 and 1.

from sklearn.linear_model import LogisticRegression

X = [[1], [2], [3], [5], [6], [8]]
y = [0, 0, 0, 1, 1, 1]

model = LogisticRegression()

model.fit(X, y)

prediction = model.predict([[6]])

print(prediction)

In this example:

X Study hours
y Class labels: 0 or 1
fit() Learns from the training data
predict() Predicts the class for new data
LABEL 0 Fail
LABEL 1 Pass

When the model predicts 1, we interpret that class as Pass.

Logistic Regression is the algorithm used in this example. We will study it separately.
REMEMBER THIS

Binary Classification means choosing between exactly two classes.

The model learns from labeled training examples and then predicts one of two possible categories for new data.

Features Classification Model Class 0 or Class 1
QUICK CHECK

Check Your Understanding

What does binary mean? There are exactly two possible classes.
Is Pass/Fail binary classification? Yes. There are two possible classes.
Is Cat/Dog/Horse binary classification? No. There are three classes, so it is multi-class classification.
Can classes use 0 and 1? Yes. They can be represented using numerical class labels.
NEXT TOPIC

Multi-Class Classification

Next, we will learn how classification works when there are more than two possible classes.