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

bookVariance, Covariance, and the Covariance Matrix

Scorri per mostrare il menu

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

Seleziona la risposta corretta

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 5

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Sezione 1. Capitolo 5
some-alt