Mahalanobis distance in Kmeans Clustering using OpenCV

I made a Kmeans cluster and discovered cluster centers using the OpenCV C ++ API.

kmeans(data_points, clusterCount, labels, TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0), 3, KMEANS_PP_CENTERS, cluster_centers); 

Then I use the Euclidean distance to find the closest cluster for a new data point for all cluster centers .

 int distance = find_EucledianDist(new_datapoint, cluster_centers); 

How to use Mahalanobis Distance instead of Euclidean Distance ? I know that I need to calculate the covariance matrix and invert it and find the Mahalanobis distance.

However, I don’t know how I do it and in which ORDER (find the Kova matrix, the inverted matrix from which the data / matrix is)?

+6
source share

Source: https://habr.com/ru/post/909553/


All Articles