-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
BUG log_loss renormalizes the predictions #24515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
can u share me the refernce of the code where the bug was there |
@TomDLT I'd be interested in you opinion. We hit this in #24365 (comment). |
I feel like computing a log loss with probabilities not summing to one does not make sense, so I am ok with the renormalization.
To me this is not a bad model (a model that has poor prediction accuracy), this is an incorrect model (a model that does not return results in the expected format), as would be a model that predicts negative probabilities. We could almost raise an error if the probabilities do not sum to one (or close), but I feel like it is simpler to just renormalize and compute the loss. |
To be honest, I strongly think renormalizing in the metric is methodologically wrong because this way the metric is not measuring the model prediction anymore. The model should take care of it's own predictions (i.e. make them sum to 1), not the metric! A metric is like a measuring device, say a scale (for measuring weight). We are measuring objects for a flight transport, so lighter is better. Renormalization is like measuring the weight of objects with their packaging removed. But the flight will have to carry the whole objects, with packaging included. |
I would be fine with raising a warning first and an error in the future. |
I agree with @lorentzenchr that the current behavior is very surprising and therefore it's a bug to me. |
What should be the behavior for larger from sklearn.metrics import log_loss
import numpy as np
y_true = [0, 1, 2]
y_pred = [[0, 0, 1], [0, 1, 0], [0, 0, 1]]
eps = 0.1
log_loss(y_true, y_pred, eps=eps)
# 0.9330788879075577
# `log_loss` will use a clipped `y_pred` for computing the log loss:
np.clip(y_pred, eps, 1 - eps)
# array([[0.1, 0.1, 0.9],
# [0.1, 0.9, 0.1],
# [0.1, 0.1, 0.9]]) We could just validate the input, i.e. scikit-learn/sklearn/metrics/_classification.py Lines 2629 to 2630 in d52e946
For me, I think that |
I agree with @thomasjpfan that |
@lorentzenchr Would it be okay for me to work on this issue? |
@OmarManzoor If the solution is clear to you, then yes. |
From what I can understand we need to raise a warning if |
@OmarManzoor Yes. You are very welcome to go ahead, open a PR and link it with this issue. Keep in mind that |
Sure thank you. |
Describe the bug
log_loss(y_true, y_pred)
renormalizesy_pred
internally such that it sums to 1. This way, a really bad model, the predictions of which do not sum to 1, gets a better loss then it actually has.Steps/Code to Reproduce
Expected Results
Result:
1.2039728
Actual Results
Result:
0.5108256237659907
Versions
The text was updated successfully, but these errors were encountered: