python/methylnet/interpretation_classes.py
def regressor_assign_scores_to_shap_data(self, test_methyl_array, n_top_features, cell_names=[]):
        """Assigns the SHAP scores to a SHAPley data object, populating nested dictionaries (containing multioutput and single output regression-individual information) with SHAPley information and "top CpGs".

        Parameters
        ----------
        test_methyl_array : type
            Testing MethylationArray.
        n_top_features : type
            Number of top SHAP scores to use for a subdict called "top CpGs"
        cell_names : type
            If multi-output regression, create separate regression classes to access for all individuals.

        """
        n_classes = (self.shap_values.shape[0] if len(self.shap_values.shape) == 3 else 0)

        cpgs=test_methyl_array.return_cpgs()

        shapley_data = ShapleyData()

        self.cpg_global_shapley_scores = (np.abs(self.shap_values).mean(0).mean(0) if n_classes else np.abs(self.shap_values).mean(0))
        shapley_data.add_global_importance(self.cpg_global_shapley_scores,cpgs, n_top_features)
        if n_classes:
            for i in range(self.shap_values.shape[0]):
                class_name = str(i) if not cell_names else cell_names[i]
                shap_df = pd.DataFrame(self.shap_values[i,...],index=test_methyl_array.beta.index,columns=cpgs)
                if shap_df.shape[0]:
                    shapley_data.add_class(class_name, shap_df, cpgs, n_top_features, add_top_abs=True)
                    #shapley_data.add_class('{}_pos'.format(class_name), shap_df, cpgs, n_top_features)
                    #shapley_data.add_class('{}_neg'.format(class_name), shap_df, cpgs, n_top_features, add_top_negative=True)
        else: # regression tasks
            shap_df = pd.DataFrame(self.shap_values,index=test_methyl_array.beta.index,columns=cpgs)
            shapley_data.add_class('regression' if not cell_names else '{}'.format(cell_names[0]), shap_df, cpgs, n_top_features, add_top_abs=True)
            #shapley_data.add_class('regression_pos' if not cell_names else '{}_pos'.format(cell_names[0]), shap_df, cpgs, n_top_features)
            #shapley_data.add_class('regression_neg' if not cell_names else '{}_neg'.format(cell_names[0]), shap_df, cpgs, n_top_features, add_top_negative=True)
        self.shapley_data = shapley_data
Assigns the SHAP scores to a SHAPley data object, populating nested dictionaries (containing multioutput and single output regression-individual information) with SHAPley information and "top CpGs".

        Parameters
        ----------
        test_methyl_array : type
            Testing MethylationArray.
        n_top_features : type
            Number of top SHAP scores to use for a subdict called "top CpGs"
        cell_names : type
            If multi-output regression, create separate regression classes to access for all individuals.

        
Assigns the SHAP scores to a SHAPley data object, populating nested dictionaries (containing multioutput and single output regression-individual information) with SHAPley information and "top CpGs".
Parameters


Assigns the SHAP scores to a SHAPley data object populating nested dictionaries ( containing multioutput and single output regression - individual information ) with SHAPley information and " top CpGs " . Parameters
def regressor_assign_scores_to_shap_data(self, test_methyl_array, n_top_features, cell_names=[]):
        n_classes = (self.shap_values.shape[0] if len(self.shap_values.shape) == 3 else 0)
        cpgs=test_methyl_array.return_cpgs()
        shapley_data = ShapleyData()
        self.cpg_global_shapley_scores = (np.abs(self.shap_values).mean(0).mean(0) if n_classes else np.abs(self.shap_values).mean(0))
        shapley_data.add_global_importance(self.cpg_global_shapley_scores,cpgs, n_top_features)
        if n_classes:
            for i in range(self.shap_values.shape[0]):
                class_name = str(i) if not cell_names else cell_names[i]
                shap_df = pd.DataFrame(self.shap_values[i,...],index=test_methyl_array.beta.index,columns=cpgs)
                if shap_df.shape[0]:
                    shapley_data.add_class(class_name, shap_df, cpgs, n_top_features, add_top_abs=True)
        else: 
            shap_df = pd.DataFrame(self.shap_values,index=test_methyl_array.beta.index,columns=cpgs)
            shapley_data.add_class('regression' if not cell_names else '{}'.format(cell_names[0]), shap_df, cpgs, n_top_features, add_top_abs=True)
        self.shapley_data = shapley_data
def regressor_assign_scores_to_shap_data ( self , test_methyl_array , n_top_features , cell_names = [ ] ) : n_classes = ( self . shap_values . shape [ 0 ] if len ( self . shap_values . shape ) == 3 else 0 ) cpgs = test_methyl_array . return_cpgs ( ) shapley_data = ShapleyData ( ) self . cpg_global_shapley_scores = ( np . abs ( self . shap_values ) . mean ( 0 ) . mean ( 0 ) if n_classes else np . abs ( self . shap_values ) . mean ( 0 ) ) shapley_data . add_global_importance ( self . cpg_global_shapley_scores , cpgs , n_top_features ) if n_classes : for i in range ( self . shap_values . shape [ 0 ] ) : class_name = str ( i ) if not cell_names else cell_names [ i ] shap_df = pd . DataFrame ( self . shap_values [ i , ... ] , index = test_methyl_array . beta . index , columns = cpgs ) if shap_df . shape [ 0 ] : shapley_data . add_class ( class_name , shap_df , cpgs , n_top_features , add_top_abs = True ) else : shap_df = pd . DataFrame ( self . shap_values , index = test_methyl_array . beta . index , columns = cpgs ) shapley_data . add_class ( 'regression' if not cell_names else '{}' . format ( cell_names [ 0 ] ) , shap_df , cpgs , n_top_features , add_top_abs = True ) self . shapley_data = shapley_data
Assigns the SHAP scores to a SHAPley data object, populating nested dictionaries (containing multioutput and single output regression-individual information) with SHAPley information and "top CpGs".
Assigns the SHAP scores to a SHAPley data object populating nested dictionaries ( containing multioutput and single output regression - individual information ) with SHAPley information and " top CpGs " .
"""Assigns the SHAP scores to a SHAPley data object, populating nested dictionaries (containing multioutput and single output regression-individual information) with SHAPley information and "top CpGs".

        Parameters
        ----------
        test_methyl_array : type
            Testing MethylationArray.
        n_top_features : type
            Number of top SHAP scores to use for a subdict called "top CpGs"
        cell_names : type
            If multi-output regression, create separate regression classes to access for all individuals.

        """ #shapley_data.add_class('{}_pos'.format(class_name), shap_df, cpgs, n_top_features) #shapley_data.add_class('{}_neg'.format(class_name), shap_df, cpgs, n_top_features, add_top_negative=True) # regression tasks #shapley_data.add_class('regression_pos' if not cell_names else '{}_pos'.format(cell_names[0]), shap_df, cpgs, n_top_features) #shapley_data.add_class('regression_neg' if not cell_names else '{}_neg'.format(cell_names[0]), shap_df, cpgs, n_top_features, add_top_negative=True)
self
test_methyl_array
n_top_features
cell_names