Linear Algebra in Numpy
“Genius is one percent inspiration and ninety-nine percent perspiration.” – Thomas Edison
Week 2 taught us how to store and move numbers: shapes, axes, broadcasting, universal functions. This week we start computing with them.
Almost every model in the second half of this course is a linear-algebra statement wearing a statistical costume. Fitting a regression is projecting a vector onto a subspace. Regularizing that regression is shrinking along directions the data barely explored. Reducing dimension before clustering is throwing away the smallest singular values. NumPy’s linalg module is where all of these statements are actually evaluated, and the three chapters below are the vocabulary.
In this chapter, we will learn the following:
Solving linear systems the right way:
solveinstead ofinv, and why the distinction is not pedantryThe QR and eigenvalue decompositions, and the condition number as a measure of how much a matrix amplifies error
Orthogonality and projection: the normal equations, the projection matrix, and least squares as a projection onto a column space
The SVD, optimal low-rank approximation, and PCA as the SVD of a centred data matrix
Nothing here is a detour. Three later lectures are promissory notes written against this week:
| When | What comes back |
|---|---|
| Nov 3—regression and ridge | Least squares is projection onto the column space (3.2). The SVD explains exactly what ridge shrinks and why (3.3). Multicollinearity is a large condition number (3.1). |
| Nov 17—k-nearest neighbours | The curse of dimensionality is distance concentration, which is a statement about norms and inner products in \mathbb{R}^d. |
| Dec 8—clustering | PCA runs before k-means so that Euclidean distance means something once the noise directions are gone. |
If a definition here feels abstract, the honest answer is: it will not be in five weeks. Learn it now while it is cheap.