MACHINE LEARNING • LESSON 8

Multi-Class Classification

Multi-Class Classification is a type of classification where a machine learning model chooses between more than two possible classes.

THE SIMPLEST DEFINITION

Multi-Class Classification means choosing one class from more than two possible classes.

The model learns patterns from labeled training data and then predicts which one of several possible categories a new input belongs to.

01

What Does "Multi-Class" Mean?

In Binary Classification, the model chooses between exactly two classes.

In Multi-Class Classification, there are more than two possible classes.

CLASS 1 Cat
CLASS 2 Dog
CLASS 3 Horse

The model must choose one class from these possible categories.

Multi-Class Classification = Classification with more than two possible classes.
02

Simple Example — Animal Classification

Imagine that we want to identify an animal from an image.

The model may have these possible classes:

CLASS Cat
CLASS Dog
CLASS Horse
CLASS Bird

Suppose we provide a new image to the model.

INPUT Animal Image
MODEL Classification
PREDICTION Dog
The model chooses one class from several possible classes.
03

How Does Multi-Class Classification Work?

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

TRAINING DATA Features + Known Classes
TRAINING Model learns patterns
NEW DATA Features
PREDICTION One of several classes

Unlike Binary Classification, the model has more than two possible answers.

04

Example — Fruit Classification

Suppose we want a model to identify different types of fruit.

Fruit Possible Class
Apple Apple
Orange Orange
Banana Banana
Mango Mango

Suppose the model receives information about a new fruit such as its weight, color, size, and shape.

FEATURES Weight, Color, Size
MODEL Classification
CLASS Mango

The model chooses one class from the available fruit categories.

05

Binary vs Multi-Class Classification

The easiest way to understand Multi-Class Classification is to compare it with Binary Classification.

BINARY CLASSIFICATION Exactly 2 classes

Example: Spam / Not Spam

MULTI-CLASS CLASSIFICATION More than 2 classes

Example: Cat / Dog / Horse / Bird

Binary = 2 classes. Multi-Class = more than 2 classes.
06

Example — Handwritten Digit Recognition

Another useful example is recognizing handwritten numbers.

Suppose a model needs to identify digits from 0 through 9.

0 1 2 3 4 5 6 7 8 9

There are ten possible classes.

INPUT Handwritten Image
MODEL Classification
PREDICTION 7
Because there are ten possible classes, this is a Multi-Class Classification problem.
07

The Model Chooses One Class

When a new input arrives, the model considers the possible classes and produces a prediction.

NEW INPUT Animal Image
Possible Classes
Cat Dog Horse Bird
FINAL CLASS Dog

The important idea is that the output is one of the available categories.

08

Simple Python Example

Here is a small example using scikit-learn. The model predicts one of three possible classes.

from sklearn.linear_model import LogisticRegression

X = [
    [1],
    [2],
    [3],
    [6],
    [7],
    [8],
    [11],
    [12],
    [13]
]

y = [
    "Small",
    "Small",
    "Small",
    "Medium",
    "Medium",
    "Medium",
    "Large",
    "Large",
    "Large"
]

model = LogisticRegression()

model.fit(X, y)

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

print(prediction)

In this example there are three possible classes:

Small
Medium
Large

When the model receives the new value 7, it predicts one of those classes.

The important part is not the algorithm yet. The important part is that the model chooses one class from more than two possible classes.
REMEMBER THIS

Multi-Class Classification means choosing one class from more than two possible classes.

The model learns patterns from labeled training data and then assigns new data to one of the available categories.

Features Classification Model One of Many Classes
QUICK CHECK

Check Your Understanding

What does Multi-Class mean? The problem has more than two possible classes.
Is Cat/Dog/Horse Multi-Class Classification? Yes. There are three possible classes.
Is Spam/Not Spam Multi-Class Classification? No. There are only two classes, so it is Binary Classification.
How many classes are in digit recognition from 0 to 9? Ten classes: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
NEXT TOPIC

Classification Examples

Next, we will look at practical examples of classification problems and understand where classification is used in the real world.