scanvi_explainer.scanvi_bootstrapper.SCANVIBoostrapper#
- class scanvi_explainer.scanvi_bootstrapper.SCANVIBoostrapper(model: SCANVI, n_bootstraps: int = 25)#
Methods table#
|
Calculate measurement for each boostrap run. |
|
Feature plot for bootstrapping |
|
Runner |
|
Save results to feather format. |
Methods#
- SCANVIBoostrapper.estimate(func_fn: Callable[[...], _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]], shap_values: list[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]]) ndarray#
Calculate measurement for each boostrap run.
- Parameters:
func_fn (Callable[..., ArrayLike]) – Stat function to call, i.e.: np.mean, np.median. The function must contain axis parameter.
shap_values (list[ArrayLike]) – SHAP values
- Returns:
Array of metric in format (classifier code, n_features, n_bootstraps)
- Return type:
np.ndarray
- SCANVIBoostrapper.feature_plot(shap_values: list, n_features: int = 10, metric_fn: ~collections.abc.Callable[[...], ~numpy._typing._array_like._SupportsArray[~numpy.dtype[~typing.Any]] | ~numpy._typing._nested_sequence._NestedSequence[~numpy._typing._array_like._SupportsArray[~numpy.dtype[~typing.Any]]] | bool | int | float | complex | str | bytes | ~numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes]] = <function mean>, kind: ~typing.Literal['boxplot', 'barplot'] = 'boxplot', gene_symbols: None | str = None, n_cols: int = 3, figsize: tuple[int, int] = (20, 20), return_fig: bool = False) Figure | None#
Feature plot for bootstrapping
- Parameters:
shap_values (list) – SHAP values
n_features (int) – Number of features to subset, by default 10
metric (Callable[..., ArrayLike]) – Statistical measurement of each boostrap, by default np.mean
kind (Literal["boxplot", "barplot"]) – Type of plot, by default “boxplot”
gene_symbols (None | str = None) – Column name in
varfor gene symbolsn_cols (int) – Number of columns for subplots, by default 3
figsize (tuple[int, int]) – Figure size, by default [20, 20]
return_fig (bool) – Flag to return figure object, by default False
- Returns:
Either plot or return figure object
- Return type:
Figure | None
- Raises:
ValueError – When specified plot kind is not supported
- SCANVIBoostrapper.save(shap_values: list[ndarray], filename: str)#
Save results to feather format.
- Parameters:
Examples
>>> lvae = scvi.model.SCANVI.load("...") >>> bootstrapper = SCANVIBoostrapper(lvae, n_bootstraps=10) >>> shap_values = bootstrapper.run(train_size=0.8, batch_size=64) >>> bootstrapper.save(shap_values, "./bootstrapped_shaps.feather")