Variance, Covariance, and the Covariance Matrix
ã¡ãã¥ãŒã衚瀺ããã«ã¯ã¹ã¯ã€ãããŠãã ãã
Variance measures how much a variable deviates from its mean.
The formula for variance of a variable x is:
Var(x)=n1âi=1ânâ(xiââxË)2Covariance measures how two variables change together.
The formula for Covariance of variables x and y is:
Cov(x,y)=nâ11âi=1ânâ(xiââxË)(yiââyËâ)The covariance matrix generalizes covariance to multiple variables. For a dataset X with d features and n samples, the covariance matrix Σ is a dÃd matrix where each entry Σijâ is the covariance between feature i and feature j, computed with denominator nâ1 to be an unbiased estimator.
12345678910111213import 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)
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.
ãã£ãŒãããã¯ããããšãããããŸãïŒ
AIã«è³ªåãã
AIã«è³ªåãã
äœã§ã質åããããææ¡ããã質åã®1ã€ã詊ããŠãã£ãããå§ããŠãã ãã