Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when importing eli5 #39

Open
leetabix opened this issue Aug 9, 2023 · 11 comments
Open

Error when importing eli5 #39

leetabix opened this issue Aug 9, 2023 · 11 comments

Comments

@leetabix
Copy link

leetabix commented Aug 9, 2023

When creating a virtual environment (using venv) and pip installing eli5 and jupyter lab, I'm unable to import eli5 as I receive the following error in my notebook:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 import eli5

File \Lib\site-packages\eli5\__init__.py:13
      6 from .formatters import (
      7     format_as_html,
      8     format_html_styles,
      9     format_as_text,
     10     format_as_dict,
     11 )
     12 from .explain import explain_weights, explain_prediction
---> 13 from .sklearn import explain_weights_sklearn, explain_prediction_sklearn
     14 from .transform import transform_feature_names
     17 try:

File \Lib\site-packages\eli5\sklearn\__init__.py:3
      1 # -*- coding: utf-8 -*-
      2 from __future__ import absolute_import
----> 3 from .explain_weights import (
      4     explain_weights_sklearn,
      5     explain_linear_classifier_weights,
      6     explain_linear_regressor_weights,
      7     explain_rf_feature_importance,
      8     explain_decision_tree,
      9 )
     10 from .explain_prediction import (
     11     explain_prediction_sklearn,
     12     explain_prediction_linear_classifier,
     13     explain_prediction_linear_regressor,
     14 )
     15 from .unhashing import (
     16     InvertableHashingVectorizer,
     17     FeatureUnhasher,
     18     invert_hashing_and_fit,
     19 )

File \Lib\site-packages\eli5\sklearn\explain_weights.py:78
     73 from eli5.transform import transform_feature_names
     74 from eli5._feature_importances import (
     75     get_feature_importances_filtered,
     76     get_feature_importance_explanation,
     77 )
---> 78 from .permutation_importance import PermutationImportance
     81 LINEAR_CAVEATS = """
     82 Caveats:
     83 1. Be careful with features which are not
   (...)
     90    classification result for most examples.
     91 """.lstrip()
     93 HASHING_CAVEATS = """
     94 Feature names are restored from their hashes; this is not 100% precise
     95 because collisions are possible. For known collisions possible feature names
   (...)
     99 the result is positive.
    100 """.lstrip()

File \Lib\site-packages\eli5\sklearn\permutation_importance.py:7
      5 import numpy as np
      6 from sklearn.model_selection import check_cv
----> 7 from sklearn.utils.metaestimators import if_delegate_has_method
      8 from sklearn.utils import check_array, check_random_state
      9 from sklearn.base import (
     10     BaseEstimator,
     11     MetaEstimatorMixin,
     12     clone,
     13     is_classifier
     14 )

ImportError: cannot import name 'if_delegate_has_method' from 'sklearn.utils.metaestimators' (\Lib\site-packages\sklearn\utils\metaestimators.py)

The issue appears to be due to scikit-learn depreciating the if_delegate_has_method decorator (in \Lib\site-packages\sklearn\utils\metaestimators.py) and replacing it with another decorator called available_if.

I've made the following updates to \Lib\site-packages\eli5\sklearn\permutation_importance.py and I'm now able to import the eli5 library:

  • changed import statement to mention available_if instead of if_delegate_has_method
  • replaced all mentions of:
    @if_delegate_has_method(delegate='wrapped_estimator_')

with

    @available_if(_estimator_has('wrapped_estimator_'))
  • defined a new _estimator_has function for use with the above

Please let me know if you'd like me to propose the above update for merge.

Thanks,
James

@GegznaV
Copy link

GegznaV commented Aug 12, 2023

@leetabix I think you should propose a pull request (PR) with the changes you've already made: it at least will be possible to install the working version of the package from your PR.

@GegznaV
Copy link

GegznaV commented Aug 12, 2023

@frosty24
Copy link

This commit addresses this as well:
840695d

@GegznaV
Copy link

GegznaV commented Aug 22, 2023

@frosty24, is 840695d merged to the main branch of this repo? I'm a bit confused as GitHub informs:
image

@frosty24
Copy link

I picked this commit from the following open PR in this repo:
#31

@isabelizimm
Copy link

Hi all! I ran into this error as well. I ended up installing scikit-learn==1.2.2 and then was able to import eli5 successfully.

@mprytoluk
Copy link

Is it possible for me to do something about this? I've stopped using eli5 in my project because I had to update scikit-learn.

@GegznaV
Copy link

GegznaV commented Dec 11, 2023

If nobody answers, you may use SHAP values as an alternative: https://github.com/shap/shap That project is currently alive.

@RobertCarruthers-Ki
Copy link

Slight correction to the above.

Instead of replacing
@if_delegate_has_method(delegate='wrapped_estimator_')
with:
@available_if(_estimator_has('wrapped_estimator_'))
it should be replaced with the name of the function being checked for:
@available_if(_estimator_has('predict_proba')) (or whatever the relevant function is)
based on:
scikit-learn/scikit-learn#20506

This is implemented in my fork here

@DrJStrudwick
Copy link

Any update on this?

@mprytoluk
Copy link

I believe it's safe to say this project is dead. Some fork on this project would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants