Skip to content

FIX, ENH: Patching for LogisticRegressionCV#2871

Merged
david-cortes-intel merged 24 commits intouxlfoundation:mainfrom
david-cortes-intel:logreg_cv
Jan 14, 2026
Merged

FIX, ENH: Patching for LogisticRegressionCV#2871
david-cortes-intel merged 24 commits intouxlfoundation:mainfrom
david-cortes-intel:logreg_cv

Conversation

@david-cortes-intel
Copy link
Copy Markdown
Contributor

@david-cortes-intel david-cortes-intel commented Dec 29, 2025

Description

From #2863

It appears that the logistic regression patching logic is in many ways designed to cover also LogisticRegressionCV, and there are tests checking that it runs with a patched replacement of an internal function, but patching is not applied explicitly to it - rather, it appears to be left patched in some cases as an incorrect cleanup of LogisticRegression.fit, resulting in some CI jobs executing some tests with this class patched but not others.

This PR implements explicit patching for LogisticRegressionCV. Since the implementation is based on replacing some internal functions from sklearn in the same way as for LogisticRegression, it implements it through daal4py even though it is deprecated.

Note that it requires #2863 to be merged before passing the tests.

Along the way, it also fixes a few outstanding issues with changes from sklearn1.8 that were not correctly adopted in logistic regression, which shares the same internal function as LogisticRegressionCV.


Checklist:

Completeness and readability

  • I have updated the documentation to reflect the changes or created a separate PR with updates and provided its number in the description, if necessary.
  • Git commit message contains an appropriate signed-off-by string (see CONTRIBUTING.md for details).
  • I have resolved any merge conflicts that might occur with the base branch.

Testing

  • I have run it locally and tested the changes extensively.
  • All CI jobs are green or I have provided justification why they aren't.

@icfaust
Copy link
Copy Markdown
Contributor

icfaust commented Jan 7, 2026

@david-cortes-intel just casually checking in. this PR if it gets moved out of draft will require updates to scikit learn bench, and depending on the results may require sklearnex.preview module patching.

cc @ethanglaser

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
azure 80.03% <90.47%> (?)
github ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sklearnex/dispatcher.py 91.26% <100.00%> (+0.12%) ⬆️
sklearnex/linear_model/__init__.py 100.00% <100.00%> (ø)
sklearnex/linear_model/logistic_regression.py 62.42% <100.00%> (+3.39%) ⬆️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@david-cortes-intel
Copy link
Copy Markdown
Contributor Author

/intelci: run

@david-cortes-intel
Copy link
Copy Markdown
Contributor Author

/azp run Nightly

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@david-cortes-intel david-cortes-intel changed the title [Do NOT merge yet] ENH: Patching for LogisticRegressionCV [Do NOT merge yet] FIX, ENH: Patching for LogisticRegressionCV Jan 12, 2026
@david-cortes-intel
Copy link
Copy Markdown
Contributor Author

CI failures are not from the class introduced here.

@david-cortes-intel david-cortes-intel changed the title [Do NOT merge yet] FIX, ENH: Patching for LogisticRegressionCV FIX, ENH: Patching for LogisticRegressionCV Jan 12, 2026
@david-cortes-intel david-cortes-intel marked this pull request as ready for review January 12, 2026 10:37
@Vika-F
Copy link
Copy Markdown
Contributor

Vika-F commented Jan 13, 2026

@david-cortes-intel I think the common tests like https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/sklearnex/tests/test_monkeypatch.py, https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/sklearnex/tests/test_run_to_run_stability.py, etc. should be also updated with LogisticRegressionCV estimator.

Or can this be done as a follow up task? I see that this PR fixes a lot of issues in the CI, maybe it worth to merge it faster.

@david-cortes-intel
Copy link
Copy Markdown
Contributor Author

@david-cortes-intel I think the common tests like https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/sklearnex/tests/test_monkeypatch.py, https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/sklearnex/tests/test_run_to_run_stability.py, etc. should be also updated with LogisticRegressionCV estimator.

Or can this be done as a follow up task? I see that this PR fixes a lot of issues in the CI, maybe it worth to merge it faster.

All of those tests use a common list of estimators to run:

They are actually running the new estimator in this PR, since it is being added to that list.

@Vika-F
Copy link
Copy Markdown
Contributor

Vika-F commented Jan 13, 2026

@david-cortes-intel but those tests have some LogReg-related code as well. Should it be extended to LogRegCV?
For example:
https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/sklearnex/tests/test_monkeypatch.py#L119

@david-cortes-intel
Copy link
Copy Markdown
Contributor Author

@david-cortes-intel but those tests have some LogReg-related code as well. Should it be extended to LogRegCV? For example: https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/sklearnex/tests/test_monkeypatch.py#L119

No, those are just random examples. As far as those tests are concerned, it doesn't matter which estimators are used, and not everything is tested in that file.

The more comprehensive tests in https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/sklearnex/tests/test_patching.py do include LogisticRegressionCV.

Copy link
Copy Markdown
Contributor

@Vika-F Vika-F left a comment

Choose a reason for hiding this comment

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

Thank you for sorting this out! The amount of testing seems also reasonable. LGTM.

@david-cortes-intel david-cortes-intel merged commit cd6e847 into uxlfoundation:main Jan 14, 2026
32 of 40 checks passed
@david-cortes-intel
Copy link
Copy Markdown
Contributor Author

Looks like there's something wrong with the CV version here. It ends up running much slower than stock sklearn. Will move it to preview as suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sklearn-patch sklearn patching

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants