Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Variance, Covariance, and the Covariance Matrix | Section
Principal Component Analysis Fundamentals

bookVariance, Covariance, and the Covariance Matrix

Stryg for at vise menuen

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

Vælg det korrekte svar

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 5

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Sektion 1. Kapitel 5
some-alt