scanvi_explainer.scanvi_deep.SCANVIDeep#
- class scanvi_explainer.scanvi_deep.SCANVIDeep(model: SCANVI, train_size: float = 0.8, batch_size: int = 128)#
SCANVIDeep is an extension of DeepExplainer [Lundberg and Lee, 2017] for models trained using SCANVI [Xu et al., 2021].
- Parameters:
Explainer – Main Explainer class from shap package
Methods table#
|
Add handles to all non-container layers in the model. |
|
|
|
Explains a single row and returns the tuple (row_values, row_expected_values, row_mask_shapes, main_effects). |
|
|
|
Load an Explainer from the given file stream. |
Helper function to track CUDA memory usage. |
|
|
Removes the x and y attributes which were added by the forward handles Recursively searches for non-container layers |
|
Write the explainer to the given file stream. |
|
Estimate SHAP values |
|
Determines if this explainer can handle the given model. |
Methods#
- SCANVIDeep.add_handles(model, forward_handle, backward_handle)#
Add handles to all non-container layers in the model. Recursively for non-container layers
- SCANVIDeep.add_target_handle(layer)#
- SCANVIDeep.explain_row(*row_args, max_evals, main_effects, error_bounds, outputs, silent, **kwargs)#
Explains a single row and returns the tuple (row_values, row_expected_values, row_mask_shapes, main_effects).
This is an abstract method meant to be implemented by each subclass.
- Returns:
A tuple of (row_values, row_expected_values, row_mask_shapes), where row_values is an array of the attribution values for each sample, row_expected_values is an array (or single value) representing the expected value of the model for each sample (which is the same for all samples unless there are fixed inputs present, like labels when explaining the loss), and row_mask_shapes is a list of all the input shapes (since the row_values is always flattened),
- Return type:
- SCANVIDeep.gradient(idx, input_x, input_batch)#
- classmethod SCANVIDeep.load(in_file, model_loader=<bound method Model.load of <class 'shap.models._model.Model'>>, masker_loader=<bound method Serializable.load of <class 'shap.maskers._masker.Masker'>>, instantiate=True)#
Load an Explainer from the given file stream.
- Parameters:
in_file (The file stream to load objects from.)
- SCANVIDeep.memory_stats()#
Helper function to track CUDA memory usage.
- SCANVIDeep.remove_attributes(model)#
Removes the x and y attributes which were added by the forward handles Recursively searches for non-container layers
- SCANVIDeep.save(out_file, model_saver='.save', masker_saver='.save')#
Write the explainer to the given file stream.
- static SCANVIDeep.supports_model_with_masker(model, masker)#
Determines if this explainer can handle the given model.
This is an abstract static method meant to be implemented by each subclass.