Skip to content

Log Loss gradient and hessian returns NaN for large negative values #28046

Closed
@lorentzenchr

Description

@lorentzenchr

Describe the bug

The private HalfBinomialLoss gradient and hessian returns np.NaN for large negative values of raw_prediction:

  • gradient
  • gradient_hessian
    Only the loss_gradient returns the correct gradient.

Steps/Code to Reproduce

import numpy as np
from sklearn._loss import HalfBinomialLoss

loss = HalfBinomialLoss()
y_true, raw = np.array([1.]), np.array([-1e3])
[
    loss.gradient(y_true, raw),
    loss.loss_gradient(y_true, raw),
    loss.gradient_hessian(y_true, raw),
]

Expected Results

gradient = -1 and hessian = 0

Actual Results

[array([nan]), (array([1000.]), array([-1.])), (array([nan]), array([nan]))]

Versions

sklearn: 1.3.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