As suggested in this answer /a/74232665/4042725,
is it possible to define a custom distance metric in the _transform method of a custom kmeans class inheriting sklearn’s Kmeans class?
class custom_Kmeans(sklearn.cluster.Kmeans):
def _tranform(self):
<define custom metric here>
a = custom_Kmeans()
a.fit()
Context:
What I am trying to do is inherit sklearn’s k-means class to write my own distance metric in its _tranform method as suggested by this answer here:
/a/74232665/4042725
When looking at sklearn’s Kmeans source, it seems to me that this shouldn’t make a difference to the clustering it self because the workhorse of this class is the fit() method whereas the transform method is only called in the fit_tranform() which is just fit(X)._transform(X)
Am I wrong? Will redefining a _tranform() method make any difference to the clustering?
How else can I make use of a different distance metric in kmeans to cluster the points using this distance metric?