Beispiel #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)
Beispiel #2
0
 def test_cap_contributions(self):
     """
     Unit test cap contributions
     """
     xmatr = pd.DataFrame(
         [[0.1, 0.43, -0.02], [-0.78, 0.002, -0.3], [0.62, -0.008, 0.4]],
         columns=['c1', 'c2', 'c3'])
     thresholdvalue = 0.3
     result = pd.DataFrame(
         [[False, True, False], [True, False, True], [True, False, True]],
         columns=['c1', 'c2', 'c3'])
     output = cap_contributions(xmatr, thresholdvalue)
     assert xmatr.shape == output.shape
     assert output.equals(result)
Beispiel #3
0
    def cap_contributions(self, s_contrib, threshold=0.1):
        """
        Compute a mask indicating where the input matrix
        has values above a given threshold in absolute value.

        Parameters
        ----------
        s_contrib : pandas.DataFrame
            Local contributions, positive and negative values.
        threshold: float, optional (default: 0.1)
            User defined threshold above which local contributions are hidden.

        Returns
        -------
        pandas.DataFrame
            Mask with only True of False elements.
        """
        return cap_contributions(s_contrib, threshold=threshold)