Skip to content
Calcrivo

Covariance Calculator

Calculate the covariance between two features or variables in a dataset.

Inputs

Sample Covariance

21.0000

Population Covariance

16.8000

Mean of X

6.0000

Mean of Y

10.6000

Step by step

  1. Mean of X, Mean of Y

    = x̄=6.0000, ȳ=10.6000

  2. Σ(x−x̄)(y−ȳ)

    = 84.0000

  3. Sample covariance: ÷ (n−1)

    84.0000 ÷ 4

    = 21.0000

  4. Population covariance: ÷ n

    84.0000 ÷ 5

    = 16.8000

How it works

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

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.

You might also need