Covariance Calculator
Calculate the covariance between two features or variables in a dataset.
About Covariance Calculator
Covariance measures how two variables change together: cov(X,Y) = Σ(x − mean_x)(y − mean_y) / (n−1) for the sample covariance. A positive covariance means the variables tend to increase together; a negative covariance means one tends to increase as the other decreases; a covariance near zero suggests no linear relationship. Unlike correlation, covariance's magnitude depends on the scale of the input variables, which is why it's often normalized into the unitless correlation coefficient for interpretability across different feature scales.
Formula
cov(X, Y) = sum((x_i - mean_x)(y_i - mean_y)) / (n - 1)
- x_i
- Values of variable X
- y_i
- Values of variable Y
- mean_x
- Mean of X
- mean_y
- Mean of Y
- n
- Number of paired observations
Worked example
With the default values below, Covariance Calculator returns Sample Covariance of 21.0000. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Series X
- 2, 4, 6, 8, 10
- Series Y
- 3, 7, 8, 15, 20
Results
- Sample Covariance
- 21.0000
- Population Covariance
- 16.8000
- Mean of X
- 6.0000
- Mean of Y
- 10.6000
Step by step
- 1Mean of X, Mean of Y= x̄=6.0000, ȳ=10.6000
- 2Σ(x−x̄)(y−ȳ)= 84.0000
- 3Sample covariance: ÷ (n−1)= 21.0000
- 4Population covariance: ÷ n= 16.8000
Assumptions and limits
- The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, fees or charges or compounding frequency into account.
- Figures are rounded for display to 4 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
Why is covariance hard to interpret directly?
Covariance's magnitude depends on the units and scale of both variables — a covariance of 1000 could indicate a strong or weak relationship depending on whether the variables are measured in single units or thousands, which is why correlation (a normalized version) is usually preferred for interpretation.
What does a covariance of exactly zero mean?
It means there is no linear relationship between the two variables on average — but note this doesn't rule out a strong nonlinear relationship, since covariance only captures linear co-movement.
How is covariance used in ML?
The covariance matrix (pairwise covariances across all features) underlies techniques like PCA (Principal Component Analysis), Gaussian distributions in probabilistic models, and portfolio-style risk analysis of feature interactions.
Why must both series be the same length?
Covariance is computed from paired observations — each x_i must correspond to the same observation as y_i — so mismatched lengths mean the pairing is undefined and the calculation cannot proceed.
