Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

K-means Clustering in Opencv & python: Is there any option to cluster in mahalanobis distance?

Is there any option to cluster in Mahalanobis distance in or can easily be used with the Opencv

cv2.kmeans

function in python?

like image 782
brainless Avatar asked Nov 17 '25 05:11

brainless


1 Answers

The documentation shows no arguments in the constructor or otherwise that can change the distance metric. In fact, visiting the kmeans.cpp source on git, you can see from lines like this that Euclidean distance (i.e., normL2Sqr) is hardcoded:

const double dist = normL2Sqr(sample, center, dims);

If you're open to using sklearn scipy for your kmeans, you can look at this question to see how to specify your own distance metric.

like image 118
TayTay Avatar answered Nov 18 '25 18:11

TayTay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!