@@ -329,10 +329,10 @@ def __init__(self, estimator, param_grid, loss_func=None, score_func=None,
329329 self .pre_dispatch = pre_dispatch
330330
331331 def _set_methods (self ):
332- if hasattr (self ._best_estimator_ , 'predict' ):
333- self .predict = self ._best_estimator_ .predict
334- if hasattr (self ._best_estimator_ , 'predict_proba' ):
335- self .predict_proba = self ._best_estimator_ .predict_proba
332+ if hasattr (self .best_estimator_ , 'predict' ):
333+ self .predict = self .best_estimator_ .predict
334+ if hasattr (self .best_estimator_ , 'predict_proba' ):
335+ self .predict_proba = self .best_estimator_ .predict_proba
336336
337337 def fit (self , X , y = None , ** params ):
338338 """Run fit with all sets of parameters
@@ -379,7 +379,7 @@ def _fit(self, X, y):
379379 params = next (iter (grid ))
380380 base_clf .set_params (** params )
381381 base_clf .fit (X , y )
382- self ._best_estimator_ = base_clf
382+ self .best_estimator_ = base_clf
383383 self ._set_methods ()
384384 return self
385385
@@ -434,7 +434,7 @@ def _fit(self, X, y):
434434 # clone first to work around broken estimators
435435 best_estimator = clone (base_clf ).set_params (** best_params )
436436 best_estimator .fit (X , y , ** self .fit_params )
437- self ._best_estimator_ = best_estimator
437+ self .best_estimator_ = best_estimator
438438 self ._set_methods ()
439439
440440 # Store the computed scores
@@ -455,14 +455,3 @@ def score(self, X, y=None):
455455 % self .best_estimator_ )
456456 y_predicted = self .predict (X )
457457 return self .score_func (y , y_predicted )
458-
459- # TODO around 0.13: remove this property, make it an attribute
460- @property
461- def best_estimator_ (self ):
462- if hasattr (self , '_best_estimator_' ):
463- return self ._best_estimator_
464- else :
465- raise RuntimeError ("Grid search has to be run with 'refit=True'"
466- " to make predictions or obtain an instance of the best "
467- " estimator. To obtain the best parameter settings, "
468- " use ``best_params_``." )
0 commit comments