The covariance of values differs if you switch from kilograms to pounds. But the correlation does not.
And just that fact is the whole explanation for the difference between covariance and correlation. It’s buried in paragraph seven in almost every explanation out there, after all the formulas and all the definitions, after you’ve finished reading the article.
So here’s where we are after reading through this whole article: The covariance can tell you about the direction of change of two values but cannot tell you about how much one changes relative to another value. The correlation, on the other hand, can give you both.
All the information below is about how these differences come about.
What Will I Learn?
What Covariance Actually Measures?
Two random variables, X and Y, are considered. The covariance determines the direction in which they move together. In simpler terms, it is a measure of the distance of each observation from their respective means multiplied by each other and then averaged for all observations.
Sample covariance equation:
Cov(X, Y) = Σ(Xᵢ − X̄)(Yᵢ − Ȳ) / (n − 1)
Each part:
- (Xᵢ − X̄) — how far each X value sits from X’s mean
- (Yᵢ − Ȳ) — how far each Y value sits from Y’s mean
- Σ / (n − 1) — sum those products across all data points, then divide by sample size minus one
This subtraction of one is the Bessel correction. If you are working with samples and not populations, dividing by n will be an underestimate of the actual variance, and subtracting one compensates for this. Most statistical programs, such as NumPy with its default parameter ‘bias = False’, use this formula.
Machine Learning Course
Average time: 5 month(s)
Skills you’ll build: Python, Scikit-learn, Supervised & Unsupervised Learning, Feature Engineering, Model Deployment, and more..
What the Sign Tells You (And What It Doesn’t)?
- Positive covariance: Both variables tend to be above their respective means simultaneously.
- Negative covariance: One variable is above its mean while the other is below.
- Zero covariance: No clear linear relationship.
However, truthfully speaking, the value itself is virtually meaningless to interpret without further knowledge. For example, what would 77 covariance for two variables mean as opposed to 77 covariance for two other variables measured using some other scale? It mixes up units of the two variables in one figure, making it impossible to interpret separately.
The meaning of the sign is meaningful; the raw number is not.
What Correlation Actually Measures?
Correlation fixes the scale problem by dividing covariance by the product of both variables’ standard deviations:
r = Cov(X, Y) / (σ_X × σ_Y)
This is the Pearson correlation coefficient. Its origin dates back to 1896 when Karl Pearson mathematically defined it. Independently, its discovery was made by Francis Galton in 1888, while investigating the field of heredity, anthropology, and psychology. The division takes away all units of measurement; the result is always somewhere within −1 and +1, regardless of the initial scale of measurement.
When a value of correlation is +1, it implies a perfect positive linear relation. When the value is −1, it denotes a perfect negative relation. A zero correlation implies there is no linear relation at all.
The consistent scale is what allows comparison of the correlations among different datasets, different variables, and different fields of study. Any two covariance numbers from two separate datasets can never be compared in a meaningful way because their scales of measurement will be different; the same cannot be said about any two correlation numbers.
What Correlation Strength Values Mean in Practice
A correlation of 0.7 sounds strong. Strong relative to what, though?
Jacob Cohen’s 1988 benchmarks give the most widely used starting point:
| Correlation Range | Interpretation |
| ±0.10 – 0.29 | Small / weak |
| ±0.30 – 0.49 | Medium / moderate |
| ±0.50 and above | Large / strong |
They are not universal. For example, in clinical medicine, a correlation between a treatment and its outcome at 0.3 is significant and actionable. On the other hand, in the financial market, because there are always confounding factors, 0.5 could be seen as irrelevant information. In the field of physics, 0.7 would probably be a bad fit.
The Core Difference — A Worked Example
Five people. Height in centimeters. Weight in kilograms.
| Person | Height (cm) | Weight (kg) |
| A | 160 | 55 |
| B | 170 | 68 |
| C | 175 | 72 |
| D | 180 | 80 |
| E | 165 | 60 |
Covariance(height_cm, weight_kg) ≈ 77.5
Now convert height to meters — divide every height value by 100. The people haven’t changed. The relationship hasn’t changed. The scatter plot looks identical.
Covariance(height_m, weight_kg) ≈ 0.775
Different number by a factor of 100.
Pearson correlation in both cases: ≈ 0.99
The correlation does not budge. It has been normalized already to make it unitless. The covariance, on the other hand, was measured in centimeters-kilograms initially and meters-kilograms in the latter measurement; the correlation, meanwhile, was measuring the form of the data pattern, which remained unchanged after you changed the scale of your axis.
Covariance vs Correlation
| Feature | Covariance | Correlation |
| What it measures | Direction of linear relationship | Direction + strength of linear relationship |
| Output range | −∞ to +∞ | −1 to +1 |
| Carries units? | Yes | No |
| Changes with scale? | Yes | No |
| Easy to interpret? | No — magnitude depends on scale | Yes — fixed, comparable range |
| Compare across datasets? | No | Yes |
| Best suited for | Model internals, matrix construction | Exploration, communication, feature analysis |
When to Use Covariance vs Correlation
As a general rule of thumb, always go for correlation. And in all fairness, this is usually the right thing to do. The exceptions are precisely where blindly following correlation causes something further down the chain to break but in a non-obvious way. All the literature on this subject gets this step wrong: they present the measures and let you decide on your own.
Use covariance when:
1. You’re running PCA and scale differences carry meaning: If PCA is performed using the covariance matrix of a variable, then variables with naturally higher variances will have greater importance in determining the principal components. This is desirable when there is genuine information in such variance differences, like daily returns volatilities in the case of financial data, since the goal is not to normalize them. By performing PCA using a correlation matrix, one assumes that all variables are scaled equally. [INTERNAL LINK: principal component analysis explained]
2. Your model depends on raw variance structure: Some multivariate and probabilistic models require the covariance matrix as the input because of their dependence on the scale. The replacement of the covariance matrix by the correlation matrix will affect the model’s results in ways not immediately apparent from its output.
3. All variables are in the same units: If the units are already identical, then it is not the scaling problem. Both covariance and correlation tell you the same thing about the direction; the difference becomes negligible in real-world situations although correlation is more straightforward.
Use correlation when:
1. You’re comparing relationships across variables in different units: Correlation allows you to analyze and understand relationships between, for example, height & weight versus age & blood pressure in one table. The covariance table will give you no information because you cannot compare those numbers.
2. You are conducting exploratory data analysis: You may understand instantly from a correlation heatmap how relationships between 20 variables look like in your data set. Not so with covariance.
3. You’re doing exploratory data analysis: A correlation heatmap over a 20-variable dataset is readable in seconds. Try interpreting a covariance heatmap without knowing each variable’s scale, and you’re guessing.
4. You’re checking for multicollinearity before regression: Highly correlated predictors cause problems in linear models; a correlation matrix identifies them quickly and clearly.
How to Calculate Both in Python
NumPy
python
import numpy as np
height_cm = [160, 170, 175, 180, 165]
weight_kg = [55, 68, 72, 80, 60]
# Sample covariance matrix (ddof=1 is the default)
cov_matrix = np.cov(height_cm, weight_kg)
print(cov_matrix[0][1]) # covariance between height and weight
# Pearson correlation matrix
corr_matrix = np.corrcoef(height_cm, weight_kg)
print(corr_matrix[0][1]) # Pearson r between height and weight
np.cov() uses ddof=1 by default — sample covariance. Pass ddof=0 for population covariance if you have the full dataset, not a sample. The two outputs will differ, and using the wrong one in a downstream model is a quiet, difficult-to-spot error.
pandas
python
import pandas as pd
df = pd.DataFrame({
'height_cm': height_cm,
'weight_kg': weight_kg
})
print(df.cov()) # covariance matrix
print(df.corr()) # Pearson correlation matrix (default method)
print(df.corr(method='spearman')) # Spearman -- use when data has outliers or non-linear rank patterns
df.corr() defaults to Pearson. Spearman is the right choice when your data has outliers that would distort a linear measure, or when the relationship you care about is monotonic rather than strictly linear.
Covariance Matrix vs Correlation Matrix in Code
Each of the diagonal elements when using df.cov() returns the variance of the respective variable, while each of the off-diagonal values represents the covariance. On the other hand, when using df.corr() , all of the diagonal elements return 1.0, while the off-diagonal values are rescaled from −1 to +1.
In reality, however, many data workflows actually begin with df.corr() specifically because of this fact – it allows you to have an overview in an instant. All you need to do then is add a heatmap using seaborn, and you will instantly be able to identify any meaningful relationships within your data set.
Two Common Mistakes to Avoid
Mistake 1: Treating a Large Covariance as a Strong Relationship
Incorrect.
The fact that the covariance between the annual income and house price variables equals 50,000, with both being expressed in dollars, does not mean that there is a more robust association than the one with the covariance of 0.003 between the two variables, which are measured in millimeters. It all depends on the units of measurement, but not on the intensity of the association. This is the exact reason why covariance is used within mathematical models, where the algorithm processes it correctly, instead of presenting the result itself.
Mistake 2: Treating Correlation as Proof of Causation
It happens more often in product analytics than I would have liked. There’s a 0.8 correlation found between a metric for engagement with a feature and a metric for user retention. They claim there’s causality. A new roadmap is created based on that. Later on, they find out that there was a third factor driving the two variables but not included in either of them. The correlation was true. The conclusion was false.
The best example here would not be the classic correlation between ice cream consumption and drownings. It would be Anscombe’s Quartet. Four entirely different datasets generate a correlation value of 0.816 according to Pearson r. One of them shows a linear relationship. One shows a curved one. One shows a perfectly flat line with one outlier affecting the results. The correlation is exactly the same. Yet the relationships are completely different.
Graph your dataset before interpreting its correlation. Not optional.
Data Science Course
Program Highlights
✓ 6 Months Industry-Focused Program
✓ Live Classes by Industry Experts
✓ 15+ Real-World Projects
✓ Resume & Interview Preparation
✓ Placement Assistance
Skills You’ll Build
Python • SQL • Power BI • Statistics • Machine Learning • Generative AI
Frequently Asked Questions
Q1. What is the main difference between covariance and correlation?
Ans. While covariance is used to determine the directional relationship between variables, correlation measures both the direction and the degree of the relationship. It is computed by dividing the covariance of the two variables by their standard deviation multiplied together. Therefore, correlation will range from -1 to +1, while covariance can have values outside that range.
Q2. Can covariance be negative?
Ans. Indeed, when one variable goes up, the other goes down, which results in negative covariance. In addition, the sign of covariance corresponds to the sign of the correlation between the variables, and thus, if covariance is positive, then the correlation will be positive, too.
Q3. What does a correlation of 0 mean?
Ans. It means that no linear association exists between the two variables. It doesn’t imply that there isn’t any relationship at all; two variables may be strongly related along a curve, for example, without having much of a linear association. That’s why you should always visualize your data before making conclusions about it from statistics alone.
Q4. When should I use covariance over correlation?
Ans. If the scale matters for your particular algorithm, especially when you’re creating covariance matrices for techniques like PCA and other types of multivariate modeling, it makes sense for variables with higher variation to influence the outcome more. If you want to explore, communicate, or analyze features, use correlations.
Q5. Is correlation just normalized covariance?
Ans. Absolutely. Normalizing by dividing the covariance by the product of the two standard deviations de-standardizes the covariance and normalizes the result from -1 to +1. There you go; you’re done. You cannot normalise them without knowing what those two standard deviations were in the first place.
Q6. Can two variables have zero covariance but still be related?
Ans. Of course! Zero correlation or zero covariance means that there is no linear relationship. But the relationship between the two variables could very well be quadratic, cyclical, or otherwise non-linear. Non-linear relationships are beyond the scope of both of these measures, so it’s important to examine the scatter diagram.
Conclusion
Do not memorize the equations. Remember the principles. Use covariance if scale preservation is important. Use correlation if you must make comparisons, communicate, and understand. These are all decisions that spring forth from these two statements.
And if there ever comes a time when you look at a correlation and know precisely what it means, still do the scatterplot. It is the surprising correlation number that you want to investigate further.