def _centroids ( n_clusters : int , points : List [ List [ float ] ] ) -> List [ List [ float ] ] : k_means = KMeans ( n_clusters = n_clusters ) k_means . fit ( points ) closest , _ = pairwise_distances_argmin_min ( k_means . cluster_centers_ , points ) return list ( map ( list , np . array ( points ) [ closest . tolist ( ) ] ) )
python kmeans get the optimal cluster number
Return n_clusters centroids of points
def _centroids(n_clusters: int, points: List[List[float]]) -> List[List[float]]:
    """ Return n_clusters centroids of points
    """

    k_means = KMeans(n_clusters=n_clusters)
    k_means.fit(points)

    closest, _ = pairwise_distances_argmin_min(k_means.cluster_centers_, points)

    return list(map(list, np.array(points)[closest.tolist()]))