Lecture 10b
Overview
Prof. Schniter demonstrates PCA on 1,288 labeled face images, showing how SVD compresses 1,850-pixel faces and how the resulting features affect XGBoost classification. The lecture contrasts PCA with non-negative matrix factorization (NMF), explains NMF's parts-based face representations and recommender-system applications, then compares PCA visualizations with nonlinear methods such as t-SNE and UMAP.
Key takeaways
- For 1,288 Labeled Faces in the Wild images with 1,850 pixels each, PCA can represent faces with far fewer coefficients; rank 300 retains much of the data's variance while visibly approximating the faces.
- PCA optimizes reconstruction error rather than class separation, so compression can destroy useful label information; LDA instead uses labels when selecting a linear projection.
- PCA is efficient and has an SVD-based closed-form solution, while NMF requires non-negative input and iterative optimization but can yield interpretable, sparse parts-based components.
- On the face-classification experiment, 100 NMF coefficients slightly outperformed raw features in test accuracy, but NMF's computational cost made that compression slower overall than using raw data.
- NMF can support recommender-system matrix completion by fitting only observed ratings; the Netflix Prize example had approximately 100 million ratings across 18,000 movies and 480,000 users.
- t-SNE and UMAP can reveal clearer structure in unlabeled high-dimensional features than PCA, but their visual separation is a diagnostic clue rather than proof of classification accuracy.
Chapters
- The scikit-learn Labeled Faces in the Wild dataset contains about 13,000 news-photo images; filtering for people with at least 70 faces leaves 1,288 images.
- Each grayscale face is 50 by 37 pixels, or 1,850 features, and the selected subset represents seven people.
- The goals are to compress face representations with PCA and test whether those compressed features can support classification.
- PCA begins by subtracting the mean of each pixel across the 1,288 images, using NumPy's column-wise mean and broadcasting.
- An economy SVD with `full_matrices=False` produces U, singular values, and V transpose; the data has rank 1,288.
- For this dataset, the economy-SVD factors U and the singular-value matrix are 1,288 by 1,288, while V transpose has 1,288 rows and 1,850 columns.
- PCA eigenvalues are computed from the SVD singular values as λⱼ = σⱼ²/N, where N is the number of samples.
- The proportion of variance (POV) at rank R is the cumulative sum of the first R eigenvalues divided by the sum of all eigenvalues.
- The POV curve reaches 1 at rank 1,288, while ranks up to 300 retain much of the data energy with a lower-dimensional representation.
- A rank-R face reconstruction adds the mean face to the product of the first R PCA basis vectors and the sample's coefficients.
- Reconstructions improve from R = 1 and 3 to R = 10, 30, 100, and 300; early components mainly capture broad lighting and shading, while later ones add facial details.
- The mean face averages the pixel values, while eigenfaces can contain negative values; the first components reflect vertical and left-right lighting changes.
- The data is split into training and test sets, with one quarter of samples reserved for testing; PCA is fit only on training data.
- Training and test faces are centered using the training mean and projected using the training PCA basis, preventing test data from influencing the fit.
- PCA coefficients can be standardized by dividing by singular values and multiplying by the square root of the training sample count, though XGBoost's tree-based method does not require standardization.
- With 100 PCA coefficients, test accuracy approaches the raw-feature baseline, and reducing the feature count lowers XGBoost runtime even after accounting for the one-time PCA computation.
- PCA minimizes reconstruction error, not classification error, so a high-variance projection can erase the direction that separates classes.
- In a two-feature example reduced to one dimension, the PCA line preserves broad data variation but collapses the distinction between class 1 and class 2.
- Linear discriminant analysis (LDA) uses class labels to choose a projection suited to classification, unlike unsupervised PCA.
- Non-negative matrix factorization approximates X as two lower-rank matrices whose entries are all non-negative, minimizing squared reconstruction error.
- Unlike PCA, NMF does not center the data; the input itself must be non-negative, making pixel values between 0 and 1 suitable but mixed-sign data problematic.
- NMF represents a face as a non-negative weighted sum of non-negative components, which can correspond to recognizable parts such as eyebrows, nose regions, and chin.
- PCA components are orthogonal and can contain positive and negative values; NMF components are non-orthogonal and non-negative, often yielding sparse, parts-based factors.
- For a fixed rank, PCA's unconstrained solution achieves no larger reconstruction error than the more constrained NMF solution; NMF factors can be less unique and require iterative optimization that may reach local minima.
- On the face dataset, NMF features gave slightly higher XGBoost accuracy than PCA and exceeded the raw-feature accuracy at 100 components, but NMF computation made that setting slower than using raw features.
- A recommender system can represent product ratings in a matrix with products as rows and users as columns, where most entries are missing.
- Matrix completion fits factors using only known ratings, then estimates missing ratings to help target product recommendations or advertising.
- The Netflix Prize dataset had about 18,000 movies, 480,000 users, and 100 million ratings, leaving roughly 99% of the matrix incomplete; winning approaches largely used NMF variants.
- Reducing three-dimensional data to two PCA coordinates can reveal cluster separation that is difficult to judge from a static projection of the original 3D points.
- PCA maps MNIST's 784-pixel digit images into two dimensions, where coloring points by their known labels exposes broad clusters for digits such as 0 and 1.
- The first MNIST component contrasts a zero-like shape with a one-like stroke, while the second captures additional shape variations among digits such as 1, 7, and 9.
- Nonlinear visualization methods include kernel PCA, Isomap, and locally linear embedding, alongside modern approaches t-SNE and UMAP.
- On MNIST, t-SNE and UMAP produce clearer digit clusters than PCA even though the embedding algorithms receive features rather than class labels.
- A well-separated embedding can suggest that classification may be feasible, while heavily intertwined points may signal difficulty; visualization is exploratory evidence, not a guarantee of classifier performance.
Transcript excerpt
0:02 All right. This is the lecture for Friday, November 20th that I wasn't able to give in person. So we just finished learning about [clears throat] PCA and how to compute it using the SVD. And so now we're going to do um an example, our demo for this unit [clears throat] um or at least one of the demos for this unit that concerns uh faces. So we're going to use a data set um it's not a very recent one. It's kind of an older one from 2007 called Labeled Faces in the Wild. So these these are this data set contains images. Um these are pretty small by today's
0:52 standards. Um 50 by 37 pixel images. So in total each image has 1,850 pixels and we'll consider those the number of features D for our samples. [clears throat] Um and we're going to use PCA for dimensionality reduction and then we'll also see what happens when we use this prior to classification. So this data set is actually built in scikit-learn. The full data set has 13,000 images. Um these faces are all from news stories in the 2000s. Um [clears throat]
1:39 we're going to um we're not going to use all 13,000. We're going to require that there's at least 70 faces per person, which is something um you can do in this data set. [snorts] And then that's going to restrict us to a subset of 1,288 images. [clears throat] Okay, those are going to be the number of samples in our data set. So we have um 1,288 samples. Each sample has 1,850 features. And because we restricted um the data this way, we also um we have labels on each image. We know whose whose face it is.
2:26 And in total, there are seven people. So
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Prof. Schniter.