You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Intercepts of Newton-Cholesky logistic regression get corrupted when warm starting #31859
When using multinomial logistic regression with warm starts from a previous iteration, the final coefficients in the model are correct, but the intercepts somehow get filled with incorrect numbers somewhere.
As a result, predictions from a warm-started model differ from those of a cold-start model that has more iterations on the same data.
The issue appears to have been introduced recently as it works fine with version 1.5, but not with 1.6 or 1.7.
Why should it be the same? Model 1 uses 2 newton iterations, model 2 only 1. The warm start does not take effect as there is nothing to "warm start with".
Note that multinomial newton-cholesky is only available as of version 1.6.
@lorentzenchrmodel2 with warm_start=True is fit twice though so it does 2 newton iterations right (just mentioning this in case you missed it)? I was going to ping you for insights but looks like you are already on it, thanks!
For reference: a git bisect points at #28840 that implemented multiclass for newton-cholesky solver and was released in 1.6. So in 1.6 newton-cholesky use multinomial solver and in 1.5 was using One vs Rest. Using multi_class='ovr' make the snippet pass for scikit-learn >= 1.6.
Why should it be the same? Model 1 uses 2 newton iterations, model 2 only 1. The warm start does not take effect as there is nothing to "warm start with".
Note that multinomial newton-cholesky is only available as of version 1.6.
Also if they weren't equivalent, the coefficients wouldn't end up being exactly the same - which in this case they are, with only the intercepts differing.
This is a tricky issue. Please note that model1 as well as model2 emit a ConvergenceWarning.
The reason why the intercept is different is that the NewtonCholeskySolver calls finalize at the end of its work, see
There, the intercept is symmetrized to adhere to our convention that coefficients and intercept should sum to zero. Therefore, two separate calls to fit with one step and warm start are not the same as one call to fit with 2 steps.
This is a tricky issue. Please note that model1 as well as model2 emit a ConvergenceWarning. The reason why the intercept is different is that the NewtonCholeskySolver calls finalize at the end of its work, see
def finalize(self, X, y, sample_weight):
There, the intercept is symmetrized to adhere to our convention that coefficients and intercept should sum to zero. Therefore, two separate calls to fit with one step and warm start are not the same as one call to fit with 2 steps.
If this is due to following glmnet's approach to make the solution unique with unregularized intercepts (which should be restricted to the intercepts only, not to the coefficients), then there's still an issue, as the intercepts in this case are not equivalent:
So the second one (warm-started) is doing something wrong when it tries to center them.
Yes, this step is done after the optimization procedure (using n_iter_ steps) to make all unpenalized parameters unique, i.e., sum to zero.
As I explained, this destroys the equivalence of same number of steps with warm start vs all steps at once. It is even worse: LogisticRegression(max_iter=6, solver='newton-cholesky') converges, but calling 6 or more time model2.fit(X, y) does not converge.
So what is more important:
Making repeated warm-start calls to fit equivalent to one fit with many steps.
Keeping current symmetrizing behavior.
The newton-cholesky solver is not a SGD solver nor a minibatch solver and has no partial_fit method. You should give it at least some number of iterations and if you prefer an even higher accuracy later, you can use a warm start fit to improve.
For me, this behavior is fine because I don't have a use case to call repeated fit with small number of iterations.
Side remark: One step of newton-cholesky and the finalize actually puts the parameters in such a bad region that it practically never recovers from it (if one keeps warm starting).
Yes, this step is done after the optimization procedure (using n_iter_ steps) to make all unpenalized parameters unique, i.e., sum to zero.
As I explained, this destroys the equivalence of same number of steps with warm start vs all steps at once. It is even worse: LogisticRegression(max_iter=6, solver='newton-cholesky') converges, but calling 6 or more time model2.fit(X, y) does not converge.
So what is more important:
Making repeated warm-start calls to fit equivalent to one fit with many steps.
Keeping current symmetrizing behavior.
The newton-cholesky solver is not a SGD solver nor a minibatch solver and has no partial_fit method. You should give it at least some number of iterations and if you prefer an even higher accuracy later, you can use a warm start fit to improve.
For me, this behavior is fine because I don't have a use case to call repeated fit with small number of iterations.
I don't follow.
If it were the case that the only thing going on is the centering of intercepts, then the predicted probabilities would be the same regardless of whether the intercepts sum to zero or to some other number, so long as all of them are off by the same constant.
The only way in which an exact Newton update would give the same result for coefficients given the same start, is if predictions from which gradients and Hessians were the same, which is the case whenever the intercepts are equivalent up to an arbitrary constant shift - i.e.:
Hence, centering of the intercepts should not change the end result in terms of predicted probabilities.
Yet in this case, the coefficients are matching, which means that the intercepts are being used correctly prior to the Newton update, but are then being incorrectly modified in a non-equivalent way afterwards.
If they received the same update and get centered after the update, the result would still be equivalent between the warm and cold start, at the very least in terms of predicted probabilities.
start fit
init coef = [0, 0], intercept = [0, 0]
iteration 1:
coef = [1, -1], intercept = [-1, 3]
finalize:
coef = [1, -1], intercept = [-2, 2]
end fit
start 2nd fit
warm start coef = [1, -1], intercept = [-2, 2]
iteration 2
coef = [2, -2] intercept = [-3, 5] # same grad and hess => same newton step as in model 1
finalize:
coef = [2, -2], intercept = [-4, 4]
end of 2nd fit
Precisely. You necessarily end up with something that produces the same predicted probabilties. In the snippet at the beginning, the predicted probabilities differ.
After iteration 2, the predicted probabilities differ, same with your original code snippet.
The question is whether this requires a fix (removing finalize), or whether we can live with it (as users are not supposed to use the solver that way).
Up until now, I can live with it. Is there a good use case to come to another conclusion?
Activity
lorentzenchr commentedon Jul 31, 2025
Why should it be the same? Model 1 uses 2 newton iterations, model 2 only 1. The warm start does not take effect as there is nothing to "warm start with".
Note that multinomial newton-cholesky is only available as of version 1.6.
lesteve commentedon Jul 31, 2025
@lorentzenchr
model2withwarm_start=Trueis fit twice though so it does 2 newton iterations right (just mentioning this in case you missed it)? I was going to ping you for insights but looks like you are already on it, thanks!For reference: a
git bisectpoints at #28840 that implemented multiclass for newton-cholesky solver and was released in 1.6. So in 1.6 newton-cholesky use multinomial solver and in 1.5 was using One vs Rest. Usingmulti_class='ovr'make the snippet pass for scikit-learn >= 1.6.david-cortes commentedon Jul 31, 2025
Also if they weren't equivalent, the coefficients wouldn't end up being exactly the same - which in this case they are, with only the intercepts differing.
lorentzenchr commentedon Jul 31, 2025
@lesteve Thanks for point out the .fit.fit.
This is a tricky issue. Please note that model1 as well as model2 emit a ConvergenceWarning.
The reason why the intercept is different is that the
NewtonCholeskySolvercallsfinalizeat the end of its work, seescikit-learn/sklearn/linear_model/_glm/_newton_solver.py
Line 606 in 3d35e02
There, the intercept is symmetrized to adhere to our convention that coefficients and intercept should sum to zero. Therefore, two separate calls to fit with one step and warm start are not the same as one call to fit with 2 steps.
david-cortes commentedon Jul 31, 2025
If this is due to following glmnet's approach to make the solution unique with unregularized intercepts (which should be restricted to the intercepts only, not to the coefficients), then there's still an issue, as the intercepts in this case are not equivalent:

So the second one (warm-started) is doing something wrong when it tries to center them.
lorentzenchr commentedon Jul 31, 2025
Yes, this step is done after the optimization procedure (using
n_iter_steps) to make all unpenalized parameters unique, i.e., sum to zero.As I explained, this destroys the equivalence of same number of steps with warm start vs all steps at once. It is even worse:
LogisticRegression(max_iter=6, solver='newton-cholesky')converges, but calling 6 or more timemodel2.fit(X, y)does not converge.So what is more important:
fitequivalent to onefitwith many steps.The newton-cholesky solver is not a SGD solver nor a minibatch solver and has no
partial_fitmethod. You should give it at least some number of iterations and if you prefer an even higher accuracy later, you can use a warm start fit to improve.For me, this behavior is fine because I don't have a use case to call repeated fit with small number of iterations.
Side remark: One step of newton-cholesky and the finalize actually puts the parameters in such a bad region that it practically never recovers from it (if one keeps warm starting).
david-cortes commentedon Jul 31, 2025
I don't follow.
If it were the case that the only thing going on is the centering of intercepts, then the predicted probabilities would be the same regardless of whether the intercepts sum to zero or to some other number, so long as all of them are off by the same constant.
For example:
The only way in which an exact Newton update would give the same result for coefficients given the same start, is if predictions from which gradients and Hessians were the same, which is the case whenever the intercepts are equivalent up to an arbitrary constant shift - i.e.:
Hence, centering of the intercepts should not change the end result in terms of predicted probabilities.
Yet in this case, the coefficients are matching, which means that the intercepts are being used correctly prior to the Newton update, but are then being incorrectly modified in a non-equivalent way afterwards.
If they received the same update and get centered after the update, the result would still be equivalent between the warm and cold start, at the very least in terms of predicted probabilities.
lorentzenchr commentedon Jul 31, 2025
Assume 2 classes, 1 feature with penalty > 0. As long as predictions stay the same, also gradients and hessians stay the same.
model 1:
model 2:
david-cortes commentedon Jul 31, 2025
Precisely. You necessarily end up with something that produces the same predicted probabilties. In the snippet at the beginning, the predicted probabilities differ.
lorentzenchr commentedon Aug 1, 2025
After iteration 2, the predicted probabilities differ, same with your original code snippet.
The question is whether this requires a fix (removing finalize), or whether we can live with it (as users are not supposed to use the solver that way).
Up until now, I can live with it. Is there a good use case to come to another conclusion?
david-cortes commentedon Aug 1, 2025
They do not differ:
david-cortes commentedon Aug 1, 2025
Broader problem is: it makes warm starts perform worse than cold starts.
david-cortes commentedon Aug 1, 2025
In case it helps: it appears to be a matter of only one of the intercepts being off.
Example:
lorentzenchr commentedon Aug 1, 2025
There is indeed a bug in the code...I'm investigating.