25
25
from .externals .joblib import Parallel , delayed
26
26
from .externals import six
27
27
from .utils import check_random_state
28
- from .utils .validation import _num_samples , check_arrays
28
+ from .utils .validation import _num_samples , indexable
29
29
from .metrics .scorer import check_scoring
30
30
31
31
@@ -282,15 +282,13 @@ class BaseSearchCV(six.with_metaclass(ABCMeta, BaseEstimator,
282
282
"""Base class for hyper parameter search with cross-validation."""
283
283
284
284
@abstractmethod
285
- def __init__ (self , estimator , scoring = None , loss_func = None ,
286
- score_func = None , fit_params = None , n_jobs = 1 , iid = True ,
285
+ def __init__ (self , estimator , scoring = None ,
286
+ fit_params = None , n_jobs = 1 , iid = True ,
287
287
refit = True , cv = None , verbose = 0 , pre_dispatch = '2*n_jobs' ,
288
288
error_score = 'raise' ):
289
289
290
290
self .scoring = scoring
291
291
self .estimator = estimator
292
- self .loss_func = loss_func
293
- self .score_func = score_func
294
292
self .n_jobs = n_jobs
295
293
self .fit_params = fit_params if fit_params is not None else {}
296
294
self .iid = iid
@@ -349,20 +347,16 @@ def _fit(self, X, y, parameter_iterable):
349
347
350
348
estimator = self .estimator
351
349
cv = self .cv
352
- self .scorer_ = check_scoring (self .estimator , scoring = self .scoring ,
353
- loss_func = self .loss_func ,
354
- score_func = self .score_func )
350
+ self .scorer_ = check_scoring (self .estimator , scoring = self .scoring )
355
351
356
352
n_samples = _num_samples (X )
357
- X , y = check_arrays (X , y , allow_lists = True , sparse_format = 'csr' ,
358
- allow_nans = True )
353
+ X , y = indexable (X , y )
359
354
360
355
if y is not None :
361
356
if len (y ) != n_samples :
362
357
raise ValueError ('Target variable (y) has a different number '
363
358
'of samples (%i) than data (X: %i samples)'
364
359
% (len (y ), n_samples ))
365
- y = np .asarray (y )
366
360
cv = check_cv (cv , X , y , classifier = is_classifier (estimator ))
367
361
368
362
if self .verbose > 0 :
@@ -525,14 +519,14 @@ class GridSearchCV(BaseSearchCV):
525
519
degree=..., gamma=..., kernel='rbf', max_iter=-1,
526
520
probability=False, random_state=None, shrinking=True,
527
521
tol=..., verbose=False),
528
- fit_params={}, iid=..., loss_func=..., n_jobs=1, param_grid=... ,
529
- pre_dispatch =..., refit =..., score_func=..., scoring =...,
530
- verbose=...)
522
+ fit_params={}, iid=..., n_jobs=1,
523
+ param_grid =..., pre_dispatch =..., refit =...,
524
+ scoring=..., verbose=...)
531
525
532
526
533
527
Attributes
534
528
----------
535
- ` grid_scores_` : list of named tuples
529
+ grid_scores_ : list of named tuples
536
530
Contains scores for all parameter combinations in param_grid.
537
531
Each entry corresponds to one parameter setting.
538
532
Each named tuple has the attributes:
@@ -542,18 +536,18 @@ class GridSearchCV(BaseSearchCV):
542
536
cross-validation folds
543
537
* ``cv_validation_scores``, the list of scores for each fold
544
538
545
- ` best_estimator_` : estimator
539
+ best_estimator_ : estimator
546
540
Estimator that was chosen by the search, i.e. estimator
547
541
which gave highest score (or smallest loss if specified)
548
542
on the left out data.
549
543
550
- ` best_score_` : float
544
+ best_score_ : float
551
545
Score of best_estimator on the left out data.
552
546
553
- ` best_params_` : dict
547
+ best_params_ : dict
554
548
Parameter setting that gave the best results on the hold out data.
555
549
556
- ` scorer_` : function
550
+ scorer_ : function
557
551
Scorer function used on the held out data to choose the best
558
552
parameters for the model.
559
553
@@ -591,7 +585,7 @@ def __init__(self, estimator, param_grid, scoring=None, loss_func=None,
591
585
error_score = 'raise' ):
592
586
593
587
super (GridSearchCV , self ).__init__ (
594
- estimator , scoring , loss_func , score_func , fit_params , n_jobs , iid ,
588
+ estimator , scoring , fit_params , n_jobs , iid ,
595
589
refit , cv , verbose , pre_dispatch , error_score )
596
590
self .param_grid = param_grid
597
591
_check_param_grid (param_grid )
@@ -696,7 +690,7 @@ class RandomizedSearchCV(BaseSearchCV):
696
690
697
691
Attributes
698
692
----------
699
- ` grid_scores_` : list of named tuples
693
+ grid_scores_ : list of named tuples
700
694
Contains scores for all parameter combinations in param_grid.
701
695
Each entry corresponds to one parameter setting.
702
696
Each named tuple has the attributes:
@@ -706,15 +700,15 @@ class RandomizedSearchCV(BaseSearchCV):
706
700
cross-validation folds
707
701
* ``cv_validation_scores``, the list of scores for each fold
708
702
709
- ` best_estimator_` : estimator
703
+ best_estimator_ : estimator
710
704
Estimator that was chosen by the search, i.e. estimator
711
705
which gave highest score (or smallest loss if specified)
712
706
on the left out data.
713
707
714
- ` best_score_` : float
708
+ best_score_ : float
715
709
Score of best_estimator on the left out data.
716
710
717
- ` best_params_` : dict
711
+ best_params_ : dict
718
712
Parameter setting that gave the best results on the hold out data.
719
713
720
714
Notes
0 commit comments