Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass argument to scoring function in scikit-learn's LogisticRegressionCV call

Problem

I am trying to use scikit-learn's LogisticRegressionCV with roc_auc_score as the scoring metric.

from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score

clf = LogisticRegressionCV(scoring=roc_auc_score)

But when I attempt to fit the model (clf.fit(X, y)), it throws an error.

 ValueError: average has to be one of (None, 'micro', 'macro', 'weighted', 'samples')

That's cool. It's clear what's going on: roc_auc_score needs to be called with the average argument specified, per its documentation and the error above. So I tried that.

clf = LogisticRegressionCV(scoring=roc_auc_score(average='weighted'))

But it turns out that roc_auc_score can't be called with an optional argument alone, because this throws another error.

TypeError: roc_auc_score() takes at least 2 arguments (1 given)

Question

Any thoughts on how I can use roc_auc_score as the scoring metric for LogisticRegressionCV in a way that I can specify an argument for the scoring function?

I can't find an SO question on this issue or a discussion of this issue in scikit-learn's GitHub repo, but surely someone has run into this before?

like image 681
Gyan Veda Avatar asked Aug 19 '16 17:08

Gyan Veda


1 Answers

A bit late (4 years later). But today you can use:

clf = LogisticRegressionCV(scoring='roc_auc')

Also, all other scoring keys can be obtained through:

from sklearn.metrics import SCORERS
print(SCORERS.keys())
like image 181
Nicow Avatar answered Sep 28 '22 23:09

Nicow