Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

python - Return coefficients after Pipeline, GridSearch, and Target Transformation

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_'
question from:https://stackoverflow.com/questions/65940390/return-coefficients-after-pipeline-gridsearch-and-target-transformation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...