scib_metrics.utils.silhouette_samples#
- scib_metrics.utils.silhouette_samples(X, labels, chunk_size=256, metric='euclidean', between_cluster_distances='nearest')[source]#
Compute the Silhouette Coefficient for each observation.
Implements
sklearn.metrics.silhouette_samples().Default parameters (‘euclidean’, ‘nearest’) match scIB implementation.
Additional options enable BRAS compatible usage (see
bras()documentation).- Parameters:
X (
ndarray) – Array of shape (n_cells, n_features) representing a feature array.labels (
ndarray) – Array of shape (n_cells,) representing label values for each observation.chunk_size (
int(default:256)) – Number of samples to process at a time for distance computation.metric (
Literal['euclidean','cosine'] (default:'euclidean')) – The distance metric to use. The distance function can be ‘euclidean’ (default) or ‘cosine’.between_cluster_distances (
Literal['nearest','mean_other','furthest'] (default:'nearest')) – Method for computing inter-cluster distances. - ‘nearest’: Standard silhouette (distance to nearest cluster) - ‘mean_other’: BRAS-specific (mean distance to all other clusters) - ‘furthest’: BRAS-specific (distance to furthest cluster)
- Return type:
- Returns:
silhouette scores array of shape (n_cells,)