@@ -192,7 +192,7 @@ def classes_(self):
192
192
"""
193
193
return self .estimator_ .classes_
194
194
195
- def fit (self , X , y ):
195
+ def fit (self , X , y , ** fit_params ):
196
196
"""Fit the RFE model and then the underlying estimator on the selected features.
197
197
198
198
Parameters
@@ -203,14 +203,18 @@ def fit(self, X, y):
203
203
y : array-like of shape (n_samples,)
204
204
The target values.
205
205
206
+ **fit_params : dict
207
+ Additional parameters passed to the `fit` method of the underlying
208
+ estimator.
209
+
206
210
Returns
207
211
-------
208
212
self : object
209
213
Fitted estimator.
210
214
"""
211
- return self ._fit (X , y )
215
+ return self ._fit (X , y , ** fit_params )
212
216
213
- def _fit (self , X , y , step_score = None ):
217
+ def _fit (self , X , y , step_score = None , ** fit_params ):
214
218
# Parameter step_score controls the calculation of self.scores_
215
219
# step_score is not exposed to users
216
220
# and is used when implementing RFECV
@@ -269,7 +273,7 @@ def _fit(self, X, y, step_score=None):
269
273
if self .verbose > 0 :
270
274
print ("Fitting estimator with %d features." % np .sum (support_ ))
271
275
272
- estimator .fit (X [:, features ], y )
276
+ estimator .fit (X [:, features ], y , ** fit_params )
273
277
274
278
# Get importance and rank them
275
279
importances = _get_feature_importances (
@@ -296,7 +300,7 @@ def _fit(self, X, y, step_score=None):
296
300
# Set final attributes
297
301
features = np .arange (n_features )[support_ ]
298
302
self .estimator_ = clone (self .estimator )
299
- self .estimator_ .fit (X [:, features ], y )
303
+ self .estimator_ .fit (X [:, features ], y , ** fit_params )
300
304
301
305
# Compute step score when only n_features_to_select features left
302
306
if step_score :
@@ -325,7 +329,7 @@ def predict(self, X):
325
329
return self .estimator_ .predict (self .transform (X ))
326
330
327
331
@if_delegate_has_method (delegate = "estimator" )
328
- def score (self , X , y ):
332
+ def score (self , X , y , ** fit_params ):
329
333
"""Reduce X to the selected features and return the score of the underlying estimator.
330
334
331
335
Parameters
@@ -336,14 +340,20 @@ def score(self, X, y):
336
340
y : array of shape [n_samples]
337
341
The target values.
338
342
343
+ **fit_params : dict
344
+ Parameters to pass to the `score` method of the underlying
345
+ estimator.
346
+
347
+ .. versionadded:: 1.0
348
+
339
349
Returns
340
350
-------
341
351
score : float
342
352
Score of the underlying base estimator computed with the selected
343
353
features returned by `rfe.transform(X)` and `y`.
344
354
"""
345
355
check_is_fitted (self )
346
- return self .estimator_ .score (self .transform (X ), y )
356
+ return self .estimator_ .score (self .transform (X ), y , ** fit_params )
347
357
348
358
def _get_support_mask (self ):
349
359
check_is_fitted (self )
0 commit comments