@Rony, Yes, it is possible to specify your own distance function.
K-means clustering is one of the most widely used unsupervised machine learning algorithms which generates clusters of data based on the similarity between various data instances. K-means algorithm starts by randomly choosing a centroid value for each cluster. After that the algorithm iteratively performs three steps:
1. Find the Euclidean distance between each data instance and centroids of all the clusters
2. Assign the data instances to the cluster of the centroid with the nearest distance
3. Calculate new centroid values based on the mean values of the coordinates of all the data instances from the corresponding cluster.
Use this example to understand how to specify your own distance function-
from pyclustering.cluster.kmeans import kmeans
from pyclustering.utils.metric import type_metric, distance_metric
myfunc = lambda point1, point2: point1 + point2 + 2
metric = distance_metric(type_metric.USER_DEFINED, func=myfunc)
scenters = [[2.9, 3.4], [5.9, 6.7]];
kinstance = kmeans(sample, start_centers, metric=metric)
clstr = kinstance.get_clusters()