tomodrgn.analysis.cluster_kmeans#
- cluster_kmeans(z: ndarray, n_clusters: int, random_state: int | RandomState | None = None, on_data: bool = True, reorder: bool = True, **kwargs: Any) tuple[ndarray, ndarray] [source]#
Cluster latent embeddings using k-means clustering. If reorder=True, reorders clusters according to agglomerative clustering of cluster centers
- Parameters:
z – array of latent embeddings, shape (nptcls, zdim)
n_clusters – number of clusters to form, passed to sklearn.cluster.KMeans
random_state – random state for reproducible runs, passed to sklearn.cluster.KMeans
on_data – adjust cluster centers to nearest point on the data manifold z
reorder – reorder clusters according to agglomerative clustering of cluster centers
kwargs – additional key word arguments passed to sklearn.cluster.KMeans
- Returns:
array of cluster labels shape (len(z)), array of cluster centers shape (n_clusters, zdim)