ImportError: cannot import name 'det_curve' from 'sklearn.metrics'

Viewed 5812

I don't know why I am getting this error, the official document reference
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.det_curve.html#sklearn.metrics.det_curve

Code:

import numpy as np
from sklearn.metrics import det_curve

fpr, fnr, thresholds = det_curve(y_test, y_pred)
print(fpr, fnr, thresholds) 

Error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-46-d8d6f0b546ca> in <module>()
     10 
     11 import numpy as np
---> 12 from sklearn.metrics import det_curve
     13 
     14 fpr, fnr, thresholds = det_curve(y_test['cEXT'], y_pred)

ImportError: cannot import name 'det_curve' from 'sklearn.metrics' (/usr/local/lib/python3.7/dist-packages/sklearn/metrics/__init__.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
2 Answers

Looks like some issue with a missing package. Try the following:

pip uninstall -v scikit-learn

pip install -v scikit-learn

This might install the related dependencies along with it.

Same kind of problem happened to me in my Jupyter notebook. I uninstall and re-install both scikit-learn and imblearn. It didn't work. Then restarting the kernel and running again solved the problem.

Related