marcotcr / anchor

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can we use Anchor to explain already built models in our own way?

DiliSR opened this issue · comments

Hi,

First of all, I should say that this is really a great paper. Good luck with you.

My question is, let's assume we have a tabular dataset. We just do encoding categorical variables as pre-processing and make a model using the random forest. And we save that model using .pickle format.

After that can we use Anchor to explain that saved model.

For example, I don't need to use these lines of code when making the model.

explainer = anchor_tabular.AnchorTabularExplainer(dataset.class_names, dataset.feature_names, dataset.data, dataset.categorical_names)
explainer.fit(dataset.train, dataset.labels_train, dataset.validation, dataset.labels_validation)
c = sklearn.ensemble.RandomForestClassifier(n_estimators=50, n_jobs=5)
c.fit(explainer.encoder.transform(dataset.train), dataset.labels_train)

I just need to use,
c = sklearn.ensemble.RandomForestClassifier(n_estimators=50, n_jobs=5)
c.fit(dataset.train, dataset.labels_train)
these two lines when making the model.

Thank you.

In LIME, explainer was created, after built the model. But in Anchor, we need to build the explainer before making the global model.

I'm glad you found the paper interesting.

Yes, you can train the model without encoding, provided that you don't have categorical features (i.e. the explainer will tread all features as ordinal / continuous and discretize them). You don't need to initialize the explainer before training the model, I just did it in that order because I wanted to use the explainer's encoder to encode the data before training the model. Note that the init function of the explainer does not depend on the model.