k-means clustering: distance from a certain datapoint to his next centroid


is their a way to get a table of distances out of the k-means (predictor) which contains the distance of datapoints? These datapoints are applied to to a k-means Modell (Trainer) and now I want the distance given from the predictor if possible.

Hi @Aliasing

The Cluster Assigner node does not provide the distances to the nearest cluster center.

The k-Means node does provide the cluster centers (second port), so you could compute the euclidean distance according to the cluster that get assigned by the Cluster Assigner node.

Hi oole,

thx for answering. I understand your proposal and want to realise it in KNIME. Problem is what I do after I connected the “Numeric Distances” node with the Output of the Trainer (second port)? I am sure I need on the one Hand the coordinates of the centroids and also the coordinates of the datapoint and additionally its assigned cluster thus KNIME knows with which cluster it builds the distance of a certain point.

I built a workflow which calculates the nearest neighbour and its distance, using the Numerical Distances and the Similarity Search nodes. You can see how i feed the cluster prototypes to the Similarity Search node.


You can download it here: kmeans_distance.knwf (18.3 KB)

Edit: typo


Thanks, that gave me really nice results for my anomaly detection algorithm :slight_smile:

I’m happy that it worked out.:tada:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Check out some new k-means components that address this issue: