Pattern Classification
STEP 1 · GOAL

Pattern Classification Fundamentals

In this codelab, we will understand how machines identify patterns, represent objects using features, and learn to classify data using supervised, unsupervised, and semi-supervised learning.

By the end: Explain pattern analysis, classification, feature vectors, discriminant functions, decision boundaries, and the difference between supervised, unsupervised, and semi-supervised learning.
Real-world object
↓
Data / Image
↓
Feature extraction
↓
Feature vector
↓
Pattern analysis
↓
Classification decision
Module 4.1

This lesson builds the foundation for later topics such as PCA, LDA, ICA, K-Means, K-Medoids, and Gaussian Mixture Models.

STEP 2 · CONCEPT

What is Pattern Analysis?

Pattern analysis means finding meaningful similarities, differences, and structures in data so that a machine can make decisions.

What is a pattern?

A pattern is a measurable representation of an object or event.

Object

A fruit, face, handwritten digit, pedestrian, vehicle, medical scan, or any other item we want to analyze.

Features

Measurable properties such as color, height, width, texture, shape, area, weight, or pixel intensity.

Example: Fruit recognition

Fruit Weight Redness Length
Apple 150 g 0.90 7 cm
Orange 180 g 0.40 8 cm
Banana 120 g 0.10 18 cm
Key idea

The computer does not understand “apple” directly. It works with numerical features that describe the apple.

STEP 3 · REPRESENTATION

Represent Objects as Feature Vectors

Machine-learning algorithms usually work with numbers, so we represent each object using a vector of features.

X = [150, 0.90, 7]

# 150  -> weight in grams
# 0.90 -> redness score
# 7    -> length in cm

This is called a feature vector.

Apple
↓ extract measurable properties
[weight, redness, length]
↓
[150, 0.90, 7]
REMEMBER

A feature vector is simply a list of numerical values used to describe one sample.

STEP 4 · CLASSIFY

What is Classification?

Classification assigns an input sample to one of several predefined categories.

Input image
↓
Feature extraction
↓
Classifier
↓
Cat / Dog / Bird

Example

Suppose we already know two possible classes:

Class 0

Cat

Class 1

Dog

The classifier receives a new input and decides which predefined class it belongs to.

Classification vs recognition

Recognition identifies what an object is. Classification is the decision process that assigns it to a known category.

STEP 5 · VISUALIZE

Understand Feature Space

When we use two features, every sample can be visualized as a point on a 2D graph.

Feature 1 = Height
Feature 2 = Weight

Each person → one point in 2D feature space
Weight ↑

80 |                    ●
75 |                 ●
70 |              ●
65 |
60 |       ○
55 |    ○
50 | ○
   +----------------------------→ Height

○ = Class A
● = Class B

The complete region containing all possible feature values is called the feature space.

Why this matters

Classification becomes the problem of deciding which region of the feature space a new point belongs to.

STEP 6 · DECISION

Discriminant Function

A discriminant function gives a score to each class. The class with the highest score is selected.

Two-class example

g_cat(x) = score for Cat
g_dog(x) = score for Dog

if g_dog(x) > g_cat(x):
    prediction = "Dog"
Cat score

0.35

Dog score

0.82

Since 0.82 > 0.35, the sample is classified as Dog.

Linear discriminant function

g(x) = wᵀx + b
Symbol Meaning
x Feature vector of the input sample.
w Weights that determine the importance of each feature.
b Bias term that shifts the decision boundary.
g(x) Discriminant score used for the decision.
STEP 7 · SEPARATE

Decision Boundary

A decision boundary separates regions belonging to different classes.

        DOGS

      ● ● ●
    ● ● ●

----------------------  ← Decision Boundary

   ○ ○ ○
 ○ ○

        CATS

A new point above the boundary may be classified as Dog, while a point below it may be classified as Cat.

Connection to discriminant functions

The decision boundary is often the location where two class scores become equal.

What does a decision boundary do?

STEP 8 · LABELED DATA

Supervised Learning

In supervised learning, every training sample is provided together with its correct answer or label.

Input Label
Cat image Cat
Dog image Dog
Cat image Cat
Dog image Dog
Labeled training data
↓
Learning algorithm
↓
Trained model
↓
New sample
↓
Predicted class

Common supervised tasks

  • Cat vs dog classification
  • Spam vs not spam
  • Pedestrian vs non-pedestrian
  • Normal vs abnormal medical image
Keyword

Supervised learning = labeled training data.

STEP 9 · PRACTICAL

A Tiny Supervised Classifier

Use K-Nearest Neighbors only as a simple demonstration of how labeled samples can classify a new point.

from sklearn.neighbors import KNeighborsClassifier

# Two features for each sample
X = [
    [1, 1],
    [1, 2],
    [2, 1],
    [8, 8],
    [8, 9],
    [9, 8]
]

# Correct labels
y = [
    "Class A",
    "Class A",
    "Class A",
    "Class B",
    "Class B",
    "Class B"
]

model = KNeighborsClassifier(n_neighbors=3)
model.fit(X, y)

prediction = model.predict([[2, 2]])
print(prediction)
X = training features
y = known labels
↓ model.fit(X, y)
model learns from labeled examples
↓ model.predict([[2, 2]])
↓ predicted class
NOTE

KNN itself will be discussed later under non-parametric methods. Here, it is only being used to demonstrate supervised learning.

STEP 10 · NO LABELS

Unsupervised Learning

In unsupervised learning, the algorithm receives data without correct labels and tries to discover structure by itself.

Unlabeled data
↓
Learning algorithm
↓
Discover similarities
↓
Groups / clusters / structure

Example

Input points:

● ● ●

            ● ●
          ●

     ● ●

No labels are provided.

The algorithm may discover:
Cluster 1
Cluster 2
Cluster 3
Important distinction

Classification usually uses known class labels. Clustering discovers groups when labels are not given.

Which type of data is used in unsupervised learning?

STEP 11 · MIX BOTH

Semi-Supervised Learning

Semi-supervised learning combines a small amount of labeled data with a much larger amount of unlabeled data.

Small labeled dataset ─┐
├→ Semi-supervised learning → Model
Large unlabeled dataset ┘

Why is it useful?

Collecting data can be easy, but labeling it can be expensive and time-consuming.

1,000 images

Manually labeled by experts.

50,000 images

Available but unlabeled.

A semi-supervised approach tries to learn from both.

Computer vision example

A hospital may have thousands of scans, but only a smaller subset has been carefully labeled by doctors.

STEP 12 · COMPARE

Supervised vs Unsupervised vs Semi-Supervised

These three terms mainly differ in how much labeled information is available during training.

Type Labels Main Goal Example
Supervised Yes Predict known classes Cat vs Dog
Unsupervised No Discover hidden structure Grouping similar pixels
Semi-Supervised Some Learn from labeled + unlabeled data Medical image classification
Easy memory trick
Supervised: teacher gives answers.
Unsupervised: no teacher, discover patterns.
Semi-supervised: teacher gives only some answers.
STEP 13 · CONNECT IT ALL

Pattern Classification Pipeline

Now connect all the concepts into one end-to-end flow.

1. Capture data / image
↓
2. Preprocess data
↓
3. Extract useful features
↓
4. Build a feature vector
↓
5. Feed it to a classifier
↓
6. Calculate class scores / discriminant functions
↓
7. Compare scores
↓
8. Cross a decision boundary
↓
9. Output predicted class
Example

An image of a pedestrian can be converted into features, passed to a trained model, scored against possible classes, and finally classified as “Pedestrian” or “Not Pedestrian”.

STEP 14 · REVISION

Pattern Classification Revision

Review the core definitions before moving to dimensionality reduction.

What is pattern analysis?
The process of identifying meaningful structures, similarities, and differences in data so that a machine can make decisions.
What is a feature?
A measurable property used to describe an object, such as color, texture, height, width, shape, or intensity.
What is a feature vector?
A numerical list containing the features of one sample.
What is classification?
The process of assigning a sample to one of several predefined classes.
What is a discriminant function?
A function that produces a score for a class. The score is used to decide which class the sample belongs to.
What is a decision boundary?
A boundary in feature space that separates regions assigned to different classes.
What is supervised learning?
Learning from labeled training examples.
What is unsupervised learning?
Learning structure or groups from unlabeled data.
What is semi-supervised learning?
Learning from a mixture of labeled and unlabeled data.

Completion checklist

  • I can explain pattern analysis.
  • I know what a feature and feature vector are.
  • I can explain classification.
  • I understand feature space.
  • I understand a discriminant function.
  • I understand a decision boundary.
  • I can distinguish supervised, unsupervised, and semi-supervised learning.
  • I understand how these ideas connect in a classification pipeline.

Practice

  1. Choose any real-world classification problem and list at least four useful features.
  2. Explain whether your problem should use supervised, unsupervised, or semi-supervised learning.
  3. Draw a simple 2D feature-space diagram containing two classes and a decision boundary.
  4. For a three-class problem, write three imaginary discriminant scores and decide the predicted class.

Module 4.1 complete! 🎉

You now have the foundation required for the next codelab: dimensionality reduction using PCA, LDA, and ICA.