10000 FIX Fixed gradient computation in gradient boosting for multiclass cl… · NicolasHug/scikit-learn@e73acef · GitHub
[go: up one dir, main page]

Skip to content

Commit e73acef

Browse files
NicolasHugadrinjalali
authored andcommitted
FIX Fixed gradient computation in gradient boosting for multiclass classification (scikit-learn#12715)
* Fixed gradient update * Added whatsnew entry
1 parent 785b4b9 commit e73acef

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

doc/whats_new/v0.21.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ random sampling procedures.
2424
`max_leaf_nodes` are set. |Fix|
2525
- :class:`linear_model.LogisticRegression` and
2626
:class:`linear_model.LogisticRegressionCV` with 'saga' solver. |Fix|
27+
- :class:`ensemble.GradientBoostingClassifier` for multiclass
28+
classification. |Fix|
2729

2830

2931
Details are listed in the changelog below.
@@ -71,6 +73,10 @@ Support for Python 3.4 and below has been officially dropped.
7173
communication overhead. :issue:`12543` by :user:`Isaac Storch <istorch>`
7274
and `Olivier Grisel`_.
7375

76+
- |Fix| Fixed a bug in :class:`ensemble.GradientBoostingClassifier` where
77+
the gradients would be incorrectly computed in multiclass classification
78+
problems. :issue:`12715` by :user:` D473 Nicolas Hug<NicolasHug>`.
79+
7480
:mod:`sklearn.linear_model`
7581
...........................
7682

sklearn/ensemble/gradient_boosting.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,11 +1163,17 @@ def _fit_stage(self, i, X, y, y_pred, sample_weight, sample_mask,
11631163
loss = self.loss_
11641164
original_y = y
11651165

1166+
# Need to pass a copy of y_pred to negative_gradient() because y_pred
1167+
# is partially updated at the end of the loop in
1168+
# update_terminal_regions(), and gradients need to be evaluated at
1169+
# iteration i - 1.
1170+
y_pred_copy = y_pred.copy()
1171+
11661172
for k in range(loss.K):
11671173
if loss.is_multi_class:
11681174
y = np.array(original_y == k, dtype=np.float64)
11691175

1170-
residual = loss.negative_gradient(y, y_pred, k=k,
1176+
residual = loss.negative_gradient(y, y_pred_copy, k=k,
11711177
sample_weight=sample_weight)
11721178

11731179
# induce regression tree on residuals

0 commit comments

Comments
 (0)
0