MATLAB K-Means Algorithm with Arbitrary Distance Function (Chebyshev Distance)
If you don't have any specific reason for using K-means and can handle hierarchical agglomeration clustering, you can use clusterdata
. It also works with Chebyshev distance.
source to share
This might help you.
http://www.purplemath.com/modules/distform.htm
http://www.mathwarehouse.com/algebra/distance_formula/index.php
In addition, there is another concept of calculating the distance between two points called " City blocking ), which is something analogous to the distance ABSOLUTE of two points. Example:
Distance, d = |x2-x1| + |y2-y1|
OR d = |x1-x2| + |y1-y2|
(Since the results are absolute, any shape will do) Check and try.
source to share
The Chebyshev distance is equivalent to infinity norm . This should help you find Matlab documentation.
I have read the documentation from K-means in Matlab and there is no mention of extending the function with additional distance norms. So you should probably implement it yourself.
Another option is to look for a mapping from Linf to L2, but that doesn't exist. I'm sorry.
source to share
Second, hierarchical clustering can be more according to what you want, since you can easily specify the distance function.
However, if you really want to use k-means, you can create a distance matrix using whatever function you like and break your object space distance matrix with SVD. Then execute k-means in a new object space represented by dozens of SVDs.
I don't know that K-means will converge with other distance marks.
source to share
I have created MATLAB code for very simple K-Means that accepts an arbitrary distance function.
You can get the code in the GitHub Repository .
Below are the results for three different distance metrics:
source to share