2

This question has been asked before, here and here. When I try those answers, my error message is that my model has no attribute of coef. I use a pipeline, gridsearch, and Target Transformation. I can access the model itself, but my error message is that my model, SGDRegressor has no attribute coef_.

cv_inner = KFold(n_splits=5, shuffle=True)
params = {'model__regressor__penalty':['elasticnet']
            ,'model__regressor__l1_ratio': [0.1,0.3]
            }
mymodel = Pipeline(steps = [('preprocessor', preprocessor),
                                ('model', TTR(regressor=SGDRegressor(n_jobs=-1),transformer=qt))
                                ])
optimize_hparams = GridSearchCV(
    estimator = mymodel, param_grid=params, n_jobs = -1,
    cv=cv_inner, scoring='neg_mean_absolute_error')
optimize_hparams.fit(X, y)
optimize_hparams.best_estimator_.named_steps['model'].regressor.coef_
# 'SGDRegressor' object has no attribute 'coef_'
Jack Armstrong
  • 1,182
  • 4
  • 26
  • 59

1 Answers1

3

The TransformedTargetRegressor attribute regressor is the input unfitted estimator. You want regressor_, the fitted regressor. (Note the documentation says that regressor gets cloned prior to fitting, which is why the attribute remains unfitted.)

Ben Reiniger
  • 10,517
  • 3
  • 16
  • 29