Mahalanobis Distance
Mahalanobis Distance
Mahalanobis Distance
com/kardi/)
MENU
Mahalanobis Distance
(index.html)
Mahalanobis Distance
Mahalanobis distance is also called quadratic distance . It measures the separation of two groups
of objects. Suppose we have two groups with means and , Mahalanobis distance is given by
the following
Formula
The data of the two groups must have the same number of variables (the same number of
columns) but not necessarily to have the same number of data (each group may have different
number of rows).
The code above requires computation of Covariance matrix, which code is given below
function C=Covariance(X)
% Return covariance given data matrix X (row = object, column = feature)
% @author: Kardi Teknomo
% http://people.revoledu.com/kardi/index.html
[n,k]=size(X);
Xc=X-repmat(mean(X),n,1); % centered data
C=Xc'*Xc/n; % covariance
Example
Suppose we have two groups of data, each of group consists of two variables (x, y). The scattered
The Mahalanobis distance is simply quadratic multiplication of mean difference and inverse of
pooled covariance matrix.
To perform the quadratic multiplication, check again the formula of Mahalanobis distance above.
When you get mean difference, transpose it, and multiply it by inverse pooled covariance. After
that, multiply the result with the mean difference again and you take the square root. The final
result of Mahalanobis distance is
Spreadsheet example (MS Excel) of this Mahalanobis computation can be downloaded here
(../../download/download.php?file=Mahalanobis) .
Use the interactive program below to compute Mahalanobis distance. If you like this program,
please recommend it to your friends.
How to use the program:
Input are two matrices name matrix A and matrix B that represent features coordinates of two
objects. The columns indicate the features, and the rows are the observations. The number of
features of the two objects must be equal (i.e. columns of matrix A = columns of matrix B). Each
matrix should have at least 2 rows and 1 column.
A matrix is sequence of numbers in a tabular format, inputted using the following format:
Validate your input before running the program. The initial input values are the example.
Refresh your browser to get back the example.
Input Matrix A
2, 2; 2, 5; 6, 5; 7, 3; 4, 7;
6, 4; 5, 3; 4, 6; 2, 5; 1, 3;
Input Matrix B
6, 5; 7, 4; 8, 7; 5, 6; 5, 4;
Clear Input
Validate Input
Get Mahalanobis Distance