English translation
Compute variances
AI Article Decision Snapshot
Turn the lesson into workflow, model, budget, and security checks before choosing tools.
Use this quick snapshot before leaving the article. It keeps the next search tied to practical AI software, model/API, cost, privacy, and implementation questions.
Workflow fit
Identify the real job behind the article: coding, research, document review, support, analytics, content, or internal automation.
Model or tool decision
Decide whether the next step is a software shortlist, an AI tool comparison, an API platform choice, or a model benchmark.
Budget and usage signal
Estimate seats, API calls, prompt volume, retries, review time, and fallback work before assuming the workflow is cheap.
Security and privacy review
Check whether source code, customer data, private documents, prompts, logs, or embeddings will enter the AI workflow.
Covariance measures whether two variables change together; correlation removes the influence of scale. A high correlation does not imply causation.
I always start with a scatter plot. A single correlation coefficient cannot reveal outliers, nonlinear relationships, or subgroup structures.
In the previous article, we explored the properties of variance, learning how to quantify the dispersion of a single random variable. This article continues our discussion of key concepts in probability theory: covariance and correlation—essential tools for analyzing relationships between random variables, widely applied in machine learning and data analysis.
Definition of Covariance
Covariance is a measure describing the linear relationship between two random variables. Given random variables and , their covariance is defined as:
When learning covariance and correlation, first assess whether the two variables move in the same direction; then examine the sign and magnitude of the standardized correlation coefficient.
This formula helps us intuitively understand covariance: it quantifies how deviations of one variable from its mean relate to deviations of the other variable from its mean.
Properties of Covariance
-
Interpretation of Sign:
- If , and are positively associated: when one tends to increase, the other tends to increase as well.
- If , and are negatively associated.
- If , there is no linear relationship between them.
-
Unit Sensitivity:
- Covariance carries units equal to the product of the units of and , making interpretation less intuitive.
Example
Suppose and represent a student’s study time (in hours) and exam score (in points), respectively. Observed data are shown below:
| Study Time () | Exam Score () |
|---|---|
| 1 | 50 |
| 2 | 55 |
| 3 | 60 |
| 4 | 70 |
| 5 | 75 |
First, compute the expectations:
Then apply the covariance formula:
import numpy as np
X = np.array([1, 2, 3, 4, 5])
Y = np.array([50, 55, 60, 70, 75])
cov_xy = np.cov(X, Y)[0][1] # Extract covariance between X and Y
cov_xy
The computed covariance is positive, indicating a positive linear association between study time and exam score.
Definition and Computation of Correlation
Correlation is the standardized version of covariance—designed specifically to eliminate unit dependence. It is typically quantified using the Pearson correlation coefficient, defined as:
When reading “Covariance and Correlation,” begin by reviewing the tasks, core concepts, exercises, and decision points illustrated in the accompanying figures—then return to the main text to fill in details. This approach helps you quickly identify which real-world scenarios this content applies to.
where and denote the variances of and , respectively.
Properties of Correlation
- Range:
- The correlation coefficient always lies in the interval .
- indicates perfect positive linear correlation; , perfect negative linear correlation; , no linear correlation.
Example
Continuing with the earlier example, we compute the Pearson correlation coefficient between study time and exam score.
# Compute variances
var_x = np.var(X)
var_y = np.var(Y)
# Compute correlation coefficient
correlation = cov_xy / (np.sqrt(var_x) * np.sqrt(var_y))
correlation
Running this code yields the correlation coefficient . Suppose the result is : this indicates a strong positive linear relationship between study time and exam performance.
When reviewing “Covariance and Correlation,” place key concepts, procedural steps, and observable outcomes on the same page for efficient revision.
When practicing “Covariance and Correlation,” write input conditions, processing steps, and observable outcomes together—making future review straightforward.
Summary
In this article, we introduced covariance and correlation, fundamental tools for investigating relationships between two random variables. By computing covariance and correlation coefficients, we gain deeper insight into underlying data structure and dependencies—laying essential groundwork for the next topic: the Law of Large Numbers.
In the following article, we will delve into the Law of Large Numbers, exploring how sample means converge toward the population mean as sample size increases. We hope you’ll apply these concepts confidently to analyze real-world problems!
Apply This Lesson
Turn this article into AI software, model, API, and security decisions.
English Article FAQ
Use this article as evidence before choosing AI tools
How should I use this AI Tutorials article?
Use it as the implementation or learning layer, then connect the idea to AI software buyer guides, tool comparisons, benchmarks, API choices, and security checks before making a production decision.
Is this English article different from the Chinese original?
The English edition is localized for global AI readers while preserving the original diagrams, screenshots, prompts, code examples, and source context from the Chinese article.
What should I read after Compute variances?
Continue with AI Software Buyer Guides, AI Tools Workbench, Best AI Coding Agents, AI Model Benchmarks, OpenAI vs Anthropic API, or LLM Security Tools depending on the decision you need to make.
Can this article alone choose an AI product or model?
No. Treat the article as evidence and context, then validate fit with pricing, privacy requirements, integration effort, benchmark results, workflow tests, and fallback planning.
Continue