Skip to content

BUG log_loss renormalizes the predictions #24515

@lorentzenchr

Description

@lorentzenchr

Describe the bug

log_loss(y_true, y_pred) renormalizes y_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

from scipy.special import xlogy
from sklearn.metrics import log_loss

y_true = [[0, 1]]
y_pred = [[0.2, 0.3]]

log_loss(y_true, y_pred)

Expected Results

-xlogy(y_true, y_pred).sum(axis=1)

Result: 1.2039728

Actual Results

Result: 0.5108256237659907

Versions

System:
    python: 3.9.14
   machine: macOS

Python dependencies:
      sklearn: 1.1.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions