Exemplo n.º 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)
Exemplo n.º 2
0
 def test_sign_contributions_2(self):
     """
     Unit test sign contributions 2
     """
     dataframe = pd.DataFrame({
         'val1': [1, -1],
         'val2': [-2, -2],
         'val3': [0.5, -2]
     })
     output = sign_contributions(dataframe, positive=False)
     expected = pd.DataFrame({
         'val1': [False, True],
         'val2': [True, True],
         'val3': [False, True]
     })
     pd.testing.assert_frame_equal(output, expected)
Exemplo n.º 3
0
    def sign_contributions(self, dataframe, positive=True):
        """
        Returns Boolean values depending on
        the signs of local contributions
        stored in dataframe and on the positive parameter.

        Parameters
        ----------
        dataframe : pandas.DataFrame
            Local contributions of the model.
        positive : boolean (default=True)
            True to evaluate positive value.
            False to evaluate negative value.

        Returns
        -------
        pandas.DataFrame
            Dataframe with boolean value.
        """
        return sign_contributions(dataframe, positive=positive)