python/methylnet/interpretation_classes.py
def return_shapley_scores(self, test_methyl_array, n_samples, n_outputs, shap_sample_batch_size=None, top_outputs=None): # split up into multiple methods
        """Generate explanations for individual predictions, in the form of SHAPley scores for supplied test data.
        One SHAP score per individual prediction per CpG, and more if multiclass/output.
        For multiclass/multivariate outcomes, scores are generated for each outcome class.

        Parameters
        ----------
        test_methyl_array : type
            Testing MethylationArray.
        n_samples : type
            Number of SHAP score samples to produce. More SHAP samples provides convergence to correct score.
        n_outputs : type
            Number of outcome classes.
        shap_sample_batch_size : type
            If not None, break up SHAP score sampling into batches of this size to be averaged.
        top_outputs : type
            For deep explainer, limit number of output classes due to memory consumption.


        Returns
        -------
        type
            Description of returned object.

        """
        n_batch = 1
        if shap_sample_batch_size != None and self.method != 'deep': #  and not feature_selection
            n_batch = int(n_samples/shap_sample_batch_size)
            n_samples = shap_sample_batch_size
        test_arr = test_methyl_array.return_raw_beta_array()
        shap_values = np.zeros((top_outputs if top_outputs != None else n_outputs,)+test_arr.shape)
        additional_opts = {}
        if self.method != 'kernel':
            additional_opts['ranked_outputs']=top_outputs
            test_arr=to_tensor(test_arr) if not self.cuda else to_tensor(test_arr).cuda()
        for i in range(n_batch):
            click.echo("Batch {}".format(i))
            print("Batch {}".format(i))
            shap_values += return_shap_values(test_arr, self.explainer, self.method, n_samples, additional_opts)
        shap_values/=float(n_batch)

        self.shap_values = shap_values
Generate explanations for individual predictions, in the form of SHAPley scores for supplied test data.
        One SHAP score per individual prediction per CpG, and more if multiclass/output.
        For multiclass/multivariate outcomes, scores are generated for each outcome class.

        Parameters
        ----------
        test_methyl_array : type
            Testing MethylationArray.
        n_samples : type
            Number of SHAP score samples to produce. More SHAP samples provides convergence to correct score.
        n_outputs : type
            Number of outcome classes.
        shap_sample_batch_size : type
            If not None, break up SHAP score sampling into batches of this size to be averaged.
        top_outputs : type
            For deep explainer, limit number of output classes due to memory consumption.


        Returns
        -------
        type
            Description of returned object.

        
Generate explanations for individual predictions, in the form of SHAPley scores for supplied test data.
One SHAP score per individual prediction per CpG, and more if multiclass/output.
For multiclass/multivariate outcomes, scores are generated for each outcome class.

Parameters



Returns

type
Description of returned object.
Generate explanations for individual predictions in the form of SHAPley scores for supplied test data . One SHAP score per individual prediction per CpG and more if multiclass / output . For multiclass / multivariate outcomes scores are generated for each outcome class . Parameters Returns type Description of returned object .
def return_shapley_scores(self, test_methyl_array, n_samples, n_outputs, shap_sample_batch_size=None, top_outputs=None): 
        n_batch = 1
        if shap_sample_batch_size != None and self.method != 'deep': 
            n_batch = int(n_samples/shap_sample_batch_size)
            n_samples = shap_sample_batch_size
        test_arr = test_methyl_array.return_raw_beta_array()
        shap_values = np.zeros((top_outputs if top_outputs != None else n_outputs,)+test_arr.shape)
        additional_opts = {}
        if self.method != 'kernel':
            additional_opts['ranked_outputs']=top_outputs
            test_arr=to_tensor(test_arr) if not self.cuda else to_tensor(test_arr).cuda()
        for i in range(n_batch):
            click.echo("Batch {}".format(i))
            print("Batch {}".format(i))
            shap_values += return_shap_values(test_arr, self.explainer, self.method, n_samples, additional_opts)
        shap_values/=float(n_batch)
        self.shap_values = shap_values
def return_shapley_scores ( self , test_methyl_array , n_samples , n_outputs , shap_sample_batch_size = None , top_outputs = None ) : n_batch = 1 if shap_sample_batch_size != None and self . method != 'deep' : n_batch = int ( n_samples / shap_sample_batch_size ) n_samples = shap_sample_batch_size test_arr = test_methyl_array . return_raw_beta_array ( ) shap_values = np . zeros ( ( top_outputs if top_outputs != None else n_outputs , ) + test_arr . shape ) additional_opts = { } if self . method != 'kernel' : additional_opts [ 'ranked_outputs' ] = top_outputs test_arr = to_tensor ( test_arr ) if not self . cuda else to_tensor ( test_arr ) . cuda ( ) for i in range ( n_batch ) : click . echo ( "Batch {}" . format ( i ) ) print ( "Batch {}" . format ( i ) ) shap_values += return_shap_values ( test_arr , self . explainer , self . method , n_samples , additional_opts ) shap_values /= float ( n_batch ) self . shap_values = shap_values
Generate explanations for individual predictions, in the form of SHAPley scores for supplied test data.
Generate explanations for individual predictions in the form of SHAPley scores for supplied test data .
# split up into multiple methods """Generate explanations for individual predictions, in the form of SHAPley scores for supplied test data.
        One SHAP score per individual prediction per CpG, and more if multiclass/output.
        For multiclass/multivariate outcomes, scores are generated for each outcome class.

        Parameters
        ----------
        test_methyl_array : type
            Testing MethylationArray.
        n_samples : type
            Number of SHAP score samples to produce. More SHAP samples provides convergence to correct score.
        n_outputs : type
            Number of outcome classes.
        shap_sample_batch_size : type
            If not None, break up SHAP score sampling into batches of this size to be averaged.
        top_outputs : type
            For deep explainer, limit number of output classes due to memory consumption.


        Returns
        -------
        type
            Description of returned object.

        """ #  and not feature_selection
self
test_methyl_array
n_samples
n_outputs
shap_sample_batch_size
top_outputs