Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG sample-weight ignored by min_sample_leaf in HGBDT #34745

Description

@glemaitre

Description

In the following course, we are using the weight of HGBDT to correct probability estimate. We know that it should be equivalent with a post-hoc correction. However, they are not equivalent for HGBDT while it works for logistic regression. In the past, we thought that it was due to the binning but it has been fixed (cf. #29641).

Potential cause (to be check further)

Splitter in sklearn/ensemble/_hist_gradient_boosting/splitting.pyx applies min_samples_leaf to histogram counts (n_samples_left / n_samples_right), not to the sum of sample weights (or hessians). Loss gradients/hessians (and bin edges after #29641) are weighted correctly.

Minimal reproducer

import numpy as np
from sklearn.base import clone
from sklearn.datasets import make_classification
from sklearn.ensemble import HistGradientBoostingClassifier

X, y = make_classification(
    n_samples=1000,
    n_features=10,
    n_informative=5,
    n_redundant=0,
    weights=[0.75, 0.25],
    random_state=0,
)
rng = np.random.RandomState(0)
sw = rng.randint(1, 4, size=len(y))
X_rep, y_rep = np.repeat(X, sw, axis=0), np.repeat(y, sw)


def max_raw_diff(min_samples_leaf):
    est = HistGradientBoostingClassifier(
        min_samples_leaf=min_samples_leaf,
        early_stopping=False,
        max_iter=50,
        random_state=0,
    )
    weighted = clone(est).fit(X, y, sample_weight=sw)
    repeated = clone(est).fit(X_rep, y_rep)
    return np.max(np.abs(weighted._raw_predict(X) - repeated._raw_predict(X)))


print(max_raw_diff(1))   # ~1e-8
print(max_raw_diff(20))  # ~2.4, unexpected

Observed on main (1.10.dev0):

  • min_samples_leaf=1: max |raw_pred| diff ≈ 4.6e-08
  • min_samples_leaf=20: max |raw_pred| diff ≈ 2.42

Expected behavior

Expect equivalence.

Notes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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