Skip to content

[MRG] Deprecated the rng_ attribute of GaussianProcessRegressor #8015

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
wants to merge 5 commits into from
Closed
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
18 changes: 16 additions & 2 deletions sklearn/gaussian_process/gpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sklearn.gaussian_process.kernels import RBF, ConstantKernel as C
from sklearn.utils import check_random_state
from sklearn.utils.validation import check_X_y, check_array
from sklearn.utils.deprecation import deprecated


class GaussianProcessRegressor(BaseEstimator, RegressorMixin):
Expand Down Expand Up @@ -140,6 +141,12 @@ def __init__(self, kernel=None, alpha=1e-10,
self.copy_X_train = copy_X_train
self.random_state = random_state

@property
@deprecated("Attribute ``rng`` is deprecated in version 0.19 and will be"
" removed in version 0.21.")
def rng(self):
return self._rng

def fit(self, X, y):
"""Fit Gaussian process regression model

Expand All @@ -161,7 +168,10 @@ def fit(self, X, y):
else:
self.kernel_ = clone(self.kernel)

self.rng = check_random_state(self.random_state)
self._rng = check_random_state(self.random_state)
# Deprecation 0.21
# Replace the above line by
# rng = check_random_state(self.random_state)

X, y = check_X_y(X, y, multi_output=True, y_numeric=True)

Expand Down Expand Up @@ -211,7 +221,11 @@ def obj_func(theta, eval_gradient=True):
bounds = self.kernel_.bounds
for iteration in range(self.n_restarts_optimizer):
theta_initial = \
self.rng.uniform(bounds[:, 0], bounds[:, 1])
self._rng.uniform(bounds[:, 0], bounds[:, 1])
# Deprecation 0.21
# Replace the above line by
# theta_initial = \
# rng.uniform(bounds[:, 0], bounds[:, 1])
optima.append(
self._constrained_optimization(obj_func, theta_initial,
bounds))
Expand Down