Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b943324

Browse filesBrowse files
thomasjpfanogrisel
andauthored
API Removes tol=None option from HistGradientBoosting* (#19296)
* API Removes tol=None option from HistGradient* * Pass tol=0.0 instead of tol=None in early stopping tests Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
1 parent 776f691 commit b943324
Copy full SHA for b943324

File tree

2 files changed

+6
-7
lines changed
Filter options

2 files changed

+6
-7
lines changed

‎sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py

Copy file name to clipboardExpand all lines: sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _validate_parameters(self):
8282
raise ValueError(
8383
'validation_fraction={} must be strictly '
8484
'positive, or None.'.format(self.validation_fraction))
85-
if self.tol is not None and self.tol < 0:
85+
if self.tol < 0:
8686
raise ValueError('tol={} '
8787
'must not be smaller than 0.'.format(self.tol))
8888

@@ -646,8 +646,7 @@ def _should_stop(self, scores):
646646
# harder for subsequent iteration to be considered an improvement upon
647647
# the reference score, and therefore it is more likely to early stop
648648
# because of the lack of significant improvement.
649-
tol = 0 if self.tol is None else self.tol
650-
reference_score = scores[-reference_position] + tol
649+
reference_score = scores[-reference_position] + self.tol
651650
recent_scores = scores[-reference_position + 1:]
652651
recent_improvements = [score > reference_score
653652
for score in recent_scores]
@@ -992,7 +991,7 @@ class HistGradientBoostingRegressor(RegressorMixin, BaseHistGradientBoosting):
992991
stopped when none of the last ``n_iter_no_change`` scores are better
993992
than the ``n_iter_no_change - 1`` -th-to-last one, up to some
994993
tolerance. Only used if early stopping is performed.
995-
tol : float or None, default=1e-7
994+
tol : float, default=1e-7
996995
The absolute tolerance to use when comparing scores during early
997996
stopping. The higher the tolerance, the more likely we are to early
998997
stop: higher tolerance means that it will be harder for subsequent
@@ -1245,7 +1244,7 @@ class HistGradientBoostingClassifier(ClassifierMixin,
12451244
stopped when none of the last ``n_iter_no_change`` scores are better
12461245
than the ``n_iter_no_change - 1`` -th-to-last one, up to some
12471246
tolerance. Only used if early stopping is performed.
1248-
tol : float or None, default=1e-7
1247+
tol : float, default=1e-7
12491248
The absolute tolerance to use when comparing scores. The higher the
12501249
tolerance, the more likely we are to early stop: higher tolerance
12511250
means that it will be harder for subsequent iterations to be

‎sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py

Copy file name to clipboardExpand all lines: sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_invalid_classification_loss():
8585
(None, None, True, 5, 1e-1),
8686
('loss', .1, True, 5, 1e-7), # use loss
8787
('loss', None, True, 5, 1e-1), # use loss on training data
88-
(None, None, False, 5, None), # no early stopping
88+
(None, None, False, 5, 0.0), # no early stopping
8989
])
9090
def test_early_stopping_regression(scoring, validation_fraction,
9191
early_stopping, n_iter_no_change, tol):
@@ -126,7 +126,7 @@ def test_early_stopping_regression(scoring, validation_fraction,
126126
(None, None, True, 5, 1e-1),
127127
('loss', .1, True, 5, 1e-7), # use loss
128128
('loss', None, True, 5, 1e-1), # use loss on training data
129-
(None, None, False, 5, None), # no early stopping
129+
(None, None, False, 5, 0.0), # no early stopping
130130
])
131131
def test_early_stopping_classification(data, scoring, validation_fraction,
132132
early_stopping, n_iter_no_change, tol):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.