eli5-org / eli5

A library for debugging/inspecting machine learning classifiers and explaining their predictions
MIT License
257 stars 41 forks source link

Unable to import eli5 #34

Open nkadochn opened 1 year ago

nkadochn commented 1 year ago

I just pip installed eli5 0.13.0 on a new AzureML instance and it is throwing an exception during "import eli5"

The sklearn.feature_selection.base 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.feature_selection. Anything that cannot be imported from sklearn.feature_selection is now part of the private API. Using TensorFlow backend.

AttributeError Traceback (most recent call last) Input In [59], in <cell line: 1>() ----> 1 import eli5

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/eli5/init.py:93, in 89 pass 92 try: ---> 93 from .keras import ( 94 explain_prediction_keras 95 ) 96 except ImportError: 97 # keras is not available 98 pass

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/eli5/keras/init.py:3, in 1 # -- coding: utf-8 -- ----> 3 from .explain_prediction import explain_prediction_keras 4 from .gradcam import gradcam, gradcam_backend

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/eli5/keras/explain_prediction.py:8, in 5 import PIL 7 import numpy as np ----> 8 import keras 9 import keras.backend as K 10 from keras.models import Model

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/keras/init.py:25, in 22 from keras import distribute 24 # See b/110718070#comment18 for more details about this import. ---> 25 from keras import models 27 from keras.engine.input_layer import Input 28 from keras.engine.sequential import Sequential

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/keras/models.py:19, in 16 """Code for model cloning, plus model-related API entries.""" 18 import tensorflow.compat.v2 as tf ---> 19 from keras import backend 20 from keras import metrics as metrics_module 21 from keras import optimizer_v1

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/keras/backend/init.py:1, in ----> 1 from .load_backend import epsilon 2 from .load_backend import set_epsilon 3 from .load_backend import floatx

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/keras/backend/load_backend.py:90, in 88 elif _BACKEND == 'tensorflow': 89 sys.stderr.write('Using TensorFlow backend.\n') ---> 90 from .tensorflow_backend import * 91 else: 92 # Try and load external backend. 93 try:

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py:25, in 22 import numpy as np 23 from distutils.version import StrictVersion ---> 25 from ..utils.generic_utils import transpose_shape 27 py_all = all 28 py_any = any

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/keras/utils/generic_utils.py:415, in 410 else: 411 return obj.name 414 @tf_contextlib.contextmanager --> 415 def skip_failed_serialization(): 416 global _SKIP_FAILED_SERIALIZATION 417 prev = _SKIP_FAILED_SERIALIZATION

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/keras/utils/tf_contextlib.py:33, in contextmanager(target) 23 """A tf_decorator-aware wrapper for contextlib.contextmanager. 24 25 Usage is identical to contextlib.contextmanager. (...) 30 A callable that can be used inside of a with statement. 31 """ 32 context_manager = _contextlib.contextmanager(target) ---> 33 return tf.internal.decorator.make_decorator(target, context_manager, 'contextmanager')

AttributeError: module 'tensorflow.compat.v2' has no attribute 'internal'

lopuhin commented 1 year ago

Thanks for the report. From the traceback, that looks to be an issue which would happen when you try to import keras as well, could you please check if it's installed correctly?

nkadochn commented 1 year ago

You are absolutely correct @lopuhin and thank you for the lightning fast response. Now if I select the "Python 3.8 - Pytorch and Tensorflow" enviroment, where Keras is working I can install and import eli5. But if I select "Python 3.8 - AzureML", where Keras is not operational I am unable to import eli5.

Since I am working with just xgboost and do not need Keras / TF environment, what would be the best way for me to import eli5, without triggering Keras issue?

nkadochn commented 1 year ago

@lopuhin, I also verified that running from tensorflow import keras works perfectly fine.

from tensorflow import keras keras.version '2.3.0-tf'