Open ming-cui opened 2 years ago
Please see the screenshot.
Thanks, it is required to pass predict_function
to the Explainer, which inputs (model, pandas.DataFrame) and outputs a 1d numpy array.
An example for the xgboost
package is available at https://dalex.drwhy.ai/python-dalex-xgboost.html.
The already implemented predict_function
s (e.g. for h2o
, pycaret
, tensorflow
) are available at https://github.com/ModelOriented/DALEX/blob/master/python/dalex/dalex/_explainer/yhat.py.
We could add native support for fastai
to dalex
-- feel free to initiate a PR with changes to the yhat.py
file, and I would try to make it happen.
Thanks, Hubert. fastai .predict
method returns three objects. The source code is
Is it not compatible with DALEX? I'm still getting errors, and the messages were lengthy.
Yes, as I said, you need to create a new function, which will use the predict
method and return only one object -- a 1-dimensional numpy array with predictions for a class of interest. Then pass it to the predict_function
parameter in dx.Explainer
Hi Hubert, I think I got the basic idea, but I struggled for quite a while as I'm new to Python and fastai. I got the error as illustrated in the screenshot. It seems the .predict
function only takes a row as input. I guess I need to write some customized prediction function to pass into DALEX. I've linked the source code of .predict
here, or you can view the code in the sceenshot. Could you help with getting the right prediction function to work with DALEX? Thank you so much!
Hi! Maybe you can try predict_function = lambda m, d: m.predict(d)[2]
?
Thanks for the function. I got the error message 'DataFrame' object has no attribute 'to_frame'
with details below. Will the .get_preds()
method be useful (shown in the photo in my last reply)? .get_preds()
returns tuples (one for predictions and the other for true labels), and I haven't figured out how to put it in a explainer
.
.
Is it possible that the tensor format predictions returned by .predict()
caused 'DataFrame' object has no attribute 'to_frame'
?
Yes, you need to first apply the predict_function outside of the explainer and see what it returns.
It returns a tensor. For example, learn.predict(xs_nn.iloc[0])[2]
will return tensor([1.7050])
as the predicted value based on the first row of the training dataframe xs_nn
. What should I do with that? Many thanks!
It should return a one dimensional numpy array
I'm trying to wrap a
fastai
tabularlearner
with DALEX. I got'DataFrame' object has no attribute 'to_frame'
error withdx.Explainer(learn, xs, y, label = "Deep NN")
. Any potential problems with this line of code? Thanks!