-
-
Notifications
You must be signed in to change notification settings - Fork 26.3k
CLN Improve doc/error consistency for GaussianProcessRegressor #19687
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8db148a
Improve documentation consistency for GaussianProcessRegressor
chrisyeh96 44c834f
Apply suggestions from code review
chrisyeh96 68b04ec
More code / documentation improvements for clarity in GPR
chrisyeh96 fe67c9e
Undo np.dot -> @
chrisyeh96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,9 @@ class GaussianProcessRegressor(MultiOutputMixin, | |
GaussianProcessRegressor: | ||
|
||
* allows prediction without prior fitting (based on the GP prior) | ||
* provides an additional method sample_y(X), which evaluates samples | ||
* provides an additional method `sample_y(X)`, which evaluates samples | ||
drawn from the GPR (prior or posterior) at given inputs | ||
* exposes a method log_marginal_likelihood(theta), which can be used | ||
* exposes a method `log_marginal_likelihood(theta)`, which can be used | ||
externally for other ways of selecting hyperparameters, e.g., via | ||
Markov chain Monte Carlo. | ||
|
||
|
@@ -68,8 +68,8 @@ class GaussianProcessRegressor(MultiOutputMixin, | |
must have the signature:: | ||
|
||
def optimizer(obj_func, initial_theta, bounds): | ||
# * 'obj_func' is the objective function to be minimized, which | ||
# takes the hyperparameters theta as parameter and an | ||
# * 'obj_func': the objective function to be minimized, which | ||
# takes the hyperparameters theta as a parameter and an | ||
# optional flag eval_gradient, which determines if the | ||
# gradient is returned additionally to the function value | ||
# * 'initial_theta': the initial value for theta, which can be | ||
|
@@ -80,7 +80,7 @@ def optimizer(obj_func, initial_theta, bounds): | |
# the corresponding value of the target function. | ||
return theta_opt, func_min | ||
|
||
Per default, the 'L-BGFS-B' algorithm from scipy.optimize.minimize | ||
Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize | ||
is used. If None is passed, the kernel's parameters are kept fixed. | ||
Available internal optimizers are:: | ||
|
||
|
@@ -113,7 +113,7 @@ def optimizer(obj_func, initial_theta, bounds): | |
random_state : int, RandomState instance or None, default=None | ||
Determines random number generation used to initialize the centers. | ||
Pass an int for reproducible results across multiple function calls. | ||
See :term: `Glossary <random_state>`. | ||
See :term:`Glossary <random_state>`. | ||
|
||
Attributes | ||
---------- | ||
|
@@ -211,8 +211,8 @@ def fit(self, X, y): | |
if self.alpha.shape[0] == 1: | ||
self.alpha = self.alpha[0] | ||
else: | ||
raise ValueError("alpha must be a scalar or an array" | ||
" with same number of entries as y.(%d != %d)" | ||
raise ValueError("alpha must be a scalar or an array " | ||
"with same number of entries as y. (%d != %d)" | ||
% (self.alpha.shape[0], y.shape[0])) | ||
|
||
self.X_train_ = np.copy(X) if self.copy_X_train else X | ||
|
@@ -283,9 +283,9 @@ def predict(self, X, return_std=False, return_cov=False): | |
"""Predict using the Gaussian process regression model | ||
|
||
We can also predict based on an unfitted model by using the GP prior. | ||
In addition to the mean of the predictive distribution, also its | ||
standard deviation (return_std=True) or covariance (return_cov=True). | ||
Note that at most one of the two can be requested. | ||
In addition to the mean of the predictive distribution, optionally also | ||
returns its standard deviation (`return_std=True`) or covariance | ||
(`return_cov=True`). Note that at most one of the two can be requested. | ||
|
||
Parameters | ||
---------- | ||
|
@@ -302,7 +302,7 @@ def predict(self, X, return_std=False, return_cov=False): | |
|
||
Returns | ||
------- | ||
y_mean : ndarray of shape (n_samples, [n_output_dims]) | ||
y_mean : ndarray of shape (n_samples,) or (n_samples, n_targets) | ||
Mean of predictive distribution a query points. | ||
|
||
y_std : ndarray of shape (n_samples,), optional | ||
|
@@ -315,8 +315,7 @@ def predict(self, X, return_std=False, return_cov=False): | |
""" | ||
if return_std and return_cov: | ||
raise RuntimeError( | ||
"Not returning standard deviation of predictions when " | ||
"returning full covariance.") | ||
"At most one of return_std or return_cov can be requested.") | ||
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. This is a code change. Given the title of the PR, I would revert. |
||
|
||
if self.kernel is None or self.kernel.requires_vector_input: | ||
X = self._validate_data(X, ensure_2d=True, dtype="numeric", | ||
|
@@ -389,21 +388,22 @@ def sample_y(self, X, n_samples=1, random_state=0): | |
|
||
Parameters | ||
---------- | ||
X : array-like of shape (n_samples, n_features) or list of object | ||
X : array-like of shape (n_samples_X, n_features) or list of object | ||
Query points where the GP is evaluated. | ||
|
||
n_samples : int, default=1 | ||
The number of samples drawn from the Gaussian process | ||
Number of samples drawn from the Gaussian process per query point | ||
|
||
random_state : int, RandomState instance or None, default=0 | ||
Determines random number generation to randomly draw samples. | ||
Pass an int for reproducible results across multiple function | ||
calls. | ||
See :term: `Glossary <random_state>`. | ||
See :term:`Glossary <random_state>`. | ||
|
||
Returns | ||
------- | ||
y_samples : ndarray of shape (n_samples_X, [n_output_dims], n_samples) | ||
y_samples : ndarray of shape (n_samples_X, n_samples), or \ | ||
(n_samples_X, n_targets, n_samples) | ||
Values of n_samples samples drawn from Gaussian process and | ||
evaluated at query points. | ||
""" | ||
|
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.
This is a code change. Given the title of the PR, I would revert.