Eigenvalues and Eigenvectors
The mathematical foundation of PCA, spectral clustering, and PageRank — built from plain English first, then intuition, then math, then code.
Imagine spinning a blob of data. Most directions stretch and rotate. A few special directions only stretch — never rotate. Those are eigenvectors.
You have a dataset of 10,000 Swiggy customers. Each customer is described by 20 numbers — order frequency, average order value, preferred cuisine, delivery distance preference, time of day, and so on. That dataset is a cloud of 10,000 points in 20-dimensional space.
Now imagine squashing that cloud into 2 dimensions so you can plot it. You need to pick which 2 directions to keep out of the original 20. If you pick randomly, you lose most of the interesting structure. But there exist specific directions in the data — the directions along which the cloud is most spread out — that capture the most information. Finding those directions is exactly what eigenvalues and eigenvectors do.
Those special directions are the eigenvectors. How much the data spreads along each direction is the eigenvalue. The eigenvector with the largest eigenvalue is the single most informative direction in your entire dataset.
Think of a shadow. You hold an odd-shaped object under a light. As you rotate the object, its shadow changes shape — sometimes long and thin, sometimes short and wide. There is one specific angle where the shadow is longest. That angle is like an eigenvector — the direction that reveals the most about the object's structure. The length of that longest shadow is like the eigenvalue.
PCA (Principal Component Analysis) uses exactly this idea. It finds the directions in your data where the shadow is longest — where the data varies the most — and uses those as the new axes. Module 33 covers PCA in full. This module gives you the mathematical foundation to understand how it works.
A matrix is a transformation — it stretches, rotates, and reflects vectors
From Module 04 you know that matrix multiplication transforms vectors. When you multiply a matrix by a vector, the result is a new vector — usually pointing in a different direction and having a different length. The matrix is performing a geometric operation on the vector.
Most vectors get both rotated AND stretched when a matrix is applied to them. The direction changes and the length changes. But some special vectors only get stretched — they keep pointing in exactly the same direction. Those special vectors are eigenvectors.
A vector e is an eigenvector of matrix A if multiplying A by e gives back e scaled by a number λ:
A concrete example — verify the definition yourself
The best way to understand eigenvectors is to verify the definition by hand on a small example. We will use a 2×2 matrix so everything is visible. Once you see it work once, the concept locks in permanently.
Eigenvalues tell you how important each eigenvector is
Every square matrix has as many eigenvalue-eigenvector pairs as it has dimensions. A 20×20 matrix has 20 pairs. Each pair is a direction (eigenvector) and a number (eigenvalue). The eigenvalue tells you how much the transformation stretches the data in that direction.
In the context of data analysis: if you compute the covariance matrix of your dataset (a matrix that describes how features vary together), its eigenvectors point in the directions of maximum variance in the data. The eigenvalues tell you how much variance each direction captures.
Explained variance — turning eigenvalues into percentages
The most useful thing you can do with eigenvalues in ML is convert them to "explained variance" — what percentage of the total information does each direction capture? This tells you how many dimensions to keep when reducing the dimensionality of your data.
PCA from scratch using eigenvalues — the complete picture
PCA (Principal Component Analysis) is the most widely used dimensionality reduction technique in ML. It reduces a dataset from many dimensions to fewer dimensions while preserving as much information as possible. The entire algorithm is just four steps — all of which you now understand.
Subtract the mean and divide by standard deviation for each feature. This puts all features on the same scale so no single feature dominates the eigenvalue calculation because of its units.
The covariance matrix captures how every pair of features varies together. If two features always go up and down together, they have high covariance. This matrix is always square and symmetric.
The eigenvectors of the covariance matrix are the principal components — the directions of maximum variance. The eigenvalues tell you how much variance each direction captures. Sort both by eigenvalue, largest first.
Multiply the original data by the top k eigenvectors. The result is a new dataset with only k dimensions, but those k dimensions capture the most important variation in the original data.
When to use PCA vs when not to
Three algorithms you will use regularly — all built on eigenvalues
Eigenvalues are not just a PCA concept. They are the mathematical core of three widely deployed algorithms. Once you see the connection, these algorithms stop being black boxes.
Eigenvectors of the covariance matrix. Already covered in full above. Used everywhere: image compression, customer segmentation visualisation, noise removal from sensor data.
Regular K-Means fails when clusters are not round blobs. Spectral Clustering builds a graph where similar data points are connected, then finds eigenvalues of the graph's Laplacian matrix. The eigenvectors reveal cluster structure that K-Means can never find. Used at Flipkart for discovering customer communities, at Swiggy for identifying restaurant "neighbourhoods".
The original Google algorithm that made Google worth a trillion dollars. The web is a graph: pages are nodes, links are edges. PageRank builds a matrix representing all links and finds its principal eigenvector. Pages that appear strongly in that eigenvector are the most "important" pages — the ones that many important pages link to. Every search result you see is influenced by this eigenvector.
Every common eigenvalue error — explained and fixed
You now understand how ML finds structure in data. Next: how it learns from it.
Eigenvalues help you find the important directions in a dataset before training. The next module — Derivatives, Gradients and the Chain Rule — explains how ML models actually improve during training. Specifically: how do you adjust millions of model parameters to make predictions better? The answer is gradient descent — the engine behind every neural network, logistic regression, and linear regression you will ever train.
The mathematical engine behind every learning algorithm. Understand gradient descent before you ever run model.fit().
🎯 Key Takeaways
- ✓An eigenvector is a special vector that does not rotate when a matrix transformation is applied to it — it only stretches or shrinks. The amount it stretches is the eigenvalue. The equation is A·e = λ·e.
- ✓Most vectors change direction when multiplied by a matrix. Eigenvectors are the exception — they are the "natural axes" of the transformation, the directions the matrix fundamentally operates along.
- ✓For a covariance matrix of your dataset, eigenvectors point in the directions of maximum variance in the data. The eigenvalue tells you how much variance that direction captures. Large eigenvalue = important direction. Small eigenvalue = noise.
- ✓PCA is four steps: standardise → covariance matrix → eigendecomposition → project onto top-k eigenvectors. The result is a lower-dimensional dataset that preserves the most important variation from the original.
- ✓Always use np.linalg.eigh() (not eig()) for covariance matrices — it guarantees real eigenvalues, is faster, and is numerically more stable. Always standardise data before computing eigenvalues.
- ✓Eigenvalues appear in three major production algorithms: PCA (covariance matrix eigenvectors), Spectral Clustering (graph Laplacian eigenvectors for non-convex clusters), and Google PageRank (principal eigenvector of the web link matrix).
Discussion
0Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.