Covariance Matrix Calculator
Paste a table of data and see how every pair of features moves together: the means, the centered data, the covariance matrix kept exact, and the correlation matrix, with a scatter you can drag.
Data
One sample per row and one feature per column, up to 100 samples and 6 features. Type, paste from a spreadsheet or CSV, or start from an example.
Covariance
Updates as you type.
8 samples of 2 features.
Dividing by n − 1 = 7 makes up for measuring spread around the sample's own mean. Use it when the rows are a sample from something larger.
Mean of each feature
- height (cm)
- 173.125
- weight (kg)
- 69.5
Covariance matrix
The diagonal holds each feature's variance: its covariance with itself.
Correlation matrix
Covariance divided by both standard deviations, so every entry is between −1 and 1 and units no longer matter.
Values marked ≈ are rounded to fit. Select an entry to see it exactly.
height (cm) and weight (kg)
- Covariance
- Standard deviations
- Correlation
height (cm) and weight (kg) rise together, closely.
What the covariance matrix holds
Put the data in a matrix with one sample per row and one feature per column. Subtract each column's mean to get the centered data , so every column averages 0. Then the covariance matrix is one matrix product:
Entry is the dot product of centered columns and , divided by . It's positive when the two features tend to sit above their means together, negative when one is high while the other is low, and near 0 when knowing one tells you little about the other. The diagonal holds each feature's variance, its covariance with itself, and the matrix is always symmetric. The product is worked through entry by entry in the Matrix Multiplication Calculator.
Sample or population, and what correlation adds
Dividing by gives the sample covariance, the usual choice when the rows are a sample from something larger: measuring spread around the sample's own mean slightly underestimates the true spread, and makes up for it. Dividing by gives the population covariance. NumPy's np.cov divides by by default and treats each *row* as a feature, so pass rowvar=False for data laid out as here.
Covariance carries units: height in centimeters against weight in kilograms gives cm·kg. Correlation removes them by dividing by both standard deviations:
That's the cosine of the angle between the two centered columns, the same quantity as in the Cosine Similarity Calculator, so it always lies between and . Correlation only sees straight-line relationships. The "A curve" example has , a perfect relationship, with correlation exactly 0.
Why machine learning cares
- The shape of the data. The covariance ellipse in the picture is drawn from the eigenvectors and eigenvalues of . Its long axis is the direction the data spreads most. Principal component analysis is exactly that: the eigenvectors of the covariance matrix, sorted by eigenvalue. Send the matrix to the Eigenvalue and Eigenvector Calculator to find them.
- Redundant features. Two features with correlation near carry almost the same information. That makes regression coefficients unstable, and it's a common reason to drop a feature or reduce dimensions first.
- Scaling. Features measured in large units dominate the covariance matrix. Standardizing each column first turns the covariance matrix into the correlation matrix, which is why many pipelines scale features before PCA.
Related calculators
The linear algebra underneath, and more of the machine learning section.
Matrix Transpose Calculator
Transpose matrices up to 12×12 in exact fractions, watch rows become columns, and check whether a matrix is symmetric or skew-symmetric.
Matrix Multiplication Calculator
Multiply two to four matrices with exact fractions, entry-by-entry explanations, and Python list import and export.
Eigenvalue and Eigenvector Calculator
Find eigenvalues and eigenvectors with exact fractions, square roots, and complex values, plus each multiplicity. Spin a vector until the matrix only stretches it.
Cosine Similarity Calculator
Compare up to eight vectors by the angle between them, with exact cosines, a similarity grid, and the closest match for each. Includes toy word vectors and king − man + woman.