@@ -34,23 +34,11 @@ def __repr__(self):
34
34
return repr_str + '>'
35
35
36
36
def __init__ (self , base_estimator , scoring = None , n_jobs = 1 ):
37
- from sklearn .metrics import make_scorer , get_scorer
38
-
39
37
_check_estimator (base_estimator )
40
38
self .base_estimator = base_estimator
41
39
self .n_jobs = n_jobs
42
40
self .scoring = scoring
43
41
44
- # If scoring is None (default), the predictions are internally
45
- # generated by estimator.score(). Else, we must first get the
46
- # predictions based on the scorer.
47
- if not isinstance (self .scoring , str ):
48
- self .scoring = (make_scorer (self .scoring ) if self .scoring is
49
- not None else self .scoring )
50
-
51
- elif self .scoring is not None :
52
- self .scoring = get_scorer (self .scoring )
53
-
54
42
if not isinstance (self .n_jobs , int ):
55
43
raise ValueError ('n_jobs must be int, got %s' % n_jobs )
56
44
@@ -239,18 +227,29 @@
10000
def score(self, X, y):
239
227
score : array, shape (n_samples, n_estimators)
240
228
Score for each estimator / data slice couple.
241
229
"""
230
+ from sklearn .metrics import make_scorer , get_scorer
242
231
self ._check_Xy (X )
243
232
if X .shape [- 1 ] != len (self .estimators_ ):
244
233
raise ValueError ('The number of estimators does not match '
245
234
'X.shape[-1]' )
246
235
236
+ # If scoring is None (default), the predictions are internally
237
+ # generated by estimator.score(). Else, we must first get the
238
+ # predictions based on the scorer.
239
+ if not isinstance (self .scoring , str ):
240
+ scoring_ = (make_scorer (self .scoring ) if self .scoring is
241
+ not None else self .scoring )
242
+
243
+ elif self .scoring is not None :
244
+ scoring_ = get_scorer (self .scoring )
245
+
247
246
# For predictions/transforms the parallelization is across the data and
248
247
# not across the estimators to avoid memory load.
249
248
parallel , p_func , n_jobs = parallel_func (_sl_score , self .n_jobs )
250
249
n_jobs = min (n_jobs , X .shape [- 1 ])
251
250
X_splits = np .array_split (X , n_jobs , axis = - 1 )
252
251
est_splits = np .array_split (self .estimators_ , n_jobs )
253
- score = parallel (p_func (est , self . scoring , X , y )
252
+ score = parallel (p_func (est , scoring_ , X , y )
254
253
for (est , x ) in zip (est_splits , X_splits ))
255
254
256
255
if n_jobs > 1 :
@@ -400,18 +399,13 @@ class GeneralizationLight(SearchLight):
400
399
----------
401
400
base_estimator : object
402
401
The base estimator to iteratively fit on a subset of the dataset.
402
+ scoring : callable, string, defaults to None
403
+ Score function (or loss function) with signature
404
+ score_func(y, y_pred, **kwargs).
403
405
n_jobs : int, optional (default=1)
404
406
The number of jobs to run in parallel for both `fit` and `predict`.
405
407
If -1, then the number of jobs is set to the number of cores.
406
408
"""
407
- def __init__ (self , base_estimator , n_jobs = 1 ):
408
- _check_estimator (base_estimator )
409
- self .base_estimator = base_estimator
410
- self .n_jobs = n_jobs
411
-
412
- if not isinstance (self .n_jobs , int ):
413
- raise ValueError ('n_jobs must be int, got %s' % n_jobs )
414
-
415
409
def __repr__ (self ):
416
410
repr_str = super (GeneralizationLight , self ).__repr__ ()
417
411
if hasattr (self , 'estimators_' ):
0 commit comments