8000 API Removes tol=None option from HistGradientBoosting* by thomasjpfan · Pull Request #19296 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

API Removes tol=None option from HistGradientBoosting* #19296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _validate_parameters(self):
raise ValueError(
'validation_fraction={} must be strictly '
'positive, or None.'.format(self.validation_fraction))
if self.tol is not None and self.tol < 0:
if self.tol < 0:
raise ValueError('tol={} '
'must not be smaller than 0.'.format(self.tol))

Expand Down Expand Up @@ -646,8 +646,7 @@ def _should_stop(self, scores):
# harder for subsequent iteration to be considered an improvement upon
# the reference score, and therefore it is more likely to early stop
# because of the lack of significant improvement.
tol = 0 if self.tol is None else self.tol
reference_score = scores[-reference_position] + tol
reference_score = scores[-reference_position] + self.tol
recent_scores = scores[-reference_position + 1:]
recent_improvements = [score > reference_score
for score in recent_scores]
Expand Down Expand Up @@ -992,7 +991,7 @@ class HistGradientBoostingRegressor(RegressorMixin, BaseHistGradientBoosting):
stopped when none of the last ``n_iter_no_change`` scores are better
than the ``n_iter_no_change - 1`` -th-to-last one, up to some
tolerance. Only used if early stopping is performed.
tol : float or None, default=1e-7
tol : float, default=1e-7
The absolute tolerance to use when comparing scores during early
stopping. The higher the tolerance, the more likely we are to early
stop: higher tolerance means that it will be harder for subsequent
Expand Down Expand Up @@ -1245,7 +1244,7 @@ class HistGradientBoostingClassifier(ClassifierMixin,
stopped when none of the last ``n_iter_no_change`` scores are better
than the ``n_iter_no_change - 1`` -th-to-last one, up to some
tolerance. Only used if early stopping is performed.
tol : float or None, default=1e-7
tol : float, default=1e-7
The absolute tolerance to use when comparing scores. The higher the
tolerance, the more likely we are to early stop: higher tolerance
means that it will be harder for subsequent iterations to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_invalid_classification_loss():
(None, None, True, 5, 1e-1),
('loss', .1, True, 5, 1e-7), # use loss
('loss', None, True, 5, 1e-1), # use loss on training data
(None, None, False, 5, None), # no early stopping
(None, None, False, 5, 0.0), # no early stopping
])
def test_early_stopping_regression(scoring, validation_fraction,
early_stopping, n_iter_no_change, tol):
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_early_stopping_regression(scoring, validation_fraction,
(None, None, True, 5, 1e-1),
('loss', .1, True, 5, 1e-7), # use loss
('loss', None, True, 5, 1e-1), # use loss on training data
(None, None, False, 5, None), # no early stopping
(None, None, False, 5, 0.0), # no early stopping
])
def test_early_stopping_classification(data, scoring, validation_fraction,
early_stopping, n_iter_no_change, tol):
Expand Down
0