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 test_init_mask(self): """ test of initialization of mask """ column_name = ['col1', 'col2'] s_ord = pd.DataFrame([[0.1, 0.43], [-0.78, 0.002], [0.62, -0.008]], columns=column_name) expected = pd.DataFrame([[True, True], [True, True], [True, True]], columns=column_name) output = init_mask(s_ord) assert output.equals(expected)
def init_mask(self, s_contrib, value=True): """ Initialize a True mask for the dataset. Parameters ---------- s_contrib: pd.DataFrame Matrix with both positive and negative values value: bool Value used for initialize the mask Returns ------- pd.Dataframe mask initialized """ return init_mask(s_contrib, value)