You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: cross_val_score fails with scoring='neg_log_loss' when not all labels are predicted #9144
This is a known problem for log_loss, which was fixed by adding an argument labels to that function: #4033
The problem above is, cross_val_score invokes that function, but does not allow us to pass the labels. Ideally, cross_val_score should be able to infer the true labels from y=df1.
We just need cross_val_score to pass labels=clf.classes_ as argument of log_loss.
As a side comment, it seems dangerous for the code to assume labels. Labels should not be an optional argument, particularly within a cross-validation function, where we have no idea if the training set will contain less classes than the training set. For example, suppose that the training set contains [-1,0], and the testing set contains [0,1]. The code will run assuming that the probability reported for "-1" corresponds to the probability of "0".
We just need cross_val_score to pass labels=clf.classes_ as argument of log_loss.
"just" ;) I think this is a pretty tricky issue, and I'm pretty sure I opened an issue to track it.
Right now I can only find #5097 that is only tangentially related. Basically the scorer objects should look at the classes_ attribute of the estimator. I don't think an argument to cross_val_score is the right way to go.
@jnothman hm I guess that makes sense for the training set score or when the CV doesn't use all the data. That's really tricky, though, right? How would that be possible with our API? at the creation of the scorer? and in the default case we do it at check_scorer?
Activity
JohnNapier commentedon Jun 16, 2017
I think something like this might fix it:
We just need cross_val_score to pass labels=clf.classes_ as argument of log_loss.
As a side comment, it seems dangerous for the code to assume labels. Labels should not be an optional argument, particularly within a cross-validation function, where we have no idea if the training set will contain less classes than the training set. For example, suppose that the training set contains [-1,0], and the testing set contains [0,1]. The code will run assuming that the probability reported for "-1" corresponds to the probability of "0".
Scary, isn't it?
amueller commentedon Jun 18, 2017
"just" ;) I think this is a pretty tricky issue, and I'm pretty sure I opened an issue to track it.
Right now I can only find #5097 that is only tangentially related. Basically the scorer objects should look at the
classes_attribute of the estimator. I don't think an argument tocross_val_scoreis the right way to go.amueller commentedon Jun 18, 2017
Found the right issue: #6231 wasn't by me after all!
jnothman commentedon Jun 18, 2017
amueller commentedon Jun 19, 2017
@jnothman hm I guess that makes sense for the training set score or when the CV doesn't use all the data. That's really tricky, though, right? How would that be possible with our API? at the creation of the scorer? and in the default case we do it at
check_scorer?amueller commentedon Jun 19, 2017
Close this as duplicate of #6231 and discuss there?
jnothman commentedon Jun 19, 2017
Yes.
mlewis1729 commentedon Sep 21, 2017
Just wanted to follow up with this discussion,
has there been any progress on solving the issue with log loss?
amueller commentedon Sep 21, 2017
@mlewis1729 check out #6231 and #9585. In the meantime you can specify
labelsexplicitly.John-Almardeny commentedon Aug 8, 2018
What I ended up doing is providing the
labelsexplicitly like this:Then use it like this:
Notes:
n_splitsvaluesRepeatedStratifiedKFoldto roughly ensure that each fold is representative of all strata of the data.