marcotcr / anchor

Code for "High-Precision Model-Agnostic Explanations" paper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple rows passed in predict function

Piyushbalwani opened this issue · comments

Hi @marcotcr I want to write wrapper for Hoeffding tree model.

  1. I am calling explain_instance for idx=0, but multiple rows are printed in predict_binary function. Can you please explain why multiple rows got printed?
  2. I want to generate rules(or anchors) for class=1 with respect to all samples, not only for single instance. By looking output, I think final anchor exp.names() generated by considering multiple rows, not single row. How rows are grouped and how can we pass all samples and generate common anchors?
class ProbWrapper:
    def __init__(self, model, feature_names):
        self.model = model
        self.feature_names = feature_names
    def predict_binary(self, X):
        print("row:",X)
        X = pd.DataFrame(X,columns=features).to_dict(orient='records')
        self.predictions = np.zeros(len(X))
        for i in range(len(X)):
            self.predictions[i]=(self.model.predict_one(X[i]))
        return self.predictions

idx = 0
wrapper = ProbWrapper(model,features)
exp = explainer.explain_instance(df_v.loc[idx,features].values,wrapper.predict_binary, threshold=0.95)
print('Anchor: %s' % (' AND '.join(exp.names())))

output: multiple rows are printing

row: [[ 4. 11.]]
row: [[ 1. 15.]]
row: [[ 0.  1.]
 [ 0. 11.]
 [ 4. 11.]
 [ 4.  2.]]
row: [[ 4. 11.]]
Anchor: x1 > 2.00

I am calling explain_instance for idx=0, but multiple rows are printed in predict_binary function. Can you please explain why multiple rows got printed?

The method works by perturbing the instance you give it, and getting predictions from the model.

I want to generate rules(or anchors) for class=1 with respect to all samples, not only for single instance. By looking output, I think final anchor exp.names() generated by considering multiple rows, not single row. How rows are grouped and how can we pass all samples and generate common anchors?

We don't have that functionality, but you may want to take a look at this