From ed0b5ecc7eb400b3502141b43e0888de818798b1 Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Thu, 8 Dec 2016 16:24:20 +0530 Subject: [PATCH 1/5] DPR: deprecated rng_ --- sklearn/gaussian_process/gpr.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sklearn/gaussian_process/gpr.py b/sklearn/gaussian_process/gpr.py index ac1b1f6d6254a..66679c5f378a5 100644 --- a/sklearn/gaussian_process/gpr.py +++ b/sklearn/gaussian_process/gpr.py @@ -140,6 +140,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" + " used only as a variable in version 0.21.") + def rng_(self): + return self._rng_ + def fit(self, X, y): """Fit Gaussian process regression model @@ -161,7 +167,7 @@ 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) X, y = check_X_y(X, y, multi_output=True, y_numeric=True) @@ -211,7 +217,7 @@ 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]) optima.append( self._constrained_optimization(obj_func, theta_initial, bounds)) From 1f0d0cd320113cc86485f72aa95d50f117fdfb26 Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Thu, 8 Dec 2016 23:37:13 +0530 Subject: [PATCH 2/5] FIX: removed trailing underscore and added import --- sklearn/gaussian_process/gpr.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sklearn/gaussian_process/gpr.py b/sklearn/gaussian_process/gpr.py index 66679c5f378a5..3970dc1773d33 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): @@ -143,8 +144,8 @@ def __init__(self, kernel=None, alpha=1e-10, @property @deprecated("Attribute ``rng_`` is deprecated in version 0.19 and will be" " used only as a variable in version 0.21.") - def rng_(self): - return self._rng_ + def rng(self): + return self._rng def fit(self, X, y): """Fit Gaussian process regression model @@ -167,7 +168,7 @@ 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) X, y = check_X_y(X, y, multi_output=True, y_numeric=True) @@ -217,7 +218,7 @@ 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]) optima.append( self._constrained_optimization(obj_func, theta_initial, bounds)) From f09e2912ee88a507e115e44c67d9aafcbce7b63e Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Thu, 8 Dec 2016 23:45:34 +0530 Subject: [PATCH 3/5] FIX: update deprecation --- sklearn/gaussian_process/gpr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/gaussian_process/gpr.py b/sklearn/gaussian_process/gpr.py index 3970dc1773d33..203bccdf7411d 100644 --- a/sklearn/gaussian_process/gpr.py +++ b/sklearn/gaussian_process/gpr.py @@ -142,8 +142,8 @@ def __init__(self, kernel=None, alpha=1e-10, self.random_state = random_state @property - @deprecated("Attribute ``rng_`` is deprecated in version 0.19 and will be" - " used only as a variable in version 0.21.") + @deprecated("Attribute ``rng`` is deprecated in version 0.19 and will be" + " removed in version 0.21.") def rng(self): return self._rng From 9c57d3157189655539feadbbcd9ec46c9cb27653 Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Sat, 10 Dec 2016 11:36:18 +0530 Subject: [PATCH 4/5] DPR: added comments for deprecation --- sklearn/gaussian_process/gpr.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sklearn/gaussian_process/gpr.py b/sklearn/gaussian_process/gpr.py index 203bccdf7411d..2266066beabb1 100644 --- a/sklearn/gaussian_process/gpr.py +++ b/sklearn/gaussian_process/gpr.py @@ -169,6 +169,9 @@ def fit(self, X, y): self.kernel_ = clone(self.kernel) 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) @@ -219,6 +222,9 @@ def obj_func(theta, eval_gradient=True): for iteration in range(self.n_restarts_optimizer): theta_initial = \ self._rng.uniform(bounds[:, 0], bounds[:, 1]) + # Deprecation 0.21 + # Replace the above line by + # rng.uniform(bounds[:, 0], bounds[:, 1]) optima.append( self._constrained_optimization(obj_func, theta_initial, bounds)) From c0df77eadf52bdcff6a23e68a55ad1389e27a044 Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Sat, 10 Dec 2016 11:59:59 +0530 Subject: [PATCH 5/5] FIX: remove pep8 errors --- sklearn/gaussian_process/gpr.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sklearn/gaussian_process/gpr.py b/sklearn/gaussian_process/gpr.py index 2266066beabb1..3452fc5216931 100644 --- a/sklearn/gaussian_process/gpr.py +++ b/sklearn/gaussian_process/gpr.py @@ -222,9 +222,10 @@ def obj_func(theta, eval_gradient=True): for iteration in range(self.n_restarts_optimizer): theta_initial = \ self._rng.uniform(bounds[:, 0], bounds[:, 1]) - # Deprecation 0.21 - # Replace the above line by - # 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))