ModuleNotFoundError: No module named 'sklearn.metrics.scorer'

5.1k Views Asked by At

I was trying to use the eli5 package in Python. Initially I was unable to install that, but later fixed it with conda install -c conda-forge eli5.

Now when I try to import eli5 into my Jupyter Notebbok, I get the following error: ModuleNotFoundError: No module named 'sklearn.metrics.scorer'.

How do I resolve this issue? I am trying to evaluate a model and use the eli5 command to give me the top 10 features.

2

There are 2 best solutions below

0
On BEST ANSWER

For those of you who have tried to import something from sklearn.metrics.scorer and got the error No module named 'sklearn.metrics.scorer', all you have to do is import the same objects from sklearn.metrics since the contents have been moved in the newer versions of sklearn (1.0+). List of scorers for example used to be accessible through from sklearn.metrics.scorer import SCORERS, but in the newer versions it is accessible through from sklearn.metrics import SCORERS.

And for @Supreetha Krishna's question, chances are you have had installed eli5 version 0.11.0, which according to eli5 documents is compatible with sklearn version 0.18+, alongside sklearn version 1.0+. However, the moving of the contents within sklearn.metrics.scorer has caused the error. You can either use pip (pip install eli5) to get the latest versions of eli5 (currently 0.13.0), in which this issue is resolved, or use conda to update eli5 package, since according to https://anaconda.org/conda-forge/eli5, conda currently uses version 0.13.0 of eli5 too.

0
On

I'm currently using scikit-learn version 1.3.2 and there is no module called scorer.py, it has changed to _scorer.py. Also the dict of all the scorer types has now been changed from SCORERS to _SCORERS.

So to solve your issue, the dict of scorers can be accessed via:

from sklearn.metrics._scorer import _SCORERS

If you just want a list of the available scorers then you can use the variable:

from sklearn.metrics import __all__