pertpy.tools.PerturbationComparison#

class PerturbationComparison[source]#

Comparison between real and simulated perturbations.

Methods table#

compare_classification(real, simulated, control)

Compare classification accuracy between real and simulated perturbations.

compare_knn(real, simulated[, control, ...])

Calculate proportions of real perturbed and control data points for simulated data.

Methods#

PerturbationComparison.compare_classification(real, simulated, control, clf=None)[source]#

Compare classification accuracy between real and simulated perturbations.

Trains a classifier on the real perturbation data & the control data and reports a normalized classification accuracy on the simulated perturbation.

Parameters:
  • real (ndarray) – Real perturbed data.

  • simulated (ndarray) – Simulated perturbed data.

  • control (ndarray) – Control data

  • clf (ClassifierMixin | None, default: None) – sklearn classifier to use, sklearn.linear_model.LogisticRegression if not provided.

Return type:

float

PerturbationComparison.compare_knn(real, simulated, control=None, use_simulated_for_knn=False, n_neighbors=20, random_state=0, n_jobs=1)[source]#

Calculate proportions of real perturbed and control data points for simulated data.

Computes proportions of real perturbed, control and simulated (if use_simulated_for_knn=True) data points for simulated data. If control (C) is not provided, builds the knn graph from real perturbed + simulated perturbed.

Parameters:
  • real (ndarray) – Real perturbed data.

  • simulated (ndarray) – Simulated perturbed data.

  • control (ndarray | None, default: None) – Control data

  • use_simulated_for_knn (bool, default: False) – Include simulted perturbed data (simulated) into the knn graph. Only valid when control (control) is provided.

  • n_neighbors (int, default: 20) – Number of neighbors to use in k-neighbor graph.

  • random_state (int, default: 0) – Random state used for k-neighbor graph construction.

  • n_jobs (int, default: 1) – Number of cores to use. Defaults to -1 (all).

Return type:

dict[str, float]