@@ -381,6 +381,7 @@ class LinearModel(MetaEstimatorMixin, BaseEstimator):
381381 "predict" ,
382382 "predict_proba" ,
383383 "predict_log_proba" ,
384+ "_estimator_type" , # remove after sklearn 1.6
384385 "decision_function" ,
385386 "score" ,
386387 "classes_" ,
@@ -428,14 +429,23 @@ def __getattr__(self, attr):
428429 def _fit_transform (self , X , y ):
429430 return self .fit (X , y ).transform (X )
430431
431- def _validate_params (self ):
432- is_predictor = is_regressor (self ._orig_model ) or is_classifier (self ._orig_model )
432+ def _validate_params (self , X ):
433+ model = self ._orig_model
434+ if isinstance (model , MetaEstimatorMixin ):
435+ model = model .estimator
436+ is_predictor = is_regressor (model ) or is_classifier (model )
433437 if not is_predictor :
434438 raise ValueError (
435439 "Linear model should be a supervised predictor "
436440 "(classifier or regressor)"
437441 )
438442
443+ # For sklearn < 1.6
444+ try :
445+ self ._check_n_features (X , reset = True )
446+ except AttributeError :
447+ pass
448+
439449 def fit (self , X , y , ** fit_params ):
440450 """Estimate the coefficients of the linear model.
441451
@@ -456,7 +466,7 @@ def fit(self, X, y, **fit_params):
456466 self : instance of LinearModel
457467 Returns the modified instance.
458468 """
459- self ._validate_params ()
469+ self ._validate_params (X )
460470 X , y = validate_data (self , X , y , multi_output = True )
461471
462472 # fit the Model
0 commit comments