
Full Clustering Performance Evaluation
Source:R/03_metrics_clustering.R
evaluate_clustering_metrics.RdEvaluates both unsupervised cluster separation (ASW, DB, Neighborhood Purity, CDI) and supervised concordance against ground truth labels (ARI, NMI).
Usage
evaluate_clustering_metrics(
data,
cluster_info = NULL,
pred_clusters = NULL,
dist_mat = NULL,
cell_types = NULL,
ref_data = NULL,
ref_cell_types = NULL,
batch_info = NULL,
threads = 1L
)Arguments
- data
Count or normalized matrix (features x cells).
- cluster_info
Cluster or cell type labels.
- pred_clusters
Optional predicted cluster labels (if different from ground truth). If NULL, k-means is automatically run.
- dist_mat
Optional precomputed distance matrix.
- cell_types
Optional alias for cluster_info.
- ref_data
Optional reference data to compute reference clustering quality.
- ref_cell_types
Optional reference cell type labels (if ref_data has different cells than data).
- batch_info
Optional batch labels per cell passed to
calc_cdi.- threads
Integer number of parallel CPU threads passed to
calc_cdi(default1L).
Value
A named list of clustering quality and cluster concordance metrics (keys present depend on inputs):
silhouette_simMean silhouette width across ground-truth labels in simulated data.
silhouetteAlias of
silhouette_sim.davies_bouldinDavies-Bouldin index computed on simulated data.
davies_bouldin_simAlias of
davies_bouldin.neighborhood_purityMean k-nearest-neighbor label purity in simulated data.
silhouette_refMean silhouette width in reference data (present when
ref_datais supplied).davies_bouldin_refDavies-Bouldin index in reference data (present when
ref_datais supplied).cdiNormalized CDI-AIC score from
calc_cdi(when finite).CDI_AICAlias of
cdi.CDI_BICNormalized CDI-BIC score from
calc_cdi(when finite).ariAdjusted Rand Index between
pred_clusters(or k-means clusters) andcluster_info.ARIAlias of
ari.nmiNormalized Mutual Information between
pred_clustersandcluster_info.NMIAlias of
nmi.
Examples
data <- matrix(stats::rpois(200, lambda = 3), 20, 10)
cl <- factor(rep(c("A", "B"), each = 5))
dist_mat <- stats::dist(t(data))
evaluate_clustering_metrics(data, cl)
#> $silhouette_sim
#> [1] -0.04216351
#>
#> $silhouette
#> [1] -0.04216351
#>
#> $davies_bouldin
#> [1] 2.338027
#>
#> $davies_bouldin_sim
#> [1] 2.338027
#>
#> $neighborhood_purity
#> [1] 0.42
#>
#> $cdi
#> [1] 4.185484
#>
#> $CDI_AIC
#> [1] 4.185484
#>
#> $CDI_BIC
#> [1] 4.306519
#>
#> $ari
#> [1] 0
#>
#> $ARI
#> [1] 0
#>
#> $nmi
#> [1] 0.1470822
#>
#> $NMI
#> [1] 0.1470822
#>