Пример #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)
Пример #2
0
 def test_compute_masked_contributions_3(self):
     """
     test of compute masked contributions 3
     """
     column_name = ['col1', 'col2', 'col3']
     xmatr = pd.DataFrame(
         [[0.1, 0.43, -0.02], [-0.78, 0.002, -0.3], [0.62, -0.008, 0.4]],
         columns=column_name)
     masktest = pd.DataFrame(
         [[True, True, True], [True, True, True], [True, True, True]],
         columns=column_name)
     output = compute_masked_contributions(xmatr, masktest)
     expected = pd.DataFrame([[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]],
                             columns=['masked_neg', 'masked_pos'])
     assert (xmatr.shape[0], 2) == output.shape
     assert output.equals(expected)
Пример #3
0
    def compute_masked_contributions(self, s_contrib, masks):
        """
        Compute the summed contributions of hidden features.

        Parameters
        ----------
        s_contrib: pd.DataFrame
            Matrix with both positive and negative values
        mask: pd.DataFrame
            Matrix with only True or False elements. False elements are the hidden elements.

        Returns
        -------
        pd.series
            Sum of contributions of hidden features.
        """
        return compute_masked_contributions(s_contrib, masks)