Covariance Matrix
Formal
(Covariance)
The covariance between two random variables and measures how they vary together:
If and are independent, (but not vice versa in general).
(Correlation) — a normalised, dimensionless version of covariance:
(Covariance Matrix)
For a random vector , the covariance matrix is the matrix:
The entry is , and the diagonal is .
Properties:
- is always symmetric: .
- is always positive semi-definite: for all .
- If all variables have non-zero variance and no perfect linear dependencies, is positive definite — a valid inner product (see Symmetric, Positive Definite Matrices).
(Sample Covariance Matrix)
Given a dataset with sample mean , the empirical estimate is:
The factor (Bessel’s correction) makes this an unbiased estimator of the population covariance.
Intuition
Think of your microservice cluster emitting a vector of metrics per minute: . The covariance matrix is the correlation dashboard for these metrics:
- Diagonal entries: variance of each individual metric (how much it fluctuates).
- Off-diagonal entries: how two metrics move together. If
cpu_usageandp99_latencyhave high positive covariance, one predicts the other.
The shape of the covariance matrix defines the geometry of the data cloud. Its eigenvectors point along the principal axes of the ellipsoid; its eigenvalues are the squared radii along those axes. This is precisely what PCA computes.
ML Applications
- PCA — decomposes via eigendecomposition. Eigenvectors = principal components; eigenvalues = variance explained along each component.
- Multivariate Gaussian — fully parameterised by . The covariance matrix controls the shape, orientation, and scale of the distribution’s ellipsoidal level sets.
- Gaussian Discriminant Analysis (LDA/QDA) — models each class as a Gaussian with its own .
- Mahalanobis distance — ; a distance metric that accounts for feature correlations and scales. Generalises Euclidean distance.
- Regularisation of — in practice, is often rank-deficient (more features than samples). Ridge-style regularisation ensures positive definiteness.
Connections
- Forward Links: MLE and MAP, Geometry of Random Variables
- Backward Links: Expectation and Variance, Common Probability Distributions, Symmetric, Positive Definite Matrices