B_HIT.st.tl.ClusterAutoK#
- class B_HIT.st.tl.ClusterAutoK(n_clusters, max_runs=5, convergence_tol=0.01, model_class=None)#
Identify the best candidates for the number of clusters.
Attributes table#
The number of clusters with the highest silhouette_scores. |
|
Methods table#
Attributes#
- ClusterAutoK.best_k#
The number of clusters with the highest silhouette_scores.
Methods#
- ClusterAutoK.fit(adata, use_rep='X_cellcharter', verbose=True)#
Fit the clustering model with a range of cluster numbers and calculate silhouette scores.
- ClusterAutoK.predict(adata, use_rep=None, k=None, store_labels=False, store_column='predicted_labels')#
Predict cluster labels for the data in the given representation and optionally store the labels in
adata.obs.- Parameters:
adata (
AnnData) – AnnData object containing the dataset. The data to be clustered is accessed fromadata.obsmoradata.X.use_rep (
Optional[str] (default:None)) – The key inadata.obsmto use as the data representation for clustering. IfNone, the method defaults to: -adata.obsm['X_cellcharter'], if it exists, or -adata.Xas a fallback.k (
Optional[int] (default:None)) – The number of clusters to predict labels for. If not specified, the best number of clusters (self.best_k) will be used. Must be one of the values inself.n_clusters.store_labels (
bool(default:False)) – IfTrue, the predicted labels will be stored inadata.obsunder the column name specified bystore_column. Default isFalse.store_column (
str(default:'predicted_labels')) – The name of the column inadata.obswhere predicted labels will be stored ifstore_labelsisTrue. Default is'predicted_labels'.
- Return type:
Categorical- Returns:
pd.Categorical A pandas Categorical object containing the predicted cluster labels. The labels are integers ranging from 0 to
k-1.- Raises:
AssertionError – If
kis provided and it is not inself.n_clusters.
Notes
This method relies on the clustering models stored in
self.best_modelsfor label prediction.Ensure that the model for the desired
kclusters has been fitted prior to calling this method.