diff --git a/sklearn/gaussian_process/gpr.py b/sklearn/gaussian_process/gpr.py index ac1b1f6d6254a..3452fc5216931 100644 --- a/sklearn/gaussian_process/gpr.py +++ b/sklearn/gaussian_process/gpr.py @@ -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): @@ -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 @@ -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) @@ -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))