how to print estimated coefficients after a (GridSearchCV) fit a model? (SGDRegressor)

后端 未结 2 2029
旧时难觅i
旧时难觅i 2021-02-06 04:08

I am new to scikit-learn, but it did what I was hoping for. Now, maddeningly, the only remaining issue is that I don\'t find how I could print (or even better, writ

相关标签:
2条回答
  • 2021-02-06 04:32

    I think you might be looking for estimated parameters of the "best" model rather than the hyper-parameters determined through grid-search. You can plug the best hyper-parameters from grid-search ('alpha' and 'l1_ratio' in your case) back to the model ('SGDClassifier' in your case) to train again. You can then find the parameters from the fitted model object.

    The code could be something like this:

    model2 = SGDClassifier(penalty='elasticnet',n_iter = np.ceil(10**6 / n),shuffle=True, alpha = gs.best_params_['alpha'], l1_ratio=gs.best_params_['l1_ratio'])
    print(model2.coef_)
    
    0 讨论(0)
  • 2021-02-06 04:41

    The SGDClassifier instance fitted with the best hyperparameters is stored in gs.best_estimator_. The coef_ and intercept_ are the fitted parameters of that best model.

    0 讨论(0)
提交回复
热议问题