Пример #1
0
    def test_local_contrib_w_discretize(self):

        row = self.frame.iloc[0, :]

        explainer = LIMEExplainer(training_frame=self.frame,
                                  X=self.X,
                                  model=self.model,
                                  discretize=self.discretize)
        local_sample = explainer._generate_local_sample(row)
        scored_local_sample = \
            explainer._score_local_sample(local_sample,
                                          row[local_sample.columns])
        weighted_scored_local_sample = \
            explainer._calculate_distance_weights(0,
                                                  scored_local_sample)
        discretized_weighted_scored_local_sample = \
            explainer._discretize_numeric(weighted_scored_local_sample)

        disc_row = pd.DataFrame(columns=self.X)
        for name in self.discretize:
            disc_row[name] = pd.cut(pd.Series(row[name]),
                                    bins=explainer.bins_dict[name])
        not_in = list(set(self.X) - set(self.discretize))
        disc_row[not_in] = row[not_in].values

        explainer.lime = \
            explainer._regress(discretized_weighted_scored_local_sample,
                               h2o.H2OFrame(disc_row))

        self.assertEqual(explainer.reason_code_values.shape, (21, 2))
        del explainer
Пример #2
0
    def test_local_contrib_w_o_discretize(self):

        row = self.frame.iloc[0, :]

        explainer = LIMEExplainer(training_frame=self.frame,
                                  X=self.X,
                                  model=self.model)
        local_sample = explainer._generate_local_sample(row)
        scored_local_sample = \
            explainer._score_local_sample(local_sample,
                                          row[local_sample.columns])
        weighted_scored_local_sample = \
            explainer._calculate_distance_weights(0,
                                                  scored_local_sample)
        explainer.lime = \
            explainer._regress(weighted_scored_local_sample,
                               h2o.H2OFrame(pd.DataFrame(row).T))

        self.assertEqual(explainer.reason_code_values.shape, (26, 2))
        del explainer