← All Base Form Math projects
BM-09NOT STARTEDBASE FORM · LINEAR ALGEBRAMATHPYTHON

Lookalike finder

Given a new face photo, find the most similar faces in a dataset using eigenfaces you compute yourself.

EST.6 h
REWARD+100 XP
AFTERTurk & Pentland

ML-ARENA BENCHMARKS

YOUR NUMBER VS THE INDUSTRY'S
METRICINDUSTRYMINE
reconstruction at k = 20
GOAL · match within 1e-6 (up to sign)
sklearn.decomposition.PCA—
no results yet
YOUR RESULTS

Your recorded results appear here.

Brief

This project builds a face matcher with no neural network. You turn every face into a short list of numbers, then look for the closest list. The numbers come from principal component analysis (PCA), which here is just the SVD you wrote in BM-08, applied to a stack of faces.

The Olivetti dataset has 400 photos of 40 people, each 64 × 64 pixels. Flatten each photo into a row of 4,096 numbers and stack them into a 400×4096400 \times 4096 matrix XX. Subtract the mean face μ\mu from every row. The top right singular vectors of the centred matrix are the directions in which faces differ most. Reshaped to 64 × 64, they look like faint faces, so they are called eigenfaces.

Keep the first k=20k = 20 eigenfaces as the rows of Vk⊤V_k^\top. A face xx becomes its projection z=Vk⊤(x−μ)z = V_k^\top (x - \mu), just 20 numbers. To rebuild it, go back the other way:

x^=μ+Vkz\hat{x} = \mu + V_k z

Two faces of the same person tend to have close zz values, so the nearest neighbour in this 20-number space is a good lookalike guess.

OVERVIEWFig. 1
STEP 1Stack faces400 × 4096,one row per photo STEP 2Centresubtract themean face STEP 3SVDkeep 20 rows of Vᵀ:the eigenfaces STEP 4Projecteach face becomes20 numbers STEP 5Nearest facesmallest distancein 20-D space
The pipeline in five steps. Objective 5 checks step 4 against scikit-learn. Why it's here: See how the SVD from BM-08 slots into a working face matcher before you start.
HINT · OBJECTIVE 3
Stuck? Hints stay hidden until you ask.
HINT · OBJECTIVE 5
Stuck? Hints stay hidden until you ask.

DATA · Olivetti faces

Objectives

0 / 6 CLEARED

Read-only. Log in to update progress.

VICTORY CONDITIONS

  1. Your rank-20 reconstruction matches sklearn PCA (svd_solver="full") within 1e-6 for every pixel, recorded with `python tools/mlarena.py record BM-09 "<largest difference>"`.
  2. Leave-one-out nearest-neighbour accuracy in the 20-number space is reported, alongside the same test on raw pixels.
  3. A grid showing the mean face, the first 8 eigenfaces, and one query with its three closest matches.

Side quests

Plot recognition accuracy and reconstruction error against k from 1 to 100. Find where adding components stops helping recognition.
Compare plain distance with cosine similarity from BM-01 in the 20-number space.

Terms in plain words

Principal component analysis (PCA)
Find the directions in which the data varies most. They are the right singular vectors of the centred data matrix.
Mean face
The average of all face images, pixel by pixel. Subtracting it first is what makes the SVD find directions of variation.
Eigenface
One principal direction, reshaped back to 64 × 64 so you can look at it. It looks like a ghostly face.
Projection
The dot products of a centred face with the k eigenfaces. These k numbers are the face's new, short description.
Nearest neighbour
The stored item at the smallest distance from the query. Here, the face whose k numbers are closest to the new face's.