Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Variance, Covariance, and the Covariance Matrix | Mathematical Foundations of PCA
Principal Component Analysis in Python

bookVariance, Covariance, and the Covariance Matrix

メニューを表示するにはスワイプしてください

Note
Definition

Variance measures how much a variable deviates from its mean.

The formula for variance of a variable xx is:

Var(x)=1ni=1n(xixˉ)2\mathrm{Var}(x) = \frac{1}{n} \sum_{i=1}^n (x_i - \bar{x})^2
Note
Definition

Covariance measures how two variables change together.

The formula for Covariance of variables xx and yy is:

Cov(x,y)=1n1i=1n(xixˉ)(yiyˉ)\mathrm{Cov}(x, y) = \frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})(y_i - \bar{y})

The covariance matrix generalizes covariance to multiple variables. For a dataset XX with dd features and nn samples, the covariance matrix Σ\Sigma is a d×dd \times d matrix where each entry Σij\Sigma_{ij} is the covariance between feature ii and feature jj, computed with denominator n1n-1 to be an unbiased estimator.

12345678910111213
import numpy as np # Example data: 3 samples, 2 features X = np.array([[2.5, 2.4], [0.5, 0.7], [2.2, 2.9]]) # Center the data (subtract mean) X_centered = X - np.mean(X, axis=0) # Compute covariance matrix manually cov_matrix = (X_centered.T @ X_centered) / X_centered.shape[0] print("Covariance matrix:\n", cov_matrix)
copy

In the code above, you manually center the data and compute the covariance matrix using matrix multiplication. This matrix captures how each pair of features varies together.

question mark

Which statement accurately describes the relationship between variance, covariance, and the covariance matrix

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 2.  1

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 2.  1
some-alt