scparadise.scnoah.explain#
- scparadise.scnoah.explain(adata, layer=None, celltype=None, path_model='', num_cells=100, random_state=0, max_evals=2000, batch_size=256, prefix='pred_', device='auto', verbose=True, normalize=False)[source]#
Compute SHAP explanations for the predicted probability of one cell type.
- Parameters:
adata (anndata.AnnData) – AnnData containing predicted cell-type columns in .obs.
layer (str or None (default: None)) – Expression layer used as input to the model. If None, uses adata.X. The selected matrix must use the same preprocessing and gene space expected by the trained scAdam model.
celltype (str) – Cell type to explain. It must be present in a cell-type encoder stored in the trained model.
path_model (str or path-like) – Directory containing the trained scAdam model and model_v2.pth.
num_cells (int or None (default: 100)) – Maximum number of cells predicted as celltype to explain. If None, all matching cells are used. If it is greater than or equal to the number of matching cells, all matching cells are used.
random_state (int or None (default: 0)) – Random seed used for cell subsampling and SHAP sampling.
max_evals (int (default: 2000)) – Maximum number of model evaluations per explained sample used by SHAP. Must be at least 2 * n_features + 1 for permutation-based explainers.
batch_size (int (default: 256)) – Batch size used while evaluating the PyTorch model.
prefix (str (default: “pred_”)) – Prefix for prediction columns in adata.obs. For a model level cell_type, the function expects a column named pred_cell_type.
device ({"auto", "cpu", "cuda", "cuda:N"} (default: "auto")) – Device used for model inference. auto selects CUDA if available.
verbose (bool (default: True)) – Print status messages.
normalize (bool (default: False)) – If True, apply per-gene min-max normalization over the selected cells. Keep False when the selected layer has already been preprocessed identically to the model training input.
- Returns:
SHAP values explaining the model probability assigned to celltype. The explanation has one scalar model output per cell and one SHAP value per input gene.
- Return type:
shap.Explanation