The Mahalanobis distance between x and y under a covariance matrix S is sqrt((x - y)^T S^-1 (x - y)). It is Euclidean distance after whitening the data, so it accounts for feature scales and for correlations between features.
Implement mahalanobis(x, y, cov).
x and y are 1-D arrays of length d. cov is a d by d matrix.cov must be symmetric and positive definite. Check this with a Cholesky factorization, and return the distance as a float.x and y must have length d, and cov must be d by d. Otherwise raise ValueError.cov that is not symmetric raises ValueError.cov that is not positive definite raises ValueError.If cov = L L^T is the Cholesky factorization, then z = L^-1 (x - y) is the whitened difference, and the distance is ||z||.
No results yet
Run your code to check it against the examples, or submit to run every test.