In statistics, Variance measures data dispersion around a mean.
It is a descriptive statistical measure that quantifies how far individual data points deviate from the mean of a dataset.
Depending on the fact that the dataset represent a full population or a sample, the formula is:
- $\sigma^2 = \frac{\sum_{i=1}^{N} (x_i - \mu)^2}{N}$ for the entire population
- $s^2 = \frac{\sum_{i=1}^{n} (x_i - \bar{x})^2}{n - 1}$ for a sample
In numpy, it can be implemented as:
((x - x.mean(axis=0))**2).mean(axis=0)In PyTorch, it can be implemented as:
((x - x.mean(dim=0))**2).mean(dim = 0)The squared root of variance is standard deviation $\sigma$.
This concept of variance must not be confused with the machine learning concept of variance.