Covariance
Covariance is an unstandardized measure of how two random variables vary together relative to their means, indicating the direction of their linear association.
Causal Inference for Data Science
Covariance is a measure of the joint variation of two random variables.
- How it is used
- Connects joint variation to correlation, linear regression, causal diagrams, and instrumental-variable estimators.
- How deep it goes
- Defines algebraic identities and regression formulas, then applies them to causal graphs and instrumental variables without software implementation.
- Examples
- Uses confounder, mediator, and collider diagrams alongside regression calculations and an instrumental-variable covariance ratio.
- What you can do after
- Evaluate/understand covariance identities, interpret standardized correlations, and follow covariance-based regression and instrumental-variable calculations.
Read how Causal Inference for Data Science explains covariance →
Build a Robo-Advisor with Python (From Scratch)
Covariance is a measure of how two asset returns vary together, combining their volatilities with their correlation.
- How it is used
- Calculates portfolio volatility from asset weights and pairwise return relationships.
- How deep it goes
- Explains formulas, matrix construction, portfolio aggregation, and historical estimation, but defers sophisticated time-varying volatility methods.
- Examples
- Uses three-asset NumPy matrices, weighted portfolio volatility, and AAPL, FE, and WMT historical covariance estimates.
- What you can do after
- Apply covariance with NumPy or pandas to build covariance matrices and calculate portfolio standard deviation.
Read how Build a Robo-Advisor with Python (From Scratch) explains covariance →
Bayesian Optimization in Action
Covariance is a measure of how two random variables vary together.
- How it is used
- Uses covariance to jointly model multiple random variables with a multivariate Gaussian distribution.
- How deep it goes
- Defines covariance through matrix entries, distinguishing individual variances on the diagonal from pairwise relationships off the diagonal.
- Examples
- Uses a housing-price multivariate Gaussian and visualizations of samples, confidence intervals, and variable relationships.
- What you can do after
- Evaluate covariance matrices by identifying variable variances and pairwise relationships in multivariate Gaussian models.
Read how Bayesian Optimization in Action explains covariance →
Investing for Programmers
Covariance is a statistical measure of how two variables vary together, with positive values indicating movement in the same direction and negative values indicating opposite movement.
- How it is used
- Measures how asset returns move together when assessing relationships among investments in a portfolio.
- How deep it goes
- Defines covariance, demonstrates annualized calculation, and stops short of treating it as a strength measure.
- Examples
- Compares annualized covariance among Microsoft, Amazon, and Alphabet using return matrices and tables.
- What you can do after
- Apply it via pandas to calculate and interpret an annualized covariance matrix from asset log returns.
Data Without Labels
Covariance is a measure of how two variables vary together.
- How it is used
- Uses covariance as a Gaussian mixture parameter during probabilistic clustering.
- How deep it goes
- Defines covariance and places it in EM parameter updates, but does not develop its formula or numerical computation.
- Examples
- Uses a dataset of n items fitted with k Gaussian distributions and iteratively updated parameters.
- What you can do after
- Evaluate/understand covariance's role in fitting Gaussian mixture clusters through EM updates.
Also covered in
- Privacy-Preserving Machine Learning
- Machine Learning Algorithms in Depth
- Grokking BayesIn early access (MEAP)
What to know first
- normal distributionA normal distribution is a continuous probability distribution with a symmetric, bell-shaped density determined by its mean and variance.
- meanThe mean is a measure of central location equal to the arithmetic average of numerical observations, or the probability-weighted average of a random variable’s possible values.
- varianceVariance is the expected squared deviation of a random variable from its mean and measures the dispersion of its values.
- K-means clusteringK-means clustering is an algorithm that partitions data into a specified number of clusters by iteratively assigning observations to the nearest centroid and updating each centroid to the mean of its assigned observations.
Related concepts
- correlationcontrasts with · Correlation is a statistical association describing how variables vary together in direction or degree, without by itself establishing causation.
- Gaussian mixture modelused by · A Gaussian mixture model is a probabilistic model that represents a distribution as a weighted combination of Gaussian component distributions.
- instrumental variableused by · An instrumental variable is a variable that affects a treatment or exposure while influencing an outcome only through that treatment or exposure, under causal identifying assumptions.
- Pearson correlation coefficientused by · The Pearson correlation coefficient is a standardized measure of the strength and direction of the linear association between two numerical variables.
Questions about covariance
What is covariance?
Covariance is an unstandardized measure of how two random variables vary together relative to their means, indicating the direction of their linear association.
Which Manning books explain covariance?
Causal Inference for Data Science, Build a Robo-Advisor with Python (From Scratch), Bayesian Optimization in Action, Investing for Programmers and Data Without Labels.
What should I know before learning covariance?
Manning books that teach covariance usually introduce normal distribution, mean, variance and K-means clustering first.
What is the difference between covariance and correlation?
Covariance is an unstandardized measure of how two random variables vary together relative to their means, indicating the direction of their linear association. Correlation is a statistical association describing how variables vary together in direction or degree, without by itself establishing causation.
What kinds of covariance are there?
Kinds of covariance include autocovariance and conditional covariance.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




