scikit-learn-contrib / scikit-learn-extra

scikit-learn contrib estimators
https://scikit-learn-extra.readthedocs.io
BSD 3-Clause "New" or "Revised" License
185 stars 42 forks source link

K-medoids with non symmetric matrix #132

Closed Tambup closed 2 years ago

Tambup commented 2 years ago

I have a piece of code like this:

result = KMedoids(n_clusters=n_clusters, max_iter=30, method='pam', metric='precomputed').fit(d_matx)

where d_matx is the distance matrix. My question is: if d_matx is a non symmetric matrix, does the result makes sense? Or it works only with symmetric matrix?

Thanks.

TimotheeMathieu commented 2 years ago

Yes it is only for symmetric matrix because a distance is necessarily symmetric. It is just the fact that the distance from x to y is equal to the distance from y to x. The symmetry is used in the optimization algorithm hence it does not make sense to use asymmetric matrix in my opinion.

Tambup commented 2 years ago

Ok, perfect.