python/methylnet/interpretation_classes.py
def add_class(self, class_name, shap_df, cpgs, n_top_cpgs, add_top_negative=False, add_top_abs=False):
        """Store SHAP scores for particular class to Shapley_Data class. Save feature importances on granular level, explanations for individual and aggregate predictions.

        Parameters
        ----------
        class_name : type
            Particular class name to be stored in dictionary structure.
        shap_df : type
            SHAP data to pull from.
        cpgs : type
            All CpGs.
        n_top_cpgs : type
            Number of top CpGs for saving n top CpGs.
        add_top_negative : type
            Only consider top negative scores.

        """
        signed = -1 if not add_top_negative else 1
        self.shapley_values['by_class'][class_name]=shap_df
        shap_vals=shap_df.values
        class_importance_shaps = shap_vals.mean(0)
        top_idx = np.argsort(class_importance_shaps*signed)[:n_top_cpgs]
        self.top_cpgs['by_class'][class_name]={'by_individual':{},'overall':{}}
        self.top_cpgs['by_class'][class_name]['overall']=pd.DataFrame(np.hstack([cpgs[top_idx][:,np.newaxis],class_importance_shaps[top_idx][:,np.newaxis]]),columns=['cpg','shapley_value'])
        top_idxs = np.argsort(shap_vals*signed if not add_top_abs else -np.abs(shap_vals))[:,:n_top_cpgs]
        for i,individual in enumerate(list(shap_df.index)):
            self.top_cpgs['by_class'][class_name]['by_individual'][individual]=pd.DataFrame(shap_df.iloc[i,top_idxs[i,:]].T.reset_index(drop=False).values,columns=['cpg','shapley_value'])
Store SHAP scores for particular class to Shapley_Data class. Save feature importances on granular level, explanations for individual and aggregate predictions.

        Parameters
        ----------
        class_name : type
            Particular class name to be stored in dictionary structure.
        shap_df : type
            SHAP data to pull from.
        cpgs : type
            All CpGs.
        n_top_cpgs : type
            Number of top CpGs for saving n top CpGs.
        add_top_negative : type
            Only consider top negative scores.

        
Store SHAP scores for particular class to Shapley_Data class. Save feature importances on granular level, explanations for individual and aggregate predictions.
Parameters

class_name : type
Particular class name to be stored in dictionary structure.
shap_df : type
SHAP data to pull from.
cpgs : type
All CpGs.
n_top_cpgs : type
Number of top CpGs for saving n top CpGs.
add_top_negative : type
Only consider top negative scores.
Store SHAP scores for particular class to Shapley_Data class . Save feature importances on granular level explanations for individual and aggregate predictions . Parameters class_name : type Particular class name to be stored in dictionary structure . shap_df : type SHAP data to pull from . cpgs : type All CpGs . n_top_cpgs : type Number of top CpGs for saving n top CpGs . add_top_negative : type Only consider top negative scores .
def add_class(self, class_name, shap_df, cpgs, n_top_cpgs, add_top_negative=False, add_top_abs=False):
        signed = -1 if not add_top_negative else 1
        self.shapley_values['by_class'][class_name]=shap_df
        shap_vals=shap_df.values
        class_importance_shaps = shap_vals.mean(0)
        top_idx = np.argsort(class_importance_shaps*signed)[:n_top_cpgs]
        self.top_cpgs['by_class'][class_name]={'by_individual':{},'overall':{}}
        self.top_cpgs['by_class'][class_name]['overall']=pd.DataFrame(np.hstack([cpgs[top_idx][:,np.newaxis],class_importance_shaps[top_idx][:,np.newaxis]]),columns=['cpg','shapley_value'])
        top_idxs = np.argsort(shap_vals*signed if not add_top_abs else -np.abs(shap_vals))[:,:n_top_cpgs]
        for i,individual in enumerate(list(shap_df.index)):
            self.top_cpgs['by_class'][class_name]['by_individual'][individual]=pd.DataFrame(shap_df.iloc[i,top_idxs[i,:]].T.reset_index(drop=False).values,columns=['cpg','shapley_value'])
def add_class ( self , class_name , shap_df , cpgs , n_top_cpgs , add_top_negative = False , add_top_abs = False ) : signed = - 1 if not add_top_negative else 1 self . shapley_values [ 'by_class' ] [ class_name ] = shap_df shap_vals = shap_df . values class_importance_shaps = shap_vals . mean ( 0 ) top_idx = np . argsort ( class_importance_shaps * signed ) [ : n_top_cpgs ] self . top_cpgs [ 'by_class' ] [ class_name ] = { 'by_individual' : { } , 'overall' : { } } self . top_cpgs [ 'by_class' ] [ class_name ] [ 'overall' ] = pd . DataFrame ( np . hstack ( [ cpgs [ top_idx ] [ : , np . newaxis ] , class_importance_shaps [ top_idx ] [ : , np . newaxis ] ] ) , columns = [ 'cpg' , 'shapley_value' ] ) top_idxs = np . argsort ( shap_vals * signed if not add_top_abs else - np . abs ( shap_vals ) ) [ : , : n_top_cpgs ] for i , individual in enumerate ( list ( shap_df . index ) ) : self . top_cpgs [ 'by_class' ] [ class_name ] [ 'by_individual' ] [ individual ] = pd . DataFrame ( shap_df . iloc [ i , top_idxs [ i , : ] ] . T . reset_index ( drop = False ) . values , columns = [ 'cpg' , 'shapley_value' ] )
Store SHAP scores for particular class to Shapley_Data class.
Store SHAP scores for particular class to Shapley_Data class .
"""Store SHAP scores for particular class to Shapley_Data class. Save feature importances on granular level, explanations for individual and aggregate predictions.

        Parameters
        ----------
        class_name : type
            Particular class name to be stored in dictionary structure.
        shap_df : type
            SHAP data to pull from.
        cpgs : type
            All CpGs.
        n_top_cpgs : type
            Number of top CpGs for saving n top CpGs.
        add_top_negative : type
            Only consider top negative scores.

        """
self
class_name
shap_df
cpgs
n_top_cpgs
add_top_negative
add_top_abs