Closed ncduy0303 closed 4 years ago
I can't seem to reproduce this. What environment are you in?
I'm using Jupyter Notebook on Gradient. Here are the versions of the libraries I'm using:
import shap, fastai2, fastcore, fastinference
fastai2.__version__, fastcore.__version__, fastinference.__version__, shap.__version__
('0.0.18', '0.1.18', '0.0.13', '0.35.0')
Thanks! I'll try to do that in gradient today and get back with you, for now I can guarantee it works in Colaboratory (this is where I did my testing real quick)
Thank you!
I don't have a gradient account so I'm not sure how to test that actually, but running in my local jupyter environment also doesn't show any issues. The versions are all the same.
Hi, I still saw the error on my side. But after I traced the error to ShapInterpretation()
, I changed self.class_names = learn.dl.vocab if hasattr(learn.dl, 'vocab') else None
into self.class_names = learn.dls.vocab if hasattr(learn.dls, 'vocab') else None
everything seems to work?
#export
class ShapInterpretation():
"Base interpereter to use the `SHAP` interpretation library"
def __init__(self, learn:TabularLearner, test_data=None, link='identity', l1_reg='auto', n_samples=128, **kwargs):
"Initialize `ShapInterpretation` with a Learner, test_data, link, `n_samples`, `l1_reg`, and optional **kwargs"
self.model = learn.model
self.dls = learn.dls
self.class_names = learn.dl.vocab if hasattr(learn.dl, 'vocab') else None # only defined for classification problems
self.train_data = pd.merge(learn.dls.cats, learn.dls.conts, left_index=True, right_index=True)
self.test_data = _prepare_data(learn, test_data, n_samples)
pred_func = partial(_predict, learn)
self.explainer = shap.SamplingExplainer(pred_func, self.train_data, **kwargs)
self.shap_vals = self.explainer.shap_values(self.test_data, l1_reg=l1_reg)
self.is_multi_output = isinstance(self.shap_vals, list)
That fix looks alright to me, would you like to put a PR in? :)
Hi, I tried running this notebook and got an error at this line: