-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Prevent division by zero in GPR when y_train is constant #18388
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4b0d894
add very small number to the y_train.std to avoid a divide by zero error
2bc2c92
add very small number to the y_train.std to avoid a divide by zero er…
7b91bc6
adding an if check to add epsilon only when _y_train_std==0
b0d2115
proper if check included to add epsilon only when _y_train_std==0
84a78f4
assign _y_train.std to 1 when _y_train.std is zero to avoid divide by…
23b06b9
suggestions, by alfaro96, included to better understanding of the cod…
fc332cd
minor fix, includ missing whitespace around operator
ea55e6a
Included test for constant target to check the private _y_train_std a…
63ca232
Minor fixes after checking with flake8
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -536,3 +536,17 @@ def test_bound_check_fixed_hyperparameter(): | |
periodicity_bounds="fixed") # seasonal component | ||
kernel = k1 + k2 | ||
GaussianProcessRegressor(kernel=kernel).fit(X, y) | ||
|
||
|
||
@pytest.mark.parametrize('kernel', kernels) | ||
def test_constant_target(kernel): | ||
# Test for constant target(s), the private _y_train_std attribute has | ||
# a standard deviation of 1 instead of 0 | ||
gpr = GaussianProcessRegressor(kernel=kernel, normalize_y=True) | ||
# create a constant targets of 2 | ||
y = np.full((1, X.shape[0]), 2).ravel() | ||
expected_std = np.full((1, X.shape[0]), 1).ravel() | ||
gpr.fit(X, y) | ||
_y_train_std = gpr._y_train_std | ||
|
||
assert_array_equal(_y_train_std, expected_std) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please expand the test and call |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please use as done
_handle_zeros_in_scale
in #19361 instead?