TeamHG-Memex / eli5

A library for debugging/inspecting machine learning classifiers and explaining their predictions
http://eli5.readthedocs.io
MIT License
2.74k stars 332 forks source link

RuntimeWarning: invalid value encountered in double_scalars when computing weights #369

Closed InterferencePattern closed 1 year ago

InterferencePattern commented 4 years ago

Hi, I'm experiencing an error in eli5.show_weights(), I believe it's where the colors are being computed. I've followed the simplest tutorial (https://eli5.readthedocs.io/en/latest/blackbox/permutation_importance.html) and it's not working with my dataset and model.

I'm using eli5 version 0.10.1

Here is the relevant code: def permutation_importance(X_test, y_test, clf): import eli5 from eli5.sklearn import PermutationImportance perm = PermutationImportance(clf).fit(X_test, y_test) eli5.show_weights(perm)

permutation_importance(X_test_dummified,y_test,rf_clf_imbalanced)

Here is the entire error log:

~/anaconda3/envs/aif360/lib/python3.7/site-packages/eli5/formatters/html.py:235: RuntimeWarning: invalid value encountered in double_scalars rel_weight = (abs(weight) / weight_range) ** 0.7

The error is probably with weight or weight_range, but the error log does not specify where these are generated.

Can anyone help me trace this error back? Thanks!

InterferencePattern commented 4 years ago

Additional information: I've now found that eli5.explain_weights(perm) results in all weights of zero, and I also realized that this model predicts the negative class for all data points. This would be the source of all zeros in the weights.

In any case, maybe it would be beneficial to users to catch this edge case.

XinQi7788 commented 3 years ago

I encountered the same issue. Can anyone help on this issue?

Thanks a lot!