Example #1
0
 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)
Example #2
0
 def test_hide_contributions_3(self):
     """
     Unit test hide contributions 3
     """
     dataframe = pd.DataFrame([[2, 0, 1], [0, 1, 2], [2, 3, 1]],
                              columns=['col1', 'col2', 'col3'])
     output = hide_contributions(dataframe, [])
     expected = pd.DataFrame(
         [[True, True, True], [True, True, True], [True, True, True]],
         columns=['col1', 'col2', 'col3'])
     pd.testing.assert_frame_equal(output, expected)
Example #3
0
    def hide_contributions(self, var_dict, features_list):
        """
        Returns Boolean dataframe with True/False depending if the
        feature is present or not in the list of
        feature to hide.

        Parameters
        ----------
        var_dict: pd.DataFrame
            Dataframe with features indexes ordered
            by contribution.
        feature_list: List
            List of index, feature to hide.

        Returns
        -------
        pd.DataFrame
            Boolean dataframe depend on hidden features.
        """
        return hide_contributions(var_dict, features_list)