3

I'm using the scikit-learn library for my daily MVA business. One of the functions I use is the roc_curve() method to get my ROC curves. The function returns the false-positive and true-positive rates. In my field (HEP), we prefer working with efficiencies, i.e. I want to normalise the number of true positives to the total number of positives.

To get what I need, I want to re-use the _binary_clf_curve() function in sklearn.metric.rankings, i.e.

def roc_curve_eff(y_true, y_score, pos_label=None, sample_weight=None) :
    fps, tps, _ = _binary_clf_curve(
        y_true, y_score, pos_label=pos_label, sample_weight=sample_weight)

    teff = tps / (tps[-1] - tps)
    feff = fps / (fps[-1] - fps)

    return feff, teff, _

and to load it into the local namespace I call from sklearn.metrics.rankings import _binary_clf_curve .

Doing so his gives me the following error:

ImportError                               
Traceback (most recent call last)
<ipython-input-10-d1d6b7292e7f> in <module>()
 11 from root_numpy import root2array, rec2array
 12 from sklearn.metrics import roc_curve, auc
---> 13 from sklearn.metrics.rankings import _binary_clf_curve
 14 
 15 #import sklearn as sklearn_

/Users/pigard/ROOT/install/lib/ROOT.pyc in _importhook(name, *args, **kwds)
299       except Exception:
300          pass
--> 301    return _orig_ihook( name, *args, **kwds )
302 
303 __builtin__.__import__ = _importhook

ImportError: No module named rankings

I think the issue here is the distinction between module and file: the _binary_clf_curve helper function is not added to the module (because it need not be exposed to the user) so I need to load it not from the module, but from the file?

1 Answer 1

0

Perhaps the solution is as easy as fixing a type-o? Try

from sklearn.metrics.ranking import _binary_clf_curve

with ranking and not rankings. That worked for me.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you James, I'm ashamed I missed that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.