TeamHG-Memex / eli5

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

Update to new sklearn API #397

Open icfly2 opened 3 years ago

icfly2 commented 3 years ago

Change as per FutureWarning in sklearn, to allow eli5 to be used with sklearn 0.24 and newer. docs

Currently issues FutureWarning

  File "/app/model/model.py", line 3, in <module>
    import eli5
  File "/usr/local/lib/python3.7/site-packages/eli5/__init__.py", line 13, in <module>
    from .sklearn import explain_weights_sklearn, explain_prediction_sklearn
  File "/usr/local/lib/python3.7/site-packages/eli5/sklearn/__init__.py", line 3, in <module>
    from .explain_weights import (
  File "/usr/local/lib/python3.7/site-packages/eli5/sklearn/explain_weights.py", line 78, in <module>
    from .permutation_importance import PermutationImportance
  File "/usr/local/lib/python3.7/site-packages/eli5/sklearn/permutation_importance.py", line 15, in <module>
    from sklearn.metrics.scorer import check_scoring  # type: ignore
  File "/usr/local/lib/python3.7/site-packages/sklearn/metrics/scorer.py", line 12, in <module>
    _raise_dep_warning_if_not_pytest(deprecated_path, correct_import_path)
  File "/usr/local/lib/python3.7/site-packages/sklearn/utils/deprecation.py", line 143, in _raise_dep_warning_if_not_pytest
    warnings.warn(message, FutureWarning)
FutureWarning: The sklearn.metrics.scorer module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.metrics. Anything that cannot be imported from sklearn.metrics is now part of the private API.
InterferencePattern commented 3 years ago

This update will break compatibility with scikit-learn < 0.20, so it would be necessary to update the requirements and setup.py to require at least this version (eli5 currently allows >=0.18).

icfly2 commented 3 years ago

Is the upgrade of the sklearn requirement acceptable, given that 0.18 is now 4 years old and 0.24 has a RC out?

codecov-io commented 3 years ago

Codecov Report

Merging #397 (805a3c1) into master (017c738) will decrease coverage by 16.74%. The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           master     #397       +/-   ##
===========================================
- Coverage   97.32%   80.58%   -16.75%     
===========================================
  Files          49       49               
  Lines        3142     3142               
  Branches      585      585               
===========================================
- Hits         3058     2532      -526     
- Misses         44      569      +525     
- Partials       40       41        +1     
Impacted Files Coverage Δ
eli5/sklearn/permutation_importance.py 93.68% <100.00%> (-6.32%) :arrow_down:
eli5/keras/gradcam.py 0.00% <0.00%> (-100.00%) :arrow_down:
eli5/xgboost.py 4.26% <0.00%> (-95.13%) :arrow_down:
eli5/formatters/image.py 5.47% <0.00%> (-94.53%) :arrow_down:
eli5/keras/explain_prediction.py 4.81% <0.00%> (-91.57%) :arrow_down:
eli5/lightgbm.py 4.27% <0.00%> (-90.60%) :arrow_down:
eli5/catboost.py 11.53% <0.00%> (-88.47%) :arrow_down:
eli5/_decision_path.py 35.48% <0.00%> (-64.52%) :arrow_down:
eli5/keras/__init__.py 50.00% <0.00%> (-50.00%) :arrow_down:
eli5/ipython.py 85.71% <0.00%> (-14.29%) :arrow_down:
... and 5 more
lopuhin commented 3 years ago

Is the upgrade of the sklearn requirement acceptable, given that 0.18 is now 4 years old and 0.24 has a RC out?

I'd say that yes, it is.

Thanks for the PR 👍

veonua commented 3 years ago

/eli5/sklearn/text.py in

----> 4 from sklearn.feature_extraction.text import VectorizerMixin # type: ignore

should be renamed to _VectorizerMixin

veonua commented 3 years ago

~/.local/lib/python3.8/site-packages/eli5/sklearn/transform.py ----> 6 from sklearn.feature_selection.base import SelectorMixin # type: ignore

from sklearn.feature_selection import SelectorMixin

icfly2 commented 3 years ago

@veonua I'm a bit confused what you are suggesting, master reads:

try:
    from sklearn.feature_extraction.text import _VectorizerMixin as VectorizerMixin
except ImportError:  # Changed in scikit-learn 0.22
    from sklearn.feature_extraction.text import VectorizerMixin

your other comment is also already addressed in this PR

veonua commented 3 years ago

can you please publish these changes to pip?

lopuhin commented 3 years ago

Thanks you! This were merged in eli5-org/eli5#2 and released to PyPI with v0.11