Calculating Mahalanobis parameters from x data

85 Views Asked by At

Roughly speaking, the Mahalanobis distance $d(x) = \sqrt{(x - \mu)^T * \Sigma^{-1} * (x - \mu)}$ is the distance between a multivariate Gaussian distribution ($\mu$, $\Sigma$) and a point. If the Gaussian distribution represents a class, we can classify new points by choosing the class with the minimum distance.

I'm giving an N*D trained data as class data, and I need to calculate mu and inverse of Sigma.

Estimates the parameters for the mahalanobis distance for a specific class.
:param x_class: a (n x d) numpy array, containing n samples with d features coresponding to a specific class.
:return: tuple of (mu, inv_Si)
    where mu     is a (d,)   numpy array
          inv_Si is a (d, d) numpy array.