sc_reconstruction.metrics.metric_knn_purity#

sc_reconstruction.metrics.metric_knn_purity(adata_pred, adata_pert_true, adata_ctrl, *, k=20, use_rep=None)[source]#

KNN purity of predicted perturbation in a (true-perturbed, control) pool.

Wraps sc_reconstruction.metrics.utils.knn_purity().

Parameters:
  • adata_pred (anndata.AnnData) – Predicted perturbed cells (the query).

  • adata_pert_true (anndata.AnnData) – Ground-truth perturbed cells (the positive pool).

  • adata_ctrl (anndata.AnnData) – Control cells (the negative pool).

  • k (int) – Number of neighbors. Returns a float in [0, 1]: 1.0 = all neighbors are true-perturbed, 0.5 = random baseline.

  • use_rep (str | None) – If given, use .obsm[use_rep] instead of .X (recommended; KNN in a learned latent space is far more meaningful than in raw expression).

Return type:

float