2
votes

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?

1
The implementation of predict_proba differs per loss function, so you'd better pickle the whole estimator.Fred Foo

1 Answers

3
votes

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?