From cbfbf02fc9b63e5a30ebd317797ffcc494d54c8f Mon Sep 17 00:00:00 2001 From: David Cortes Date: Wed, 19 Nov 2025 16:49:16 +0100 Subject: [PATCH 1/6] more adjustments for sklearn1.8 --- daal4py/sklearn/linear_model/logistic_path.py | 8 +++++++- doc/sources/algorithms.rst | 19 ++++++++----------- sklearnex/linear_model/logistic_regression.py | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/daal4py/sklearn/linear_model/logistic_path.py b/daal4py/sklearn/linear_model/logistic_path.py index 650696cad4..b517987d2d 100755 --- a/daal4py/sklearn/linear_model/logistic_path.py +++ b/daal4py/sklearn/linear_model/logistic_path.py @@ -102,7 +102,7 @@ def __logistic_regression_path( # Comment 2025-08-04: this file might have dead code paths from unsupported solvers. # It appears to have initially been a copy-paste of scikit-learn with a few additions - # for varying levels of offloading to oneDAL, but later on the check above was added that + # for varying levels of offloading to oneDAL, but later on a check was added that # calls 'lr_path_original' early on when it won't end up offloading anything to oneDAL. # Some parts of the file have been selectively updated since the initial copy-paste # to reflect newer additions to sklearn, but they are not synch. The rest of the file @@ -469,6 +469,12 @@ def logistic_regression_path(*args, **kwargs): (not sparse.issparse(args[0]), "X is sparse. Sparse input is not supported."), (kwargs["sample_weight"] is None, "Sample weights are not supported."), (kwargs["class_weight"] is None, "Class weights are not supported."), + ( + kwargs["penalty"] + in (["l2", "deprecated"] if sklearn_check_version("1.8") else ["l2"]), + "Penalties other than l2 are not supported.", + ), + (not kwargs["l1_ratio"], "L1 regularization is not supported."), ] ) if not _dal_ready: diff --git a/doc/sources/algorithms.rst b/doc/sources/algorithms.rst index 192802daca..c0fc049108 100755 --- a/doc/sources/algorithms.rst +++ b/doc/sources/algorithms.rst @@ -72,7 +72,8 @@ Classification - All parameters are supported except: - ``solver`` not in [``'lbfgs'``, ``'newton-cg'``] - - ``penalty`` in [``'l1'``, ``'elasticnet'``] + - ``l1_ratio`` != ``0`` + - ``dual`` = ``True`` - ``sample_weight`` != ``None`` - ``class_weight`` != ``None`` - Sparse data is not supported. @@ -316,12 +317,10 @@ Classification - ``solver`` != `'newton-cg'` - ``class_weight`` != `None` - ``sample_weight`` != `None` - - ``penalty`` != `'l2'` - - ``dual`` = `True` + - ``dual`` = ``True`` - ``intercept_scaling`` != `1` - - ``multi_class`` = `'multinomial'` - - ``warm_start`` = `True` - - ``l1_ratio`` != 0 and ``l1_ratio`` != ``None`` + - ``warm_start`` = ``True`` + - ``l1_ratio`` != ``0`` - Only binary classification is supported - No limitations @@ -512,12 +511,10 @@ Classification - ``solver`` != `'newton-cg'` - ``class_weight`` != `None` - ``sample_weight`` != `None` - - ``penalty`` != `'l2'` - - ``dual`` = `True` + - ``dual`` = ``True`` - ``intercept_scaling`` != `1` - - ``multi_class`` != `'multinomial'` - - ``warm_start`` = `True` - - ``l1_ratio`` != `None` + - ``warm_start`` = ``True`` + - ``l1_ratio`` != ``0`` - Only binary classification is supported - No limitations diff --git a/sklearnex/linear_model/logistic_regression.py b/sklearnex/linear_model/logistic_regression.py index 8a0b8233e7..8f9d191725 100644 --- a/sklearnex/linear_model/logistic_regression.py +++ b/sklearnex/linear_model/logistic_regression.py @@ -66,7 +66,7 @@ class LogisticRegression(oneDALEstimator, _sklearn_LogisticRegression): def __init__( self, - penalty="l2", + penalty="deprecated", *, dual=False, tol=1e-4, @@ -77,10 +77,11 @@ def __init__( random_state=None, solver="lbfgs", max_iter=100, + multi_class="deprecated", verbose=0, warm_start=False, n_jobs=None, - l1_ratio=None, + l1_ratio=0.0, ): super().__init__( penalty=penalty, @@ -93,6 +94,7 @@ def __init__( random_state=random_state, solver=solver, max_iter=max_iter, + multi_class=multi_class, verbose=verbose, warm_start=warm_start, n_jobs=n_jobs, @@ -256,7 +258,15 @@ def _onedal_gpu_fit_supported(self, method_name, *data): ) patching_status.and_conditions( [ - (self.penalty == "l2", "Only l2 penalty is supported."), + ( + self.penalty + in ( + ["l2", "deprecated"] + if sklearn_check_version("1.8") + else ["l2"] + ), + "Only l2 penalty is supported.", + ), (self.dual == False, "dual=True is not supported."), ( self.intercept_scaling == 1, @@ -271,7 +281,7 @@ def _onedal_gpu_fit_supported(self, method_name, *data): ), ( not self.l1_ratio, - "l1 ratio is not supported.", + "l1 penalty is not supported.", ), (sample_weight is None, "Sample weight is not supported."), ( From 1ac0b03acdfaad0b0931be76b05de6140e766dbb Mon Sep 17 00:00:00 2001 From: David Cortes Date: Thu, 20 Nov 2025 15:25:24 +0100 Subject: [PATCH 2/6] try using fork to see if it passes tests --- .ci/scripts/setup_sklearn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/scripts/setup_sklearn.sh b/.ci/scripts/setup_sklearn.sh index f5d83e7ed1..351a08b3a4 100755 --- a/.ci/scripts/setup_sklearn.sh +++ b/.ci/scripts/setup_sklearn.sh @@ -29,7 +29,7 @@ if [ "$sklearn_version" == "main" ]; then # install sklearn build dependencies pip install threadpoolctl joblib scipy # install sklearn from main branch of git repo - pip install git+https://github.com/scikit-learn/scikit-learn.git@main + pip install git+https://github.com/lorentzenchr/scikit-learn.git@dep_logistic_penalty else sed -i.bak -E "s/scikit-learn==[0-9a-zA-Z.]*/scikit-learn==${sklearn_version}.*/" requirements-test.txt fi From 268dec79b1fc9f7a916bd871ab8a341788066e53 Mon Sep 17 00:00:00 2001 From: David Cortes Date: Wed, 26 Nov 2025 08:46:03 +0100 Subject: [PATCH 3/6] restore main branch after PR was merged --- .ci/scripts/setup_sklearn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/scripts/setup_sklearn.sh b/.ci/scripts/setup_sklearn.sh index 351a08b3a4..f5d83e7ed1 100755 --- a/.ci/scripts/setup_sklearn.sh +++ b/.ci/scripts/setup_sklearn.sh @@ -29,7 +29,7 @@ if [ "$sklearn_version" == "main" ]; then # install sklearn build dependencies pip install threadpoolctl joblib scipy # install sklearn from main branch of git repo - pip install git+https://github.com/lorentzenchr/scikit-learn.git@dep_logistic_penalty + pip install git+https://github.com/scikit-learn/scikit-learn.git@main else sed -i.bak -E "s/scikit-learn==[0-9a-zA-Z.]*/scikit-learn==${sklearn_version}.*/" requirements-test.txt fi From caff55f943a79c15b107c250f6677fb91a7e7de0 Mon Sep 17 00:00:00 2001 From: david-cortes-intel Date: Wed, 26 Nov 2025 00:34:01 -0800 Subject: [PATCH 4/6] corrections --- sklearnex/linear_model/logistic_regression.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sklearnex/linear_model/logistic_regression.py b/sklearnex/linear_model/logistic_regression.py index 8f9d191725..c90e64aea1 100644 --- a/sklearnex/linear_model/logistic_regression.py +++ b/sklearnex/linear_model/logistic_regression.py @@ -15,7 +15,6 @@ # =============================================================================== import logging -from abc import ABC from daal4py.sklearn._utils import daal_check_version from daal4py.sklearn.linear_model.logistic_path import ( @@ -28,7 +27,7 @@ from sklearn.linear_model import LogisticRegression as _sklearn_LogisticRegression from sklearn.metrics import accuracy_score from sklearn.utils.multiclass import type_of_target - from sklearn.utils.validation import check_array, check_is_fitted, check_X_y + from sklearn.utils.validation import check_is_fitted from daal4py.sklearn._n_jobs_support import control_n_jobs from daal4py.sklearn._utils import sklearn_check_version @@ -68,20 +67,19 @@ def __init__( self, penalty="deprecated", *, + C=1.0, + l1_ratio=0.0, dual=False, tol=1e-4, - C=1.0, fit_intercept=True, intercept_scaling=1, class_weight=None, random_state=None, solver="lbfgs", max_iter=100, - multi_class="deprecated", verbose=0, warm_start=False, n_jobs=None, - l1_ratio=0.0, ): super().__init__( penalty=penalty, @@ -94,7 +92,6 @@ def __init__( random_state=random_state, solver=solver, max_iter=max_iter, - multi_class=multi_class, verbose=verbose, warm_start=warm_start, n_jobs=n_jobs, From 27e4659958054d8b6a00a0af834f36a61d195353 Mon Sep 17 00:00:00 2001 From: david-cortes-intel Date: Wed, 26 Nov 2025 02:02:29 -0800 Subject: [PATCH 5/6] add missing patching condition --- daal4py/sklearn/linear_model/logistic_path.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/daal4py/sklearn/linear_model/logistic_path.py b/daal4py/sklearn/linear_model/logistic_path.py index b517987d2d..d9b5a16537 100755 --- a/daal4py/sklearn/linear_model/logistic_path.py +++ b/daal4py/sklearn/linear_model/logistic_path.py @@ -475,6 +475,10 @@ def logistic_regression_path(*args, **kwargs): "Penalties other than l2 are not supported.", ), (not kwargs["l1_ratio"], "L1 regularization is not supported."), + ( + not (kwargs["solver"] == "newton-cg" and not kwargs["fit_intercept"]), + "'newton-cg' solver without intercept is not supported.", + ), ] ) if not _dal_ready: From b4cbeddbf38cf6b6d79826e3be828d5991f278ac Mon Sep 17 00:00:00 2001 From: david-cortes-intel Date: Wed, 26 Nov 2025 02:03:22 -0800 Subject: [PATCH 6/6] document conditions --- doc/sources/algorithms.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/sources/algorithms.rst b/doc/sources/algorithms.rst index d6dc0ea4f9..487fe16bba 100755 --- a/doc/sources/algorithms.rst +++ b/doc/sources/algorithms.rst @@ -78,6 +78,7 @@ Classification - ``dual`` = ``True`` - ``sample_weight`` != ``None`` - ``class_weight`` != ``None`` + - Solver ``'newton-cg'`` with ``fit_intercept`` = ``False`` is not supported - Sparse data is not supported. Regression