Join at slido.com�#3640956
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
3640956
Dimensionality Reduction
Lecture 3
PCA with a review of linear algebra, calculus, and optimization
EECS 189/289, Fall 2026 @ UC Berkeley
Joseph E. Gonzalez and Narges Norouzi
Recap
In Tuesday’s lecture we focused on Nearest Neighbor methods:
Today we will explore Principal Component Analysis (PCA)
We will review linear algebra, calculus, and optimization.
3640956
Taxonomy of�Machine Learning
Supervised Learning
Labeled Data
Quantitative�Label
Clustering
Categorical�Label
Reinforcement
Learning
Alpha Go
Reward
Classification
Regression
Stock
Prediction
Dimensionality�Reduction
Unsupervised
Learning
Unlabeled Data
3640956
Demo
Using PCA and scikit-learn to make sense of congressional votes.
Model
Algorithm
Owl
Cat
Application
This Machine Learning Class
Interpreting the demonstration
How does PCA construct this low-dimensional representation of the data?
3640956
Objective of Dimensionality Reduction
High-dimensional data (many columns) and can be difficult to visualize and model.
3640956
The Curse of Dimensionality
3640956
Objective of Dimensionality Reduction
High-dimensional data (many columns) and can be difficult to visualize and model.
Often high-dimensional data can be �compressed into a lower dimensional �space with minimal loss of information.�
Dimensionality reduction: take �high-dimensional data and map it to a �lower dimensional space that preserves �as much information as possible.
3D Data
2D Representation
3640956
Formulating the Problem
The Rank of a Matrix
3640956
Simple Example
Suppose I have a large table of random rectangles along with properties of those rectangles:
What is the rank of this dataset?
width | height | perimeter | area | diagonal |
7 | 6 | 26 | 42 | 9.22 |
4 | 6 | 20 | 24 | 7.21 |
5 | 2 | 14 | 10 | 5.39 |
7 | 4 | 22 | 28 | 8.06 |
3 | 5 | 16 | 15 | 5.83 |
width
height
area
perimeter
diagonal
3640956
What is the rank of the following dataset?
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
3640956
Rank of the Rectangles Example
a linear combination of the �other two columns
not a linear combination
not a linear combination
5 columns, rank 4
the perimeter column is redundant, so the matrix is not full rank
width | height | perimeter | area | diagonal |
7 | 6 | 26 | 42 | 9.22 |
4 | 6 | 20 | 24 | 7.21 |
5 | 2 | 14 | 10 | 5.39 |
7 | 4 | 22 | 28 | 8.06 |
3 | 5 | 16 | 15 | 5.83 |
width
height
area
perimeter
diagonal
How many dimensions (columns) are really needed?
3640956
How many dimensions are needed to fully describe this dataset?
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
3640956
Intrinsic Dimension and Matrix Rank
The intrinsic dimension is the minimum number of variables needed to describe the data.
5 columns, rank 4
the perimeter column is redundant, so the matrix is not full rank
Intrinsic Dimension is 2
every column is determined by w and h alone
width
height
area
perimeter
diagonal
a linear combination of the �other two columns
not a linear combination
not a linear combination
Every column of that table is determined by the width w and the height h.
3640956
Real data is rarely exactly low rank
Measure the perimeter with a tape measure instead of computing it, and the exact relationship is destroyed 🡪 the rank returns to 5.
Typically, datasets are nearly full rank but are often accurately approximated by a lower dimensional sub-space (close to the intrinsic dimension).
How do we find a lower dimensional representation that �accurately approximates the data?
Full Rank (41)
nothing may be discarded
Rank 2 Approx. → 86%
of the spread in the data
Example: the congressional vote matrix from the demo
3640956
Deriving PCA
The input Data Matrix
3640956
Dimensionality reduction as �Matrix Factorization
3640956
Interpretation of Z and W
Each row of W determines the basis of the subspace of X used to approximate the data. (These will become our Principal Components give the opt. problem.)
Each row of Z determines the “mix” of the rows of W used to reconstruct a row in the original data.
3640956
Which of these products can equal X exactly?
🤔
3640956
Suppose 𝐗∈ℝ^(3×3) is a any 3×3 matrix with full rank. Which factorizations could always exactly reconstruct X.
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
3640956
The rank of the product is bounded by k
Among all factorizations of rank k, which one is best?
rank(ZW) ≤ min(rank Z, rank W) ≤ k
3640956
Defining an objective function
X is assumed to be centered
that is, the mean of each column has been subtracted.
This is an optimization problem
The parameters are Z and W, and there is a single quantity to be minimized. It is the first of many such problems this semester.
3640956
Why we subtract the mean
The best fitting subspace always passes through the mean, �so we subtract the mean first.
3640956
The Factorization is Not Unique
3640956
The Full Optimization Problem
3640956
The Basic Stationary Point Method
This procedure applies when the objective is smooth and the resulting equations can be solved. All conditions hold today, and we obtain an exact solution.
Loss
Stationary Point
3640956
Case k = 1 (Rank 1 Factorization)
1
(orthonormality �constraint)
Simplified Loss
3640956
3640956
=
3640956
The constraint is essential: it is what makes the problem well posed.
3640956
The Method of �Lagrange Multipliers
Gradients of the loss and scaled constraint violation should be parallel!
3640956
A Small Example
so x = y
3640956
Applying the Method of Lagrange Multipliers
3640956
Applying the Method of Lagrange Multipliers
🤔
What is this?
3640956
What does this equation (Σ𝐰^⊤=𝜆𝐰^⊤) say about w?
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
3640956
The Eigenvector Equation
3640956
Subsequent Principal Components
3640956
Computing the Principal Components
U, S, Vt = np.linalg.svd(X, full_matrices=False)
3640956
Returning to the vote data
3640956
Matrix Factorization for �Content Recommendation
Only the observed pairs Ω are part of the loss. �The learned factors are then used to fill in every rating that was never given.
Bonus
Drop unit vector constraint and add a penalty term.
3640956
Summary
Next week we turn to probability!
3640956
Dimensionality Reduction
Lecture 3
Credit: Joseph E. Gonzalez and Narges Norouzi
Reference Book Chapters:
Have Fun!!!