Skip to content

ENH add newton-cg Array API to PoissonRegressor - #35050

Merged
virchan merged 5 commits into
scikit-learn:mainfrom
lorentzenchr:glm_array_api_newtoncg
Nov 11, 2026
Merged

virchan merged 5 commits into
scikit-learn:mainfrom
lorentzenchr:glm_array_api_newtoncg

Conversation

@lorentzenchr

Copy link
Copy Markdown
Member

Reference Issues/PRs

Continuation of #33348 and #34412.

What does this implement/fix? Explain your changes.

This PR makes PoissonRegressor(solver="newton-cg") array API compatible (same as LogisticRegression in #34412)

AI usage disclosure

I used AI assistance for:

  • Code review and bug fixing

Any other comments?

@lorentzenchr
lorentzenchr force-pushed the glm_array_api_newtoncg branch from 559a98b to d6d93ed Compare October 26, 2026 08:20
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Oct 26, 2026
@lorentzenchr lorentzenchr added this to the 1.10 milestone Oct 30, 2026
@github-actions github-actions Bot removed the CUDA CI label Oct 31, 2026
@lorentzenchr

Copy link
Copy Markdown
Member Author

@betatim This could interest you. The solver newton-cg has the advantage over lbfgs that it can compute 100% within Array API whereas lbfgs needs to hold certain arrays in numpy.

@cakedev0 cakedev0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at the 1.10 milestone and I saw this one: it's small and valuable, so let's get it merged! Thanks for the PR!

Small findings, but easy to fix.

doc/modules/array_api.rst also needs an update at the PoissonRegressor line (add newton-cg).

Comment thread sklearn/linear_model/_glm/glm.py Resolved
else:
# Needs to be F-contiguous which only numpy provides. We init a
# ravelled array instead.
coef = xp.zeros(shape=(n_classes * n_dof), dtype=dtype, device=device)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this branch needed? The only non-test caller of init_zero_coef is glm.py, which is never multiclass, and no test reaches this branch. It also returns a shape that the docstring doesn't list, (n_classes * n_dof,).

Let's drop it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not really matter. I find it cleaner to keep it, even when untested.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sounds reasonable. And it's well commented so 👍

@lorentzenchr

Copy link
Copy Markdown
Member Author

In fea2c23, I had to promote the intercept (also for fit_intercept=False) to a scalar array.
For the moment this is the way to go, @betatim is working on simplifying this part.

@cakedev0 cakedev0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice one 👍

@cakedev0 cakedev0 added the Waiting for Second Reviewer First reviewer is done, need a second one! label Nov 8, 2026
@lorentzenchr

lorentzenchr commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

@virchan @OmarManzoor Maybe you have time and are interested to give the final +1. Should land in 1.10, IMO.

@virchan virchan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, @lorentzenchr.

We should also add the estimator to doc/modules/array_api.rst.

I also have a minor question for my own understanding.

Otherwise, LGTM.

Comment thread sklearn/linear_model/_glm/glm.py Resolved

@virchan virchan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@virchan
virchan merged commit 9840819 into scikit-learn:main Nov 11, 2026
35 of 36 checks passed
@lorentzenchr
lorentzenchr deleted the glm_array_api_newtoncg branch November 11, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants