scib.metrics.silhouette

scib.metrics.silhouette(adata, label_key, embed, metric='euclidean', scale=True)

Average silhouette width (ASW)

Wrapper for sklearn silhouette function values range from [-1, 1] with

  • 1 indicates distinct, compact clusters

  • 0 indicates overlapping clusters

  • -1 indicates core-periphery (non-cluster) structure

By default, the score is scaled between 0 and 1 (scale=True).

Parameters:
  • label_key – key in adata.obs of cell labels

  • embed – embedding key in adata.obsm, default: ‘X_pca’

  • metric – type of distance metric to use for the silhouette scores

  • scale – default True, scale between 0 (worst) and 1 (best)

The function requires an embedding to be stored in adata.obsm and can only be applied to feature and embedding integration outputs. Please note, that the metric cannot be used to evaluate kNN graph outputs. See User Guide for more information on preprocessing.

Examples

# full feature output
scib.pp.reduce_data(
    adata, n_top_genes=2000, batch_key="batch", pca=True, neighbors=False
)
scib.me.silhouette(adata, label_key="celltype", embed="X_pca")

# embedding output
scib.me.silhouette(adata, label_key="celltype", embed="X_emb")