Random vectors and the covariance matrix
The topic Joint distributions and independence gave us the words for several variables at once: a joint density, marginals, conditional distributions, and covariance as a measure of how two variables move together. It also showed the price. A joint distribution of variables is a function of arguments, and nothing forces it to be simple. This topic studies the one family that machine learning reaches for first, because a vector of means and a table of covariances describe it completely.
Stack the variables into a random vector , for example features of one object in a dataset. Its mean vector collects the means, . Its covariance matrix collects all the covariances:
A one-line reminder on matrices: turns a column into a row, and a column times a row, , is a table with entries . So the second formula is just the first one written for all pairs at once. The diagonal holds the variances, since .
The running example of this topic has two features measured from their averages, so , and
Feature 1 varies more (), feature 2 less (), and the positive covariance says they tend to rise together.
Not every table of numbers can be a covariance matrix. It is symmetric, because . And for any fixed weights , the number has variance
which is the rule from the previous topic, extended to weighted terms. A variance is never negative, so for every : the matrix is positive semidefinite. For a symmetric matrix this comes down to a nonnegative diagonal and a nonnegative determinant , which is the familiar once more. The course Mathematics for ML covers such matrices in the topic Symmetric matrices and quadratic forms.