The first unsupervised problem we tackle is the vaguest-sounding one: given a set of data points, understand something useful about them. To make that precise we need three things: what a data point is, what "understand" means, and what "useful" means. The first is easy. The second is where the running theme of this course, comprehension is compression, does its work.
Data points are vectors
Throughout the course, a data set is a collection of points , each a vector of real numbers:
Each coordinate is a feature. If we record the height, weight and age of 100 people, each person is a point in and . If we store 28-by-28 grey-scale images, each image is a point in .
Understanding as compression
Here is a small data set of four points in two dimensions:
How many numbers does a computer need to store it? The obvious answer is . But look again: in every point, the second coordinate is exactly times the first. If we spot that relationship, we can store the data differently:
- one representative vector for the whole data set, say ;
- one coefficient per point: .
Each point is the representative scaled by its coefficient: . That is numbers instead of 8, and nothing is lost: the data can be reconstructed exactly.
Six instead of eight is unimpressive, but the saving grows with the data. With a billion such points we would store numbers instead of , almost exactly half. In dimensions, if every point is a multiple of one direction, the cost drops from to . Finding that relationship is understanding something about the data, and the compression is the proof.
Two details will matter later.
- The representative is not unique. Any non-zero vector along the same line works, with the coefficients rescaled to match. We are free to pick the one of length 1, which makes the formulas cleaner.
- Lines through the origin. "Representative times coefficient" always describes a line through the origin (coefficient 0 gives the origin), so for now our lines pass through the origin.
When points leave the line
Real data is never this tidy. Add a fifth point, , which is not on the line. Now no single representative reproduces all five points.
We could use two representatives, say and , and give every point two coefficients. That reconstructs everything exactly, but it costs numbers, which is more than storing the data directly. Exact reconstruction and compression are now in conflict, and one must give.
We give up exact reconstruction. Keep the line, and for the stray point find a proxy: a point on the line that stands in for it. We lose a little information (the gap between and its proxy), but we keep the compression. The natural choice of proxy is the point on the line closest to , because it loses the least. That point is the projection of onto the line.
Finding the projection
Let the line be all multiples of a vector , and look for the multiple closest to a point . The squared length of the gap is
This is a parabola in . Setting its derivative to zero, , gives
The numerator is the dot product of the point with the direction; the denominator is the squared length of the direction. If we choose with , the denominator disappears:
So with a unit representative, the coefficient of a point is simply its dot product with the representative. For our stray point, the unit vector along is , so the coefficient is and the proxy is . The leftover, , is perpendicular to , as it must be: .
Which line?
So far someone handed us the line. In practice nobody tells us which points are "on the line" and which stray: every point strays a little. Height and weight are related, but no real class of 100 people lies exactly on a line.
Any line gives the same compression (one representative plus one coefficient per point), so compression cannot choose between lines. What differs is how much we lose. A line through the long axis of the cloud leaves short gaps; a line across it leaves long ones. That suggests the goal:
Find the unit vector whose line gives the smallest total reconstruction error over the data set.
The next chapter solves exactly this problem, and the solution turns out to be an eigenvector of a matrix built from the data.
The leftovers may still hold information
Suppose we find the best line. Are we done? Picture data in three dimensions that lies on a flat plane. The best single line lies somewhere in that plane, but every point's leftover (its residual, ) also lies in the plane, and the residuals all point along one common direction. If the residuals were pure noise they would scatter in every direction; because they line up, they still contain structure.
That suggests a procedure:
- Find the best line for the data.
- Replace every point by its residual, .
- Find the best line for the residuals, and repeat.
Each round peels off one more direction. Before running it, one practical problem must be fixed: our lines pass through the origin, but a data cloud can sit far from the origin. A line through the origin may then fit badly even when the cloud is perfectly long and thin. The fix is to centre the data first, by subtracting the mean:
After centring, the origin sits in the middle of the cloud, and lines through the origin can follow its shape.
This procedure raises four questions, which the next two chapters answer:
- How do we actually find the best line?
- How many times should we repeat?
- Where is the compression once there are several lines?
- What representation of each point do we end up with?