4

I am using scikit-learn's linear_model.LogisticRegression to perform multinomial logistic regress. I would like to initialize the solver's seed value, i.e. I want to give the solver its initial guess as the coefficients' values.

Does anyone know how to do that? I have looked online and sifted through the code too, but haven't found an answer. Thanks!

sa_zy
  • 331
  • 1
  • 10
  • http://stackoverflow.com/questions/24438779/creating-a-sklearn-linear-model-logisticregression-instance-from-existing-coeffi – timbmg Dec 27 '16 at 13:34
  • Per the documentation it appears these are the only options available `solver : {‘newton-cg’, ‘lbfgs’, ‘liblinear’, ‘sag’}, default: ‘liblinear’`. Furthermore it seems multinomial only accepts `'newton-cg' or 'lbfgs'`. – gold_cy Dec 27 '16 at 14:27
  • Thank you @blckbird, the question in the link is about changing the fields of a logistic regression result. Whereas I want to give the solver the initial value for its estimation – sa_zy Dec 28 '16 at 10:08
  • Thank you @DmitryPolonskiy, I see these are the options available. As I told blckbird, I'd like to determine the initial guess the solver uses in its approximation. I read the code for the function and didn't find it there either. I generated data according to a logistic distribution (with coefficients I determined) and when I use the LogisticRegression function to make sure it works, it doesn't return the values I used and the error is great. That is why I want to try and determine the initial value for the approximation (if that doesn't work, there must be a problem with the function) – sa_zy Dec 28 '16 at 10:12

1 Answers1

0

You can use the warm_start option (with solver not liblinear), and manually set coef_ and intercept_ prior to fitting.

warm_start : bool, default=False When set to True, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. Useless for liblinear solver.

Ben Reiniger
  • 10,517
  • 3
  • 16
  • 29