Understanding Unsupervised Learning Techniques
Understanding Unsupervised Learning Techniques
Unsupervised learning is a type of machine learning where the model learns patterns and structure
from data without using labeled outputs. Unlike supervised learning—where the algorithm is trained
using labeled input-output pairs—unsupervised learning only receives raw input data and tries to find
hidden relationships or groupings within it.
Key Idea
Anomalies or outliers
No "correct answers" are provided—so the algorithm self-learns from the inherent structure of the data.
Real-World Examples
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/63
Netflix / Spotify recommendations based on similarity patterns.
Customer segmentation for targeted marketing.
Advantages
Suppose a dataset contains customer purchase history but no labels like "type of customer."
A clustering algorithm (like K-Means) may form groups:
Summary
Unsupervised learning helps machines discover the hidden structure of unlabeled data.
It is essential for clustering, pattern mining, anomaly detection, and feature extraction
in modern AI systems.
If you'd like, I can also provide a numeric example with K-means clustering.
What is a Cluster?
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/63
Data points within the same group are highly similar to each other.
Similarity between data points is usually measured using a distance metric such as:
Euclidean distance
Manhattan distance
Cosine similarity
Example:
If we cluster customers based on shopping behavior:
→ K-Means Clustering
Starts with k random centroids and assigns data points to the nearest centroid.
Similar to K-means but uses actual data points (medoids) instead of centroids.
More robust against noise and outliers.
→ Agglomerative (Bottom-Up)
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/63
Each point begins as its own cluster.
→ Divisive (Top-Down)
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/63
✔ Fast for large datasets
✖ Accuracy depends on grid size
6️⃣ Fuzzy Clustering
Instead of placing a point in only one cluster, it allows soft assignment.
→ Fuzzy C-Means
Each data point has a degree of belonging to multiple clusters (0–1 membership score).
Conclusion
Clustering is a powerful unsupervised learning technique used to discover structure in unlabeled data.
The choice of clustering algorithm depends on factors such as dataset size, noise level, shape of
clusters, and whether soft or hard clustering is needed.
If you want, I can also provide a numerical example of K-Means clustering or a visual explanation.
I’ll break it into two parts: K-Means first, then Kernel K-Means, and then a short comparison.
1. K-Means Clustering
1.1 Idea
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 5/63
Divides the data into K clusters.
Represents each cluster by its centroid (mean of points in that cluster).
Tries to minimize the within-cluster variance (sum of squared distances from points to their
cluster centroid).
It works best when clusters are roughly spherical and separated in Euclidean space.
1.2 Notation
Data points: x1 , x2 , … , xn
∈ Rd
Number of clusters: K
Centroid of cluster j : μj ∈ Rd
i=1
K
J = ∑ ∑ ∥ xi − μ j ∥
2
j=1 xi ∈Cj
The centroids μj
that minimize J .
Steps:
1. Initialization
Choose K initial centroids μ1 , … , μK .
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 6/63
Better: K-Means++ (chooses spread-out initial centers).
2. Assignment Step (E-step-like)
j∈{1,…,K}
For each cluster j , recompute the centroid as the mean of its assigned points:
1
μj = ∑ xi
∣Cj ∣
xi ∈Cj
Update step gives the best centroid (mean) for the fixed assignments (because mean minimizes
sum of squared distances).
1.6 Properties
n: number of points
d: dimension
K : clusters
T : iterations
Hard clustering: each point belongs to exactly one cluster.
1.7 Advantages
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 7/63
Fast and scalable for large n and moderate K .
similar size,
1.8 Limitations
Must pre-specify K.
Sensitive to:
Initialization → can get bad local minima.
Concentric circles
“Moon-shaped” clusters
Idea:
Map data to a higher-dimensional feature space where clusters become linearly separable /
spherical and run K-Means there.
Directly mapping via ϕ(x) can be very high-dimensional or infinite-dimensional. So we use the kernel
trick.
ϕ : Rd → F
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 8/63
Feature-space centroid for cluster j :
1
mj = ∑ ϕ(xi )
∣Cj ∣
xi ∈Cj
K
Jkernel = ∑ ∑ ∥ϕ(xi ) − mj ∥
2
j=1 xi ∈Cj
Typical kernels:
Polynomial kernel
Sigmoid kernel, etc.
∥ϕ(xi ) − mj ∥2
Expand:
2
∥ϕ(xi ) − mj ∥ = ⟨ϕ(xi ) − mj , ϕ(xi ) − mj ⟩
1. Self-similarity:
xp ∈Cj xp ∈Cj
3. Centroid self-term:
⟨mj , mj ⟩ = ⟨ ∑ ϕ(xq )⟩ =
1 1 1
∑ ϕ(xp ), ∑ ∑ K(xp , xq )
∣Cj ∣ ∣Cj ∣ ∣Cj ∣2
So:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 9/63
2 1
∑ K(xi , xp ) + ∑ ∑ K(xp , xq )
2
∥ϕ(xi ) − mj ∥ = K(xi , xi ) −
∣Cj ∣ ∣Cj ∣2
This expression requires only kernel values K(⋅, ⋅), not explicit ϕ(x).
Input:
Data {xi }n
i=1
Number of clusters K
Pre-compute:
Steps:
1. Initialization
2. Assignment Step
Dij = ∥ϕ(xi ) − mj ∥2
3. Update Step
Based on the new assignments, recompute the sets Cj and their statistics (e.g., sums over
You don’t form mj explicitly, but you update the cluster composition so that the formulas for
Repeat steps 2–3 until cluster assignments stop changing or a max iteration limit is reached.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 10/63
Needs computing and storing the kernel matrix: O(n2 ) memory.
Sensitive to choice of kernel type and kernel parameters (e.g., RBF γ , polynomial degree).
Space used Original data space Implicit high-dimensional feature space via ϕ(x)
Short Intuition
K-Means: “Draw K balls (spheres) in the original space and adjust them to best cover the data.”
Kernel K-Means: “First (implicitly) bend and twist the space using a kernel so that complicated
shapes become blob-like, then run K-Means in that transformed world.”
If you want, I can next give you a small numerical example showing how K-Means works step-by-step,
and then conceptually show how the same data can be separated with Kernel K-Means using an RBF
kernel.
1. K-Medoid Clustering
1.1 What is a Medoid?
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 11/63
Formally, in a cluster C , the medoid m is the point that minimizes the total dissimilarity to all
other points in the cluster:
xj ∈C
xi ∈C
K-Medoids: cluster center is an actual data point, so it is more robust to outliers and works with
any distance metric, not just Euclidean.
Given:
Data points x1 , x2 , … , xn
Number of clusters K
n
J = ∑ d(xi , mc(i) )
i=1
Steps:
1. Initialization
2. Assignment Step
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 12/63
Assign each point to the nearest medoid (smallest distance).
3. Update (Swap) Step
For each medoid m and for each non-medoid point x,
try swapping: make x a medoid and m a normal point.
Compute the total cost (sum of distances to nearest medoid) after the swap.
If the swap reduces the total cost, keep it.
Advantages:
More robust to outliers than K-Means (because medoids are real points).
Works with any distance metric: Euclidean, Manhattan, edit distance, etc.
Good for clustering non-numeric or categorical data (where a mean is not meaningful).
Disadvantages:
Classic PAM has higher computational cost than K-Means (because of many swap evaluations).
Still needs K to be specified.
Can be slow on very large datasets (but there are faster variants like CLARA, CLARANS).
2.1 Intuition
DBSCAN forms clusters as areas of high point density separated by areas of low density.
It’s great for:
Given:
For a point p:
1. ε-neighborhood of p:
Nε (p) = {q ∣ d(p, q) ≤ ε}
2. Core Point:
A point p is a core point if:
3. Border Point:
6. Density-Reachable:
p = p1 , p2 , … , pk = q
Two points p and q are density-connected if there exists a point o such that:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 14/63
2.3 Algorithm Steps of DBSCAN
If p is UNVISITED:
Mark p as VISITED.
If q is UNVISITED:
Mark q as VISITED.
Compute Nε (q).
If ∣Nε (q)∣
≥ minPts (i.e., q is core):
Add all points of Nε (q) to Seeds (if not already in cluster).
2.4 Characteristics
No need for K: DBSCAN automatically determines the number of clusters based on density.
Can find arbitrary shapes: e.g., crescent-moon, rings, nested shapes, etc.
Time complexity:
With spatial indexing (k-d trees, R-trees, etc.): can be closer to O(n log n).
ε (eps):
Use a k-distance plot:
For each point, compute distance to its k-th nearest neighbor (k = minPts − 1).
(You don’t need to calculate this in exam answers, but explaining this process shows understanding.)
1. Parameter sensitivity:
Choosing ε and minPts is non-trivial, especially for high-dimensional data.
2. Varying density problem:
If clusters have very different densities, a single ε and minPts may not work for all.
3. High-dimensional data:
Outliers handling Robust but still assigns each point to a cluster Explicitly marks some points as noise
Distance metric Any dissimilarity measure Any distance, but sensitive to choice
Parameters K (number of medoids) ε (radius), minPts
If you want, I can next give you a small conceptual example showing:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 16/63
how DBSCAN forms clusters around dense regions and marks some points as noise,
or a comparison example where K-Medoids fails on non-spherical shapes but DBSCAN succeeds.
Dimensionality reduction is about taking data with many features (high-dimensional) and
representing it with fewer, more informative features—without losing too much important
information. In unsupervised learning, this is done without class labels; the algorithm relies only on
the structure of the input data.
xi ∈ R D
with large D (e.g., 100, 1000, or more). High dimensionality causes several problems:
1. Curse of dimensionality
Distance measures become less meaningful as dimensions grow.
4. Visualization
We can’t visualize data directly in more than 3D.
Dimensionality reduction lets us get 2D/3D embeddings for visualization.
xi ∈ R D → z i ∈ R d ,
d≪D
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 17/63
Variance-based selection (drop low-variance features).
Correlation-based selection (remove highly correlated/duplicate features).
Most exam discussions of dimensionality reduction focus on feature extraction, especially PCA.
The second principal component (PC2) captures the maximum remaining variance, subject to
being orthogonal to PC1.
And so on.
x1 , x2 , ..., xn ∈ RD
− x⊤
1 −
− x⊤
2 −
X= of size n × D
⋮
− x⊤
n
−
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 18/63
n
1
μ = ∑ xi
n
i=1
Center each point:
~ =x −μ
x
i i
~
Let X be the matrix of centered data.
2. Compute covariance matrix
1 ~⊤ ~
Σ= X X (D × D)
n
3. Eigen-decomposition
Find eigenvalues λ1 ≥ λ2 ≥ ⋯ ≥ λD and corresponding eigenvectors v1 , v2 , … , vD such
that:
Σvj = λj vj
W = [v1 , v2 , ..., vd ] (D × d)
~ i ∈ Rd
zi = W ⊤ x
Similar to PCA but assumes a probabilistic model where observed variables are generated from a
few latent factors + noise.
Focuses more on explaining covariance structure than just variance.
Tries to find components that are statistically independent, not just uncorrelated.
Used in signal separation (e.g., separating voices in an audio mixture).
(These may or may not be in your syllabus, but good to name them.)
High-dimensional data (like images, text embeddings, etc.) often live on a low-dimensional curved
surface (manifold) inside the high-dimensional space.
Goal: Uncover this manifold and represent data using a few coordinates.
Common nonlinear DR methods:
For each pair of points in high-dimensional space, define a probability that they are neighbors
(using Gaussian distributions).
Find low-dimensional points such that their pairwise neighbor probabilities match, using a Student
t-distribution in low-dimensional space.
Optimizes a Kullback–Leibler divergence between high- and low-dimensional distributions.
Characteristics:
Not ideal as a general-purpose feature extractor for other algorithms (more for visualization).
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 20/63
Idea:
Approximate geodesic distances (distances along the manifold) between all pairs of points using
shortest paths on this graph.
Apply classical MDS (multidimensional scaling) to these geodesic distances to get low-
dimensional coordinates.
Good for:
Manifolds where geodesic distances capture the true structure (e.g., Swiss-roll dataset).
Idea:
3. In low-dimensional space, find points that preserve these reconstruction weights as much as
possible.
Encoder:
x → z (maps input to low-dimensional latent code).
Decoder:
z→x ^ (reconstructs input from latent code).
L = ∑ ∥xi − x
^ i ∥2
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 21/63
If the latent layer z has dimension d ≪ D, the encoder learns a compressed representation →
unsupervised dimensionality reduction.
Variants:
Apply PCA or another method first → then run K-Means / DBSCAN on reduced data.
Helps remove noise and redundant features.
2. Visualization
Use PCA / t-SNE / UMAP to plot data in 2D/3D and inspect natural groupings.
3. Noise filtering
Drop low-variance principal components in PCA to remove noise.
4. Feature learning
Autoencoders / deep representation learning discover compact, meaningful latent features.
Limitations
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 22/63
If you’d like, next I can:
what PCA is
its intuition
the step-by-step algorithm
1. What is PCA?
Principal Component Analysis (PCA) is a linear dimensionality reduction technique.
It:
So PCA transforms:
x ∈ RD ⟶ z ∈ Rd , d ≪ D
Intuition: PCA finds the directions in which the data “spreads out” the most and uses those as
new axes.
2. Mathematical Intuition
2.1 Data Setup
D
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 23/63
x1 , x2 , … , xn ∈ R D
− x⊤
1 −
− x⊤
2 −
X= (n × D)
⋮
− x⊤
n −
We want a direction (unit vector) w ∈ RD such that the variance of the data projected on w is
maximum.
Projection of point xi on w is:
z i = w ⊤ xi
Var(z) = w⊤ Σw
Similarly, PC2 is the eigenvector with second largest eigenvalue, orthogonal to PC1, and so on.
So PCA = eigen-decomposition of the covariance matrix.
Write the data as an n × D matrix X (each row = one sample, each column = one feature).
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 24/63
n
1
μ = ∑ xi (μ ∈ RD )
n
i=1
~
Let X be the matrix of centered data.
1 ~⊤ ~
Σ= X X
(D × D)
n
Element Σjk is the covariance between feature j and feature k .
Σvj = λj vj
You get:
Eigenvalues: λ1
≥ λ2 ≥ ⋯ ≥ λD
Eigenvectors: v1 , v2 , … , vD
Common ways:
W = [v1 v2 … vd ] (D × d)
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 25/63
Project each centered data point:
~i
zi = W ⊤ x ∈ Rd
Matrix form:
~
Z = XW (n × d)
x1 = (2, 0),
x2 = (0, 2),
x3 = (3, 1),
x4 = (1, 3)
2 0
0 2
X=
3 1
1 3
Feature-wise mean:
1 1
μ= [(2 + 0 + 3 + 1), (0 + 2 + 1 + 3)] = [6, 6] = (1.5, 1.5)
4 4
~
Centered data matrix X :
0.5 −1.5
~ −1.5 0.5
X=
1.5 −0.5
−0.5 1.5
1.25 −0.75
Σ=[ ]
−0.75 1.25
Solve:
Σv = λv
λ1 = 2.0
λ2 = 0.5
For λ1
= 2.0:
1
v1 = (1, −1)⊤ ≈ (0.707, −0.707)
2
For λ2 = 0.5:
1
v2 = (1, 1)⊤ ≈ (0.707, 0.707)
2
So:
We want to reduce to 1D, so we keep only PC1 (the eigenvector with largest eigenvalue).
Projection matrix:
0.707
W = v1 = [ ]
−0.707
~
zi = W ⊤ x
i
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 27/63
Example for x1 :
0.5
z1 = [0.707 −0.707] [ ] = 0.707(0.5) + (−0.707)(−1.5) ≈ 0.3535 + 1.0607 ≈ 1.414
−1.5
z1 ≈ 1.414,
z2 ≈ −1.414,
z3 ≈ 1.414,
z4 ≈ −1.414
x1 , x3 → positive side,
x2 , x4 → negative side.
We have compressed from 2D to 1D, keeping the direction that captures maximum variance (2.0 vs
0.5).
5. Summary (Exam-Friendly)
PCA is an unsupervised linear dimensionality reduction method.
It finds principal components (eigenvectors of covariance matrix) along which data variance is
maximized.
Steps:
Used for:
Dimensionality reduction,
Noise reduction,
Visualization,
Preprocessing before clustering or other ML algorithms.
If you want, I can next show how PCA + K-Means can be combined on a dataset, or give you a short
bullet-note version suitable for writing directly in exams.
Kernel PCA = PCA performed in a high-dimensional feature space using the kernel trick
(without explicitly computing that space).
1 T
Σ= X X
N
Kernel PCA works differently:
1. Feature Mapping
ϕ : Rd → Rm (m ≫ d)
2. Kernel Trick
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 29/63
Kernel Formula Use Case
3. Kernel Matrix
Kij = K(xi , xj ) (N × N )
1
(where 1N = N
11T ).
4. Eigenvalue Decomposition
N
zk (x) = ∑ vi K(x, xi )
(k)
i=1
These points cannot be separated linearly (standard PCA would give nearly zero useful direction).
∥xi −xj ∥2
−
K(xi , xj ) = e
2σ 2
Assume σ = 1.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 30/63
Compute pairwise distances and kernel values.
Example pairs:
(1 − 0)2 + (0 − 1)2 = 2
Kernel value:
2
e− 2 = e−1 ≈ 0.3679
−4
0.3679 e 0.3679 1
λ1 = 1.9
λ2 = 1.8
λ3 = 0.01
λ4 = 0.001
zk (xi ) = ∑ vj K (xi , xj )
(k)
Face recognition
Bioinformatics (gene data)
Nonlinear clustering preprocessing
Anomaly detection
Summary (Exam-Ready)
Kernel PCA is a nonlinear dimensionality reduction technique that uses kernel functions to
compute principal components in a high-dimensional feature space without computing the
mapping explicitly. It overcomes the limitations of standard PCA by capturing nonlinear
structures in data using the kernel trick.
Discuss in detail about Matrix Factorization in Unsupervised Learning . Explain the mathematical
preliminaries with examples
Matrix factorization in unsupervised learning is basically about breaking a big data matrix into the
product of two (or more) smaller matrices so that:
Dimensionality reduction
Topic modeling
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 32/63
Recommendation systems
Representation learning (latent factors)
1. Basic Setup
Suppose you have a data matrix:
X ∈ Rm×n
X ≈ WH
where:
W ∈ Rm×k
H ∈ Rk×n
k is much smaller than m, n → low-rank approximation
Interpretation:
Each row of W = low-dimensional representation / latent vector of a data point (like hidden
factors).
Each column of H = how each original feature is built from latent factors.
2. Mathematical Preliminaries
2.1 Rank and Low-Rank Approximation
The rank of a matrix X is the dimension of the space spanned by its rows or columns.
X ≈ WH
min ∥X − W H∥2F
W ,H
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 33/63
where ∥ ⋅ ∥F is the Frobenius norm (like Euclidean norm for matrices):
∥X∥2F = ∑ x2ij
i,j
X = U ΣV ⊤
where:
U ∈ Rm×m is orthogonal (U ⊤ U = I ),
V ∈ Rn×n is orthogonal,
Σ is diagonal (m × n) with non-negative singular values σ1 ≥ σ2 ≥ ⋯ ≥ 0.
Low-rank approximation:
If we keep only the top k singular values:
X ≈ Uk Σk Vk⊤
Here:
Uk = first k columns of U ,
Vk = first k columns of V ,
We can interpret:
1/2
W = U k Σk
1/2
H = Σk Vk⊤
so that:
X ≈ WH
Used for:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 34/63
Objective:
min ∥X − M ∥2F
rank(M )≤k
X ≈ W H, with W ≥ 0, H ≥ 0 (elementwise)
Objective:
min ∥X − W H∥2F
W ≥0,H≥0
We approximate:
R ≈ UV ⊤
where:
Predicted rating:
^ ui = u⊤ vi
R u
min ∑ (Rui − u⊤ 2 2 2
u vi ) + λ (∥U ∥F + ∥V ∥F )
U ,V
(u,i)∈Ω
This is also unsupervised w.r.t external labels (we only have interactions).
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 35/63
4. Detailed Example – Small NMF / Low-Rank Factorization
Let’s take a simple document–word matrix as an example.
Suppose we have 3 documents and 4 words:
Words:
w1 = “apple”
w2 = “banana”
w3 = “football”
w4
= “cricket”
3 2 0 0
X= 4 3 0 0
0 0 5 4
We can see:
X ≈ WH
with:
1 0
3 2 0 0
W ≈ 1.2 0 , H≈[ ]
0 0 3 2.5
0 1.5
Then:
1 0 3 2 0 0
3 2 0 0
W H ≈ 1.2 0 [ ] = 3.6 2.4 0 0
0 0 3 2.5
Compare with X :
3 2 0 0
X= 4 3 0 0
0 0 5 4
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 36/63
The approximation is close:
This illustrates how matrix factorization can discover hidden structure (topics) without labels.
5. Optimization Perspective
General form in unsupervised matrix factorization:
W ,H
W ⊤X
H←H⊙
W ⊤W H
XH ⊤
W ←W ⊙
W HH ⊤
Compress high-dimensional data into k -dimensional codes (rows of W ), similar to PCA but
often more interpretable (NMF).
2. Clustering
The low-dimensional representation can be sent to a clustering algorithm.
Sometimes, rows of W can directly indicate cluster membership (e.g., one factor dominates per
row).
3. Topic Modeling
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 37/63
Documents vs words → topics discovered as latent factors.
4. Recommendation Systems
Users and items represented via latent factors; predictions made in latent space.
5. Noise Reduction
Low-rank approximation filters out small singular values (noise directions).
Example: Document–word matrix factorization reveals topics (“fruits”, “sports”) as latent factors.
Use cases: Dimensionality reduction, topic modeling, recommender systems, clustering, noise
reduction.
If you want, I can next compare PCA vs NMF vs SVD directly, or give you a short handwritten-style
version suitable to write in an exam.
Singular Value Decomposition (SVD) is a method of decomposing a matrix into three special matrices
that reveal important structural properties of the original matrix. For any real matrix A of size m × n,
SVD expresses it as:
A = U ΣV T
Where:
Am×n
Step 1: Compute AT A
AT A
∣AT A − λI∣ = 0
λ1 ≥ λ2 ≥ ⋯ ≥ λr > 0,
(where r = rank of A)
Normalize eigenvectors of AT A.
∣ ∣ ∣
V = v1
v2
⋯ vn
∣ ∣ ∣
σi = λi
σ1 0 ⋯ 0
0 σ2 ⋯ 0
Σ=
⋮ ⋮ ⋱ ⋮
0 0 ⋯ σr
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 39/63
Step 5: Compute Matrix U
1
ui =
Avi
for i = 1, 2, … , r
σi
∣ ∣ ∣
U = u1 u2 ⋯ um
∣ ∣ ∣
Ensure:
UT U = I and V T V = I
Finally:
A = U ΣV T
3 1
A=[ ]
1 3
Step 1: Compute AT A
3 1 3 1 10 6
AT A = [ ][ ]=[ ]
1 3 1 3 6 10
Solve:
10 − λ 6
=0
6 10 − λ
(10 − λ)2 − 36 = 0
λ1 = 16, λ2 = 4
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 40/63
Step 3: Find Singular Values
σ1 = 16 = 4,
σ2 = 4=2
So:
4 0
Σ=[ ]
0 2
For λ1
= 16:
Eigenvector:
1 1
v1 = [ ]
2 1
For λ2 = 4:
(10 − 4)x + 6y = 0 ⇒ 6x + 6y = 0 ⇒ x = −y
Eigenvector:
1 1
v2 = [ ]
2 −1
So:
1 1 1
V = [ ]
2 1 −1
Step 5: Compute U
1
ui = Avi
σi
For u1 :
1 1 1 1 1 4 1 1
u1 = ⋅A [ ]= ⋅ [ ]= [ ]
4 2 1 4 2 4 2 1
Similarly:
1 1 1 1 2 1 1
u2 = A [ ]= [ ]= [ ]
2 2 −1 2 2 −2 2 −1
Thus:
[ to PDF]API.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML 41/63
1 1 1
U= [ ]
2 1 −1
Final SVD of A
1 1 1 4 0 1 1 1
A = U ΣV T = [ ][ ] [ ]
2 1 −1 0 2 2 1 −1
Final decomposition:
A = U ΣV T
If you'd like, I can also give a short flowchart or handwritten-style notes version for quick
memorization.
Explain in detail about Non-negative Matrix Factorization (NMF) with mathematical preliminaries .
Give an example
Non-negative Matrix Factorization (NMF) is a matrix factorization technique where all values are
constrained to be non-negative. This makes the learned components easy to interpret as “parts” or
“additive combinations” (e.g., topics in documents, parts of faces, etc.).
I’ll cover:
2. Mathematical formulation
3. Optimization & multiplicative update rules
4. Geometric / intuitive interpretation
5. A worked example with interpretation
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 42/63
X ∈ Rm×n
≥0
X ≈ WH
where:
W ∈ Rm×k
≥0 (non-negative)
H ∈ Rk×n
≥0 (non-negative)
Interpretation:
Each row of W : how strongly that data point uses each latent factor.
Each column of H : how each original feature is composed from the latent factors.
This is different from PCA/SVD where components can have positive and negative values.
2. Mathematical Formulation
2.1 Objective (Euclidean/Frobenius norm)
1
min J(W , H) = ∥X − W H∥2F
2
W ≥0, H≥0
i=1 j=1
subject to:
Wik ≥ 0,
Hkj ≥ 0 ∀i, k, j
(W H)ij
i,j
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 43/63
min DKL (X∥W H)
W ≥0, H≥0
Always keep W , H ≥0
Guarantee non-increase of the objective (monotonic descent)
Objective:
1
J(W , H) = ∥X − W H∥2F
2
(W ⊤ X)kj
Hkj ← Hkj ⋅
(W ⊤ W H)kj
(XH ⊤ )ik
Wik ← Wik ⋅
(W HH ⊤ )ik
Numerator and denominator are non-negative (products and sums of non-negative terms).
So the ratio is non-negative.
Multiplying a non-negative value by a non-negative ratio gives a non-negative result.
For
DKL (X∥W H)
updates become:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 44/63
x
∑i Wik (W H)
ij
Hkj ← Hkj ⋅
ij
∑i Wik
∑j Hkj (WxH)
ij
Wik ← Wik ⋅
ij
∑j Hkj
(You usually don’t need exact formula in exams unless explicitly in syllabus; knowing there are different
updates for different losses is enough.)
1. Choose rank k .
xj ≈ W hj
Each data point is an additive combination of basis vectors, with non-negative weights given by
hj .
This leads to parts-based representation (e.g., face = nose + eyes + mouth + …).
Words:
w1 = apple
w2 = banana
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 45/63
w3 = football
w4 = cricket
3 2 0 0
X= 4 3 0 0
0 0 5 4
Interpretation:
X ≈ WH
with:
W ∈ R3×2
≥0 (document–topic matrix)
H ∈ R2×4
≥0 (topic–word matrix)
1 0
3 2 0 0
W ≈ 1.2 0 , H≈[ ]
0 0 3 2.5
0 1.5
1 0 3 2 0 0
3 2 0 0
W H = 1.2 0 [ ] = 3.6 2.4 0 0 ≈X
0 0 3 2.5
Doc 1: [3, 2, 0, 0]
Doc 2: [3.6, 2.4, 0, 0] (approx [4, 3, 0, 0])
Doc 3: [0, 0, 4.5, 3.75] (approx [0, 0, 5, 4])
3 2 0 0
H=[ ]
0 0 3 2.5
Topic 1 (row 1): high weights on apple (3), banana (2) → Fruit topic
Topic 2 (row 2): high weights on football (3), cricket (2.5) → Sports topic
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 46/63
5.2 Interpretation of W (document mixtures)
1 0
W = 1.2 0
0 1.5
So NMF automatically discovered topics and how each document is a mixture of them, using only the
non-negative structure of X , no labels.
min ∥X − W H∥2F
W ,H≥0
or minimize KL divergence.
Update rules (Euclidean loss):
W ⊤X XH ⊤
H←H⊙ , W ←W ⊙
W ⊤W H W HH ⊤
(elementwise operations).
Interpretation:
Columns of W : basis vectors (parts, topics, components).
If you want, I can next give you a short one-page note version of NMF (only key formulas + bullet
points) that you can directly write in an exam.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 47/63
Matrix completion is an unsupervised learning technique used to recover missing entries in a partially
observed matrix by assuming that the full matrix has some underlying low-rank structure. It is widely
used in systems where only a few observations are available—such as recommendation systems, sensor
networks, bioinformatics, and image reconstruction.
User / Movie M1 M2 M3 M4
U1 5 ? 3 ?
U2 ? 4 ? 2
U3 1 ? 2 3
Even though the matrix looks incomplete, there is an underlying pattern, and the true matrix
can be approximated by a low-rank matrix.
M ∈ Rm×n
P Ω (M )
where:
(PΩ (M ))ij = {
Mij , (i, j) ∈ Ω
0, otherwise
PΩ (X) = PΩ (M )
3. Optimization Formulation
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 48/63
We want to minimize rank:
min ∥X∥∗
subject to PΩ (X) = PΩ (M )
where:
min(m,n)
∥X∥∗ = ∑ σi
i=1
X = UV T
where:
U ∈ Rm×k
V ∈ Rn×k
k ≪ min(m, n)
Then solve:
U ,V
(i,j)∈Ω
This approach is widely used in recommender systems like Netflix and Amazon.
5. Worked Example
Suppose we have a partially filled matrix:
5 ? 3
M= 4 2 ?
? 3 4
M ≈ UV T
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 49/63
Let:
u1 v1
U = u2 ,
V = v2
u3 v3
U ,V
5 2.5 3
X= 4 2 3.2
3.5 3 4
Then:
These predictions match patterns in known data because the model learned:
User 1 and User 2 share similar taste (high ratings on items 1 and 3),
Item 2 is moderately rated across users,
User 3 prefers item 4.
7. Key Advantages
✔ Handles missing data naturally
✔ Identifies hidden structure using latent factors
✔ Works well when the matrix is large but low rank
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 50/63
8. Limitations
✖ Requires enough observed entries to detect structure
✖ Assumes low-rank structure (not always true)
✖ Optimization may be costly for very large matrices
Summary (Exam-Ready)
If you'd like, I can also provide a short handwritten-style summary or comparison between matrix
completion and matrix factorization.
Discuss in detail about Generative Models (mixture models and latent factor models) in
unsupervised learning
Generative models in unsupervised learning are all about learning how the data was “generated” –
i.e., learning the full probability distribution of the data, not just boundaries or clusters.
You asked specifically about:
Mixture models
Latent factor models
x1 , x2 , … , xn ∈ R d
No labels.
A generative model tries to model the data-generating process by specifying a probabilistic model:
where:
x = observed data
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 51/63
z = hidden / latent variables (cluster labels, factors, etc.)
θ = model parameters
We then:
2. Latent factor models → think “data is generated from a few hidden continuous factors”.
2. Mixture Models
2.1 Basic Idea
A mixture model assumes that each data point x comes from one of several components, but we do
not know which one.
Example intuition:
Formally, suppose we have K components, with a hidden variable z ∈ {1, … , K} indicating which
component generated x.
K
p(z = k) = πk , with πk ≥ 0, ∑ πk = 1
k=1
Component likelihood:
p(x ∣ z = k; θk )
K
p(x) = ∑ πk p(x ∣ z = k; θk )
k=1
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 52/63
1. Choose a component z according to {πk }.
p(x ∣ z = k) = N (x ∣ μk , Σk )
K
p(x) = ∑ πk N (x ∣ μk , Σk )
k=1
Parameters:
πk (mixing weights)
μk (means)
Σk (covariances)
Joint probability:
zi
πk p(xi ∣ zi = k)
γik = p(zi = k ∣ xi ) =
K
∑j=1 πj p(xi ∣ zi =
j)
So each point belongs to each cluster with a probability, not a hard label.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 53/63
2.4 Learning with EM (Expectation–Maximization)
i=1
log ∑ πk p(xi ∣ zi = k)
which is messy.
Use EM algorithm:
E-step: (Expectation)
M-step: (Maximization)
n
i=1
n
∑ γik xi
μnew = i=1
k n
∑i=1 γik
n
∑i=1 γik (xi − μnew new ⊤
k )(xi − μk )
Σnew =
k n
∑i=1 γik
GMM will:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 54/63
This is unsupervised, but we often interpret components as hidden groups (e.g., male/female).
Each high-dimensional data point x is generated from a few continuous hidden factors h ∈
R , where k ≪ d.
k
Let:
Generative model:
x ∼ p(x ∣ h; θ)
Then marginal:
Factor Analysis
Probabilistic PCA
Assume:
x = μ + Wh + ϵ
where:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 55/63
h ∼ N (0, Ik ) (latent factors)
Then:
p(x ∣ h) = N (x ∣ μ + Wh, Ψ)
p(x) = N (x ∣ μ, W W ⊤ + Ψ)
Interpretation:
Ψ = σ 2 I (isotropic noise)
Same form: x = μ + Wh + ϵ
Then:
p(x) = N (x ∣ μ, W W ⊤ + σ 2 I)
It can be shown that the maximum likelihood solution for the subspace spanned by columns of W
corresponds exactly to the principal components found by PCA.
So PCA is essentially a latent factor model with:
Linear mapping W ,
In collaborative filtering (recommendation systems), data is a user–item matrix R with missing entries. A
common model:
Rui ≈ u⊤
u vi
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 56/63
uu : latent factor vector for user u
Generative story:
Rui ∼ N (u⊤
2
u vi , σ )
x1 : Math
x2 : Physics
x3 : Chemistry
Let:
x = μ + Wh + ϵ,
with:
h ∼ N (0, 1)
10
W = 9 ,
8
50
μ = 50 ,
50
Then:
50 10 65
x ≈ 50 + 9 ⋅ 1.5 = 63.5
50 8 62
So one latent factor (“science ability”) explains correlated variation across all three subjects. Fitting
FA/PPCA learns W and μ from data, without labels.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 57/63
4. Mixture Models vs Latent Factor Models (Key Differences)
Aspect Mixture Models Latent Factor Models
Latent variable
Discrete (e.g., cluster label) Continuous (e.g., hidden factors)
type
Data from combination of a few continuous
Interpretation Data from one of K subpopulations
sources
Data approximated by several separate blobs Data lies near a low-dimensional subspace /
Geometry
(clusters) manifold
Gaussian Mixture Models, Mixture of Factor Analysis, Probabilistic PCA, Matrix
Examples
Bernoullis Factorization
Dimensionality reduction, representation
Typical task Clustering, density estimation
learning
Both are generative because they specify how data is generated from latent variables.
What is Confusion Matrix . Explain with examples . What is False positive and False negetive
A confusion matrix is a performance evaluation table used in machine learning classification tasks
(especially binary classification) to compare the actual (true) labels with the predicted labels made by a
model.
It helps visually understand how well the model is performing, including correct predictions and the
types of errors.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 58/63
Structure of a Confusion Matrix (Binary Classification)
Predicted Positive Predicted Negative
Actual Positive True Positive (TP) False Negative (FN)
Actual Negative False Positive (FP) True Negative (TN)
Meaning:
Example
Suppose a classifier predicts whether a person has a disease.
TP: Model predicted Positive where actual was Positive → Persons: 1,5 → 2
TN: Model predicted Negative where actual was Negative → Person: 2 → 1
Confusion Matrix:
Example scenario:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 59/63
Spam detection system marks a normal (non-spam) email as spam.
Medical test identifies a healthy person as sick.
Example scenario:
A medical test fails to detect a disease when the patient actually has it.
This error is considered more serious in medical diagnosis and is also called a Type II Error.
Metric Formula
TP +TN
Accuracy TP +FP +FN +TN
TP
Precision TP +FP
TP
Recall (Sensitivity) TP +FN
TN
Specificity TN +FP
Precision⋅Recall
F1 Score 2× Precision+Recall
So the confusion matrix is a central tool for evaluating classification models, especially when class
imbalance exists.
Summary (Exam-Friendly)
If you'd like, I can also provide a confusion matrix for multiclass classification or generate Python
code to compute it.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 60/63
Discuss each term in the confusion matrix in detail with their meaning significance
A confusion matrix is more than just a table of predictions—it gives insight into the different types of
success and failure of a classification model. Each cell represents a count of how the predicted values
compare to actual values. Understanding each term helps evaluate model reliability, robustness, and
practical usefulness.
Below is the standard binary classification confusion matrix format:
Example:
A medical test correctly identifies a sick patient as sick.
Significance:
Example:
A spam filter correctly identifies a normal email as not-spam.
Significance:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 61/63
3. False Positive (FP) (Type I Error)
Meaning:
Cases where the model predicted positive, but the actual class was negative.
Example:
Significance:
Problematic when the cost of wrong positive predictions is high, such as:
Wrongly approving a loan to a risky customer,
Wrongly flagging harmless activities as cyber intrusions.
Impacts metrics: Precision and Specificity.
Example:
Significance:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 62/63
Term Indicates Affects Practical Concern
Good performance in identifying
TP Correct detection of positive Recall, Accuracy
target class
Accuracy,
TN Correct rejection of negative Avoids false alarms
Specificity
FP (Type I Wrongly classifying negatives as Precision,
Costs: false alerts, unnecessary action
Error) positives Specificity
FN (Type II Dangerous in critical systems (missed
Missing actual positive cases Recall
Error) detection)
Conclusion
A confusion matrix does not just show correct and incorrect predictions—it reveals the nature of errors.
Depending on the application, either false positives or false negatives may be more costly, so
understanding each term helps choose the right model, tune thresholds, or select appropriate
evaluation metrics.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 63/63