def filter(self): """ The filter method is an important method which allows to summarize the local explainability by using the user defined mask_params parameters which correspond to its use case. """ mask = [init_mask(self.summary['contrib_sorted'], True)] if self.mask_params["features_to_hide"] is not None: mask.append( hide_contributions(self.summary['var_dict'], features_list=self.check_features_name( self.mask_params["features_to_hide"]))) if self.mask_params["threshold"] is not None: mask.append( cap_contributions(self.summary['contrib_sorted'], threshold=self.mask_params["threshold"])) if self.mask_params["positive"] is not None: mask.append( sign_contributions(self.summary['contrib_sorted'], positive=self.mask_params["positive"])) self.mask = combine_masks(mask) if self.mask_params["max_contrib"] is not None: self.mask = cutoff_contributions(mask=self.mask, k=self.mask_params["max_contrib"]) self.masked_contributions = compute_masked_contributions( self.summary['contrib_sorted'], self.mask)
def combine_masks(self, masks): """ Combine a list of masks with the AND operator. Parameters ---------- masks : list List of boolean pandas.DataFrames. Returns ------- pd.Dataframe Combination of all masks. """ return combine_masks(masks)
def test_combine_masks_2(self): """ Unit test combine masks 2 """ df1 = pd.DataFrame( [[True, False, True], [True, True, True], [False, False, False]], columns=['col1', 'col2', 'col3']) df2 = pd.DataFrame( [[False, False, True], [True, False, True], [True, False, False]], columns=['contrib_1', 'contrib_2', 'contrib_3']) output = combine_masks([df1, df2]) expected_output = pd.DataFrame( [[False, False, True], [True, False, True], [False, False, False]], columns=['contrib_1', 'contrib_2', 'contrib_3']) pd.testing.assert_frame_equal(output, expected_output)