Projections: the closest point in a smaller space
Drop a point onto a line or plane and keep what's left over at right angles. Least-squares fits, PCA scores and random projections are all this one move, with different choices of where to project.
What runs in CodeSplash
- REP012Johnson–Lindenstrauss random projection Runs in CodeSplash (Prepare)
- Principal component analysis Verified in Python and R
You will be able to
- Project a vector onto a unit direction and onto a subspace with orthonormal columns
- Recognize least-squares fitted values and PCA reconstructions as orthogonal projections
- Say what a random projection keeps and why its dimension depends on the number of rows, not columns
Drop a point onto a line
ReadTake a unit vector (length 1). The orthogonal projectionOrthogonal projectionDrop a point straight onto a line or subspace: the closest point there, with a leftover at right angles to it. of onto the line through is
The dot productDot productMultiply two vectors entry by entry and add: large when they point the same way, zero when they are at right angles. is the coordinate along the line, the score. The leftover is at right angles to , and is the closest point on the line to . Pythagoras splits the squared length: .
Onto a plane, or any subspace
ReadStack orthonormal directions as the columns of . Then
gives the scores; multiplying by rebuilds the point in the original space. With = the top principal directions, this is exactly the PCA reconstruction from the previous lesson. Projecting twice changes nothing: for every projection .
Least squares is a projection
ExploreRegression asks for the fitted values closest to among all mixes of the feature columns. The closest point in a subspace is the orthogonal projection, so
is the hat matrix, and the residuals are at right angles to every feature column.
DExplorable · Fit the line yourself
What makes the least-squares line 'best'?
Add one point far below the trend at high x. What happens to the least-squares slope?
Commit your prediction above to see the result
Make your prediction to see the result.
Move the line until your sum of squared residuals is as small as it gets. That minimum is the projection.
Random directions work surprisingly well
ReadPCA learns its directions from the data. A random projectionRandom projectionMaps many numeric columns to fewer by fixed random weights; distances between rows are kept up to a small distortion. draws them at random:
The Johnson–Lindenstrauss lemma says that for rows, a target dimension on the order of keeps every pairwise distance within a factor with high probability. The number of original columns doesn't appear. With = 0.2, the usual bound asks for about 3,200 dimensions to keep every distance among a million rows, whether they started with ten thousand columns or ten million.
Check: projections
CheckpointCheck yourself
and , a unit vector. What is the score ?
Show the answer
Answer: 5
. Here lies exactly on the line, so the leftover is zero.
Check yourself
In a least-squares fit with an intercept, what is true of the residuals?
Show the answer
Answer: a
Orthogonal projection leaves a residual perpendicular to the subspace. The intercept column is all ones, so perpendicular to it means the residuals sum to zero.
Check yourself
You project the PCA reconstruction onto the same principal directions again. What do you get?
Show the answer
Answer: a
Projections are idempotent: .
Check yourself
The Johnson–Lindenstrauss lemma sets the target dimension of a random projection. What does that dimension grow with?
Show the answer
Answer: a
. The original dimension doesn't enter, which is why random projection scales to very wide data.
Recap
Recap- Projection keeps the closest point in a subspace and leaves a perpendicular remainder.
- with orthonormal projects; least squares uses the hat matrix .
- Random projection keeps pairwise distances with a dimension set by , not by the number of columns.
Concepts in this lesson