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

后端 未结 2 2030
旧时难觅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_)
    

提交回复
热议问题