8000 fix: deviance computation in BinomialDeviance was wrong (ignored case… · deepatdotnet/scikit-learn@2da9f01 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2da9f01

Browse files
pprettlarsmans
authored andcommitted
fix: deviance computation in BinomialDeviance was wrong (ignored cases where y == 0) - thanks to ChrisBeaumont for reporting this issue
1 parent f4bd2ca commit 2da9f01

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sklearn/ensemble/gradient_boosting.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,22 @@ def __call__(self, y, pred):
340340
"""Compute the deviance (= negative log-likelihood). """
341341
# logaddexp(0, v) == log(1.0 + exp(v))
342342
pred = pred.ravel()
343-
return np.sum(np.logaddexp(0.0, -2 * y * pred)) / y.shape[0]
343+
return -2.0 * np.mean((y * pred) - np.logaddexp(0.0, pred))
344344

345345
def negative_gradient(self, y, pred, **kargs):
346+
"""Compute the residual (= negative gradient). """
346347
return y - 1.0 / (1.0 + np.exp(-pred.ravel()))
347348

348349
def _update_terminal_region(self, tree, terminal_regions, leaf, X, y,
349350
residual, pred):
350-
"""Make a single Newton-Raphson step. """
351+
"""Make a single Newton-Raphson step.
352+
353+
our node estimate is given by:
354+
355+
sum(y - prob) / sum(prob * (1 - prob))
356+
357+
we take advantage that: y - prob = residual
358+
"""
351359
terminal_region = np.where(terminal_regions == leaf)[0]
352360
residual = residual.take(terminal_region, axis=0)
353361
y = y.take(terminal_region, axis=0)

0 commit comments

Comments
 (0)
0