mbfmri.utils.explainer¶
Explainer employs SHAP to interpret MVPA models.
- class mbfmri.utils.explainer.Explainer(shap_explainer='deep', shap_n_background=100, shap_n_sample=100, include_trainset=True, pval_threshold=0.05, voxel_mask=None)¶
Bases:
objectExplainer interprets Tensorflow Keras models based on SHAP by Lundberg et al., 2017. This module is aiming to make voxel-level interpretation of MVPA models.
By SHAP, Feature attribution of each voxel is calculated for sample from input distribution.
The weights are defined as a linear slope of activity-attribution for each voxel, which corresponds with reading coefficients in one-layer linear models.
In general such activityy-attribution relation ship is similar to each kernel in kernel regression. Here, for intuitivity and simplicity, only linear kernel is considered.
The sampled SHAP values can be saved as well, allowing the further analysis on how voxel activities modulate the corresponding voxel attribution.
- Parameters
shap_explainer (str, default=”deep”) – Name for SHAP algorithm to interprete Keras models. Two algorithms, “deep” and “gradient,” are in options. Please refer to the package repo (https://github.com/slundberg/shap/),
shap_n_background (int, default=100) – Number of background to be used as reference in SHAP calculation. The number of sample will be retrieved from the given input data.
shap_n_sample (int, default=100) – Number of sample to be used as input to explain by SHAP. The number of sample will be retrieved from the given input data. The SHAP values for each feature and each sample will be obtained.
include_trainset (bool, default=True) – Iindicate if including train set in the input pool from which the backgrounds and sample will be retrieved.
pval_threshold (float, default=0.05) – Threshold value for false detection rate (FDR) correction. FDR will be done for threshold out insignificantly estimated slopes in activity-attribution.
voxel_mask (nibabel.Nifti1Image, default=None) – Nii object for mask inputs. It is used for flattening input data if the input is provided in 3D shape (when CNN is used).