Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reinitializing learned linear models with scikit-learn

Say I run SGDRegressor or SGDClassifier, and get a set of coefficients that I want to use for the future. It's definitely trivial to do the basic predictions (since, for the regressor, it's just matrix multiplication), but it'd be nice to be able to get at the other methods on a fitted model (like predict_proba, etc.). Is there a way to do this in general? I've been looking through the docs and couldn't find anything.

Specific code example for clarity:

from sklearn import linear_model

sgd = linear_model.SGDRegressor()
sgd.fit([[0, 1, 1], [0, -1, 1]], [0, 1])
coefs = sgd.coef_
intercept = sgd.intercept_

And what I'd like to do is just keep coefs and intercept stored somewhere and then be able to reinitialize a SGDRegressor with them. Is that possible?

like image 816
Jeff Tratner Avatar asked Oct 24 '25 02:10

Jeff Tratner


1 Answers

Coefficiants may help you do some other calculations. But if it's not the case, you can save the learned model to your disc and use it later without reinitializing.

here is an example: scikit learn SVM, how to save/load support vectors?

like image 102
Bilal Dadanlar Avatar answered Oct 26 '25 15:10

Bilal Dadanlar