python/methylnet/interpretation_classes.py
def classifier_assign_scores_to_shap_data(self, test_methyl_array, n_top_features, interest_col='disease', prediction_classes=None):
        """Assigns the SHAP scores to a SHAPley data object, populating nested dictionaries (containing class-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"
        interest_col : type
            Column in pheno sheet from which class names reside.
        prediction_classes : type
            User supplied prediction classes.

        """

        cpgs=test_methyl_array.return_cpgs()
        shapley_data = ShapleyData()

        self.cpg_global_shapley_scores = np.abs(self.shap_values).mean(0).mean(0)
        shapley_data.add_global_importance(self.cpg_global_shapley_scores,cpgs, n_top_features)
        """if cross_class:
            self.shap_values = np.abs(self.shap_values).mean(axis=0)"""
        for i in range(self.shap_values.shape[0]):
            class_name = prediction_classes[i] if prediction_classes != None else str(i)
            shap_df = pd.DataFrame(self.shap_values[i,...],index=test_methyl_array.beta.index,columns=cpgs)
            if shap_df.shape[0]:
                if prediction_classes != None:
                    shap_df = shap_df.loc[test_methyl_array.pheno[interest_col].values == class_name,:]
                shapley_data.add_class(class_name, shap_df, cpgs, n_top_features)

        self.shapley_data = shapley_data
Assigns the SHAP scores to a SHAPley data object, populating nested dictionaries (containing class-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"
        interest_col : type
            Column in pheno sheet from which class names reside.
        prediction_classes : type
            User supplied prediction classes.

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


Assigns the SHAP scores to a SHAPley data object populating nested dictionaries ( containing class - individual information ) with SHAPley information and " top CpGs " . Parameters
def classifier_assign_scores_to_shap_data(self, test_methyl_array, n_top_features, interest_col='disease', prediction_classes=None):
        cpgs=test_methyl_array.return_cpgs()
        shapley_data = ShapleyData()
        self.cpg_global_shapley_scores = np.abs(self.shap_values).mean(0).mean(0)
        shapley_data.add_global_importance(self.cpg_global_shapley_scores,cpgs, n_top_features)
        for i in range(self.shap_values.shape[0]):
            class_name = prediction_classes[i] if prediction_classes != None else str(i)
            shap_df = pd.DataFrame(self.shap_values[i,...],index=test_methyl_array.beta.index,columns=cpgs)
            if shap_df.shape[0]:
                if prediction_classes != None:
                    shap_df = shap_df.loc[test_methyl_array.pheno[interest_col].values == class_name,:]
                shapley_data.add_class(class_name, shap_df, cpgs, n_top_features)
        self.shapley_data = shapley_data
def classifier_assign_scores_to_shap_data ( self , test_methyl_array , n_top_features , interest_col = 'disease' , prediction_classes = None ) : cpgs = test_methyl_array . return_cpgs ( ) shapley_data = ShapleyData ( ) self . cpg_global_shapley_scores = np . abs ( self . shap_values ) . mean ( 0 ) . mean ( 0 ) shapley_data . add_global_importance ( self . cpg_global_shapley_scores , cpgs , n_top_features ) """if cross_class:
            self.shap_values = np.abs(self.shap_values).mean(axis=0)""" for i in range ( self . shap_values . shape [ 0 ] ) : class_name = prediction_classes [ i ] if prediction_classes != None else str ( i ) shap_df = pd . DataFrame ( self . shap_values [ i , ... ] , index = test_methyl_array . beta . index , columns = cpgs ) if shap_df . shape [ 0 ] : if prediction_classes != None : shap_df = shap_df . loc [ test_methyl_array . pheno [ interest_col ] . values == class_name , : ] shapley_data . add_class ( class_name , shap_df , cpgs , n_top_features ) self . shapley_data = shapley_data
Assigns the SHAP scores to a SHAPley data object, populating nested dictionaries (containing class-individual information) with SHAPley information and "top CpGs".
Assigns the SHAP scores to a SHAPley data object populating nested dictionaries ( containing class - individual information ) with SHAPley information and " top CpGs " .
"""Assigns the SHAP scores to a SHAPley data object, populating nested dictionaries (containing class-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"
        interest_col : type
            Column in pheno sheet from which class names reside.
        prediction_classes : type
            User supplied prediction classes.

        """ """if cross_class:
            self.shap_values = np.abs(self.shap_values).mean(axis=0)"""
self
test_methyl_array
n_top_features
interest_col
prediction_classes