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

AttributeError: module 'eli5' has no attribute 'show_prediction' only in Docker Image #345

Closed wesley-pattison closed 4 years ago

wesley-pattison commented 4 years ago

Hi,

I have a strange situation here. When I call my endpoint on the FastApi app locally through Postman, I can successfully get back the results of show_prediction() however, once I throw this Api into a docker container and run the same call through Postman, I get the error below:

Traceback (most recent call last):
  File "/app/main.py", line 73, in explain
    t_pred = te.show_prediction()
  File "/usr/local/lib/python3.7/site-packages/eli5/lime/lime.py", line 278, in show_prediction
    return eli5.show_prediction(self.clf_, self.doc_, vec=self.vec_,
AttributeError: module 'eli5' has no attribute 'show_prediction'

Partial Code:

from eli5.lime import TextExplainer
import eli5
....
te.fit(request.statement, prediction_generator.explain_statements)
t_pred = te.show_prediction() # FAILS HERE with error above.

Docker File:

FROM tiangolo/uvicorn-gunicorn:python3.7

COPY ./requirements.txt /var/www/requirements.txt
RUN pip install --upgrade pip
RUN pip install -r /var/www/requirements.txt

COPY ./app /app

Requirements.txt

fastapi==0.41.0
uvicorn==0.9.0
scikit-learn==0.21.2
pandas==0.24.2
Keras==2.2.4
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
eli5==0.10.1
numpy==1.16.4
tensorflow==1.14.0
tensorflow-estimator==1.14.0
psathyrella commented 4 years ago

I'm also getting this error, neither show_weights() nor show_prediction() seem to actually exist in the 0.10 version pulled from pypi, although there's references to them if you grep through the install directory. Perhaps there was an interface change that is not yet reflected in the docs, since the readthedocs.io changelog only goes up to 0.9, and does not show the version that pypi gives you (0.10).

I'm on python 2.7, ubuntu 16.04, eli5 0.10.1

lopuhin commented 4 years ago

Looks like the docs didn't rebuild properly in the last release, thanks for pointing out. Release notes for 0.10 and up are here https://github.com/TeamHG-Memex/eli5/blob/master/CHANGES.rst - so no API changes.

I just did a fresh install of eli5 to be extra sure, and indeed eli5.show_prediction and eli5.show_weights are missing 😱 . This is definitely not intended, could be due to some updated dependencies, looking into it.

lopuhin commented 4 years ago

Actually this is expected: eli5.show_prediction is for showing predictions in jupyter notebooks, and needs at least ipython installed to work. So solution here is to also install ipython if they are needed. Or to use various export functions to export explanations in different formats, if used outside of jupyter notebook.

lopuhin commented 4 years ago

I'm closing this but please tell if anything still needs to be fixed or looks weird.

psathyrella commented 4 years ago

This is great, thanks for the explanation.