KMeans.transform

KMeans.transform(data)[source]

Transforms the provided data into the cluster-distance space. That is, it returns the distance of each datapoint to each cluster centroid.

Parameters

data (Union[ndarray[Any, dtype[float32]], Tensor]) -- The data to transform.

Return type

Tensor

Returns

A tensor of shape [num_datapoints, num_clusters] with the distances to the cluster centroids.

Attention

When calling this function in a multi-process environment, each process receives only a subset of the predictions. If you want to aggregate predictions, make sure to gather the values returned from this method.