def decision_function(self, X):
"""Compute the distances to the nearest centroid for
an array of test vectors X.
Parameters
----------
X : array-like, shape = [n_samples, n_features]
Returns
-------
C : array, shape = [n_samples]
"""
from sklearn.metrics.pairwise import pairwise_distances
from sklearn.utils.validation import check_array, check_is_fitted
check_is_fitted(self, 'centroids_')
X = check_array(X, accept_sparse='csr')
return pairwise_distances(X, self.centroids_,
metric=self.metric).min(axis=1)
评论列表
文章目录