scikit-learn-intelex 2024.0.1__py38-none-manylinux1_x86_64.whl → 2024.2.0__py38-none-manylinux1_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of scikit-learn-intelex might be problematic. Click here for more details.

Files changed (78) hide show
  1. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.2.0.dist-info}/METADATA +2 -2
  2. scikit_learn_intelex-2024.2.0.dist-info/RECORD +101 -0
  3. sklearnex/__init__.py +3 -1
  4. sklearnex/__main__.py +0 -1
  5. sklearnex/_utils.py +15 -1
  6. sklearnex/basic_statistics/__init__.py +0 -1
  7. sklearnex/cluster/__init__.py +0 -1
  8. sklearnex/cluster/dbscan.py +2 -1
  9. sklearnex/cluster/k_means.py +0 -1
  10. sklearnex/cluster/tests/test_dbscan.py +0 -1
  11. sklearnex/cluster/tests/test_kmeans.py +0 -1
  12. sklearnex/covariance/__init__.py +19 -0
  13. sklearnex/covariance/incremental_covariance.py +130 -0
  14. sklearnex/covariance/tests/test_incremental_covariance.py +143 -0
  15. sklearnex/decomposition/__init__.py +0 -1
  16. sklearnex/decomposition/pca.py +0 -1
  17. sklearnex/decomposition/tests/test_pca.py +0 -1
  18. sklearnex/dispatcher.py +35 -1
  19. sklearnex/ensemble/__init__.py +0 -1
  20. sklearnex/ensemble/_forest.py +17 -2
  21. sklearnex/ensemble/tests/test_forest.py +0 -1
  22. sklearnex/glob/__main__.py +0 -1
  23. sklearnex/glob/dispatcher.py +0 -1
  24. sklearnex/linear_model/__init__.py +1 -3
  25. sklearnex/linear_model/coordinate_descent.py +0 -1
  26. sklearnex/linear_model/linear.py +9 -1
  27. sklearnex/linear_model/logistic_path.py +0 -1
  28. sklearnex/linear_model/logistic_regression.py +333 -0
  29. sklearnex/linear_model/ridge.py +0 -1
  30. sklearnex/linear_model/tests/test_linear.py +8 -3
  31. sklearnex/linear_model/tests/test_logreg.py +70 -6
  32. sklearnex/manifold/__init__.py +0 -1
  33. sklearnex/manifold/t_sne.py +0 -1
  34. sklearnex/manifold/tests/test_tsne.py +0 -1
  35. sklearnex/metrics/__init__.py +0 -1
  36. sklearnex/metrics/pairwise.py +0 -1
  37. sklearnex/metrics/ranking.py +0 -1
  38. sklearnex/metrics/tests/test_metrics.py +0 -1
  39. sklearnex/model_selection/__init__.py +0 -1
  40. sklearnex/model_selection/split.py +0 -1
  41. sklearnex/model_selection/tests/test_model_selection.py +0 -1
  42. sklearnex/neighbors/__init__.py +1 -2
  43. sklearnex/neighbors/_lof.py +167 -0
  44. sklearnex/neighbors/common.py +1 -2
  45. sklearnex/neighbors/knn_classification.py +5 -4
  46. sklearnex/neighbors/knn_regression.py +5 -4
  47. sklearnex/neighbors/knn_unsupervised.py +4 -3
  48. sklearnex/neighbors/tests/test_neighbors.py +12 -12
  49. sklearnex/preview/__init__.py +1 -2
  50. sklearnex/preview/cluster/__init__.py +0 -1
  51. sklearnex/preview/cluster/k_means.py +2 -1
  52. sklearnex/preview/covariance/__init__.py +19 -0
  53. sklearnex/preview/covariance/covariance.py +132 -0
  54. sklearnex/preview/covariance/tests/test_covariance.py +53 -0
  55. sklearnex/preview/decomposition/__init__.py +0 -1
  56. sklearnex/preview/decomposition/pca.py +43 -45
  57. sklearnex/preview/decomposition/tests/test_preview_pca.py +7 -3
  58. sklearnex/spmd/__init__.py +1 -0
  59. sklearnex/spmd/covariance/__init__.py +19 -0
  60. sklearnex/spmd/covariance/covariance.py +21 -0
  61. sklearnex/spmd/linear_model/__init__.py +2 -1
  62. sklearnex/spmd/linear_model/logistic_regression.py +21 -0
  63. sklearnex/svm/__init__.py +0 -1
  64. sklearnex/svm/nusvc.py +4 -0
  65. sklearnex/svm/nusvr.py +2 -0
  66. sklearnex/svm/svc.py +5 -1
  67. sklearnex/svm/svr.py +2 -0
  68. sklearnex/svm/tests/test_svm.py +0 -1
  69. sklearnex/tests/test_memory_usage.py +1 -4
  70. sklearnex/tests/test_monkeypatch.py +46 -16
  71. sklearnex/tests/test_n_jobs_support.py +93 -0
  72. sklearnex/tests/test_patching.py +19 -5
  73. sklearnex/utils/validation.py +0 -1
  74. scikit_learn_intelex-2024.0.1.dist-info/RECORD +0 -90
  75. sklearnex/neighbors/lof.py +0 -437
  76. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.2.0.dist-info}/LICENSE.txt +0 -0
  77. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.2.0.dist-info}/WHEEL +0 -0
  78. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.2.0.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ==============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -43,6 +42,7 @@ from sklearn.utils.validation import (
43
42
  check_X_y,
44
43
  )
45
44
 
45
+ from daal4py.sklearn._n_jobs_support import control_n_jobs
46
46
  from daal4py.sklearn._utils import (
47
47
  check_tree_nodes,
48
48
  daal_check_version,
@@ -114,6 +114,8 @@ class BaseForest(ABC):
114
114
  # [:, np.newaxis] that does not.
115
115
  y = np.reshape(y, (-1, 1))
116
116
 
117
+ self._n_samples, self.n_outputs_ = y.shape
118
+
117
119
  y, expanded_class_weight = self._validate_y_class_weight(y)
118
120
 
119
121
  self.n_features_in_ = X.shape[1]
@@ -189,7 +191,16 @@ class BaseForest(ABC):
189
191
  self.oob_decision_function_ = (
190
192
  self._onedal_estimator.oob_decision_function_
191
193
  )
192
-
194
+ if self.bootstrap:
195
+ self._n_samples_bootstrap = max(
196
+ round(
197
+ self._onedal_estimator.observations_per_tree_fraction
198
+ * self._n_samples
199
+ ),
200
+ 1,
201
+ )
202
+ else:
203
+ self._n_samples_bootstrap = None
193
204
  self._validate_estimator()
194
205
  return self
195
206
 
@@ -1122,6 +1133,7 @@ class ForestRegressor(sklearn_ForestRegressor, BaseForest):
1122
1133
  predict.__doc__ = sklearn_ForestRegressor.predict.__doc__
1123
1134
 
1124
1135
 
1136
+ @control_n_jobs(decorated_methods=["fit", "predict", "predict_proba"])
1125
1137
  class RandomForestClassifier(ForestClassifier):
1126
1138
  __doc__ = sklearn_RandomForestClassifier.__doc__
1127
1139
  _onedal_factory = onedal_RandomForestClassifier
@@ -1331,6 +1343,7 @@ class RandomForestClassifier(ForestClassifier):
1331
1343
  self.min_bin_size = min_bin_size
1332
1344
 
1333
1345
 
1346
+ @control_n_jobs(decorated_methods=["fit", "predict"])
1334
1347
  class RandomForestRegressor(ForestRegressor):
1335
1348
  __doc__ = sklearn_RandomForestRegressor.__doc__
1336
1349
  _onedal_factory = onedal_RandomForestRegressor
@@ -1531,6 +1544,7 @@ class RandomForestRegressor(ForestRegressor):
1531
1544
  self.min_bin_size = min_bin_size
1532
1545
 
1533
1546
 
1547
+ @control_n_jobs(decorated_methods=["fit", "predict", "predict_proba"])
1534
1548
  class ExtraTreesClassifier(ForestClassifier):
1535
1549
  __doc__ = sklearn_ExtraTreesClassifier.__doc__
1536
1550
  _onedal_factory = onedal_ExtraTreesClassifier
@@ -1740,6 +1754,7 @@ class ExtraTreesClassifier(ForestClassifier):
1740
1754
  self.min_bin_size = min_bin_size
1741
1755
 
1742
1756
 
1757
+ @control_n_jobs(decorated_methods=["fit", "predict"])
1743
1758
  class ExtraTreesRegressor(ForestRegressor):
1744
1759
  __doc__ = sklearn_ExtraTreesRegressor.__doc__
1745
1760
  _onedal_factory = onedal_ExtraTreesRegressor
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2023 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -17,14 +16,13 @@
17
16
 
18
17
  from .coordinate_descent import ElasticNet, Lasso
19
18
  from .linear import LinearRegression
20
- from .logistic_path import LogisticRegression, logistic_regression_path
19
+ from .logistic_regression import LogisticRegression
21
20
  from .ridge import Ridge
22
21
 
23
22
  __all__ = [
24
23
  "Ridge",
25
24
  "LinearRegression",
26
25
  "LogisticRegression",
27
- "logistic_regression_path",
28
26
  "ElasticNet",
29
27
  "Lasso",
30
28
  ]
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -65,10 +65,15 @@ if daal_check_version((2023, "P", 100)):
65
65
  import numpy as np
66
66
  from sklearn.linear_model import LinearRegression as sklearn_LinearRegression
67
67
 
68
+ from daal4py.sklearn._n_jobs_support import control_n_jobs
68
69
  from daal4py.sklearn._utils import get_dtype, make2d, sklearn_check_version
69
70
 
70
71
  from .._device_offload import dispatch, wrap_output_data
71
- from .._utils import PatchingConditionsChain, get_patch_message
72
+ from .._utils import (
73
+ PatchingConditionsChain,
74
+ get_patch_message,
75
+ register_hyperparameters,
76
+ )
72
77
  from ..utils.validation import _assert_all_finite
73
78
 
74
79
  if sklearn_check_version("1.0") and not sklearn_check_version("1.2"):
@@ -78,9 +83,12 @@ if daal_check_version((2023, "P", 100)):
78
83
  from sklearn.exceptions import NotFittedError
79
84
  from sklearn.utils.validation import _deprecate_positional_args, check_X_y
80
85
 
86
+ from onedal.common.hyperparameters import get_hyperparameters
81
87
  from onedal.linear_model import LinearRegression as onedal_LinearRegression
82
88
  from onedal.utils import _num_features, _num_samples
83
89
 
90
+ @register_hyperparameters({"fit": get_hyperparameters("linear_regression", "train")})
91
+ @control_n_jobs(decorated_methods=["fit", "predict"])
84
92
  class LinearRegression(sklearn_LinearRegression, BaseLinearRegression):
85
93
  __doc__ = sklearn_LinearRegression.__doc__
86
94
  intercept_, coef_ = None, None
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -0,0 +1,333 @@
1
+ # ===============================================================================
2
+ # Copyright 2024 Intel Corporation
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ===============================================================================
16
+
17
+ import logging
18
+ from abc import ABC
19
+
20
+ from daal4py.sklearn._utils import daal_check_version
21
+ from daal4py.sklearn.linear_model.logistic_path import (
22
+ LogisticRegression as LogisticRegression_daal4py,
23
+ )
24
+ from daal4py.sklearn.linear_model.logistic_path import daal4py_fit, daal4py_predict
25
+
26
+
27
+ class BaseLogisticRegression(ABC):
28
+ def _save_attributes(self):
29
+ assert hasattr(self, "_onedal_estimator")
30
+ self.classes_ = self._onedal_estimator.classes_
31
+ self.coef_ = self._onedal_estimator.coef_
32
+ self.intercept_ = self._onedal_estimator.intercept_
33
+ self.n_features_in_ = self._onedal_estimator.n_features_in_
34
+ self.n_iter_ = self._onedal_estimator.n_iter_
35
+
36
+
37
+ if daal_check_version((2024, "P", 1)):
38
+ import numpy as np
39
+ from scipy.sparse import issparse
40
+ from sklearn.linear_model import LogisticRegression as sklearn_LogisticRegression
41
+ from sklearn.utils.validation import check_X_y
42
+
43
+ from daal4py.sklearn._n_jobs_support import control_n_jobs
44
+ from daal4py.sklearn._utils import sklearn_check_version
45
+ from onedal.linear_model import LogisticRegression as onedal_LogisticRegression
46
+ from onedal.utils import _num_features, _num_samples
47
+
48
+ from .._device_offload import dispatch, wrap_output_data
49
+ from .._utils import PatchingConditionsChain, get_patch_message
50
+ from ..utils.validation import _assert_all_finite
51
+
52
+ @control_n_jobs(
53
+ decorated_methods=["fit", "predict", "predict_proba", "predict_log_proba"]
54
+ )
55
+ class LogisticRegression(sklearn_LogisticRegression, BaseLogisticRegression):
56
+ __doc__ = sklearn_LogisticRegression.__doc__
57
+ intercept_, coef_, n_iter_ = None, None, None
58
+
59
+ if sklearn_check_version("1.2"):
60
+ _parameter_constraints: dict = {
61
+ **sklearn_LogisticRegression._parameter_constraints
62
+ }
63
+
64
+ def __init__(
65
+ self,
66
+ penalty="l2",
67
+ *,
68
+ dual=False,
69
+ tol=1e-4,
70
+ C=1.0,
71
+ fit_intercept=True,
72
+ intercept_scaling=1,
73
+ class_weight=None,
74
+ random_state=None,
75
+ solver="lbfgs" if sklearn_check_version("0.22") else "liblinear",
76
+ max_iter=100,
77
+ multi_class="auto" if sklearn_check_version("0.22") else "ovr",
78
+ verbose=0,
79
+ warm_start=False,
80
+ n_jobs=None,
81
+ l1_ratio=None,
82
+ ):
83
+ super().__init__(
84
+ penalty=penalty,
85
+ dual=dual,
86
+ tol=tol,
87
+ C=C,
88
+ fit_intercept=fit_intercept,
89
+ intercept_scaling=intercept_scaling,
90
+ class_weight=class_weight,
91
+ random_state=random_state,
92
+ solver=solver,
93
+ max_iter=max_iter,
94
+ multi_class=multi_class,
95
+ verbose=verbose,
96
+ warm_start=warm_start,
97
+ n_jobs=n_jobs,
98
+ l1_ratio=l1_ratio,
99
+ )
100
+
101
+ _onedal_cpu_fit = daal4py_fit
102
+
103
+ def fit(self, X, y, sample_weight=None):
104
+ if sklearn_check_version("1.0"):
105
+ self._check_feature_names(X, reset=True)
106
+ if sklearn_check_version("1.2"):
107
+ self._validate_params()
108
+ dispatch(
109
+ self,
110
+ "fit",
111
+ {
112
+ "onedal": self.__class__._onedal_fit,
113
+ "sklearn": sklearn_LogisticRegression.fit,
114
+ },
115
+ X,
116
+ y,
117
+ sample_weight,
118
+ )
119
+ return self
120
+
121
+ @wrap_output_data
122
+ def predict(self, X):
123
+ if sklearn_check_version("1.0"):
124
+ self._check_feature_names(X, reset=False)
125
+ return dispatch(
126
+ self,
127
+ "predict",
128
+ {
129
+ "onedal": self.__class__._onedal_predict,
130
+ "sklearn": sklearn_LogisticRegression.predict,
131
+ },
132
+ X,
133
+ )
134
+
135
+ @wrap_output_data
136
+ def predict_proba(self, X):
137
+ if sklearn_check_version("1.0"):
138
+ self._check_feature_names(X, reset=False)
139
+ return dispatch(
140
+ self,
141
+ "predict",
142
+ {
143
+ "onedal": self.__class__._onedal_predict_proba,
144
+ "sklearn": sklearn_LogisticRegression.predict_proba,
145
+ },
146
+ X,
147
+ )
148
+
149
+ @wrap_output_data
150
+ def predict_log_proba(self, X):
151
+ if sklearn_check_version("1.0"):
152
+ self._check_feature_names(X, reset=False)
153
+ return dispatch(
154
+ self,
155
+ "predict",
156
+ {
157
+ "onedal": self.__class__._onedal_predict_log_proba,
158
+ "sklearn": sklearn_LogisticRegression.predict_log_proba,
159
+ },
160
+ X,
161
+ )
162
+
163
+ def _test_type_and_finiteness(self, X_in):
164
+ X = np.asarray(X_in)
165
+
166
+ if np.iscomplexobj(X):
167
+ return False
168
+ try:
169
+ _assert_all_finite(X)
170
+ except BaseException:
171
+ return False
172
+ return True
173
+
174
+ def _onedal_gpu_fit_supported(self, method_name, *data):
175
+ assert method_name == "fit"
176
+ assert len(data) == 3
177
+ X, y, sample_weight = data
178
+
179
+ class_name = self.__class__.__name__
180
+ patching_status = PatchingConditionsChain(
181
+ f"sklearn.linear_model.{class_name}.fit"
182
+ )
183
+
184
+ dal_ready = patching_status.and_conditions(
185
+ [
186
+ (self.penalty == "l2", "Only l2 penalty is supported."),
187
+ (self.dual == False, "dual=True is not supported."),
188
+ (self.intercept_scaling == 1, "Intercept scaling is not supported."),
189
+ (self.class_weight is None, "Class weight is not supported"),
190
+ (self.solver == "newton-cg", "Only newton-cg solver is supported."),
191
+ (
192
+ self.multi_class != "multinomial",
193
+ "multi_class parameter is not supported.",
194
+ ),
195
+ (self.warm_start == False, "Warm start is not supported."),
196
+ (self.l1_ratio is None, "l1 ratio is not supported."),
197
+ (sample_weight is None, "Sample weight is not supported."),
198
+ ]
199
+ )
200
+
201
+ if not dal_ready:
202
+ return patching_status
203
+
204
+ if not patching_status.and_condition(
205
+ self._test_type_and_finiteness(X), "Input X is not supported."
206
+ ):
207
+ return patching_status
208
+
209
+ patching_status.and_condition(
210
+ self._test_type_and_finiteness(y), "Input y is not supported."
211
+ )
212
+
213
+ return patching_status
214
+
215
+ def _onedal_gpu_predict_supported(self, method_name, *data):
216
+ assert method_name in ["predict", "predict_proba", "predict_log_proba"]
217
+ assert len(data) == 1
218
+
219
+ class_name = self.__class__.__name__
220
+ patching_status = PatchingConditionsChain(
221
+ f"sklearn.linear_model.{class_name}.{method_name}"
222
+ )
223
+
224
+ n_samples = _num_samples(*data)
225
+ model_is_sparse = issparse(self.coef_) or (
226
+ self.fit_intercept and issparse(self.intercept_)
227
+ )
228
+ dal_ready = patching_status.and_conditions(
229
+ [
230
+ (n_samples > 0, "Number of samples is less than 1."),
231
+ (not issparse(*data), "Sparse input is not supported."),
232
+ (not model_is_sparse, "Sparse coefficients are not supported."),
233
+ (hasattr(self, "_onedal_estimator"), "oneDAL model was not trained."),
234
+ ]
235
+ )
236
+ if not dal_ready:
237
+ return patching_status
238
+
239
+ patching_status.and_condition(
240
+ self._test_type_and_finiteness(*data), "Input X is not supported."
241
+ )
242
+
243
+ return patching_status
244
+
245
+ def _onedal_gpu_supported(self, method_name, *data):
246
+ if method_name == "fit":
247
+ return self._onedal_gpu_fit_supported(method_name, *data)
248
+ if method_name in ["predict", "predict_proba", "predict_log_proba"]:
249
+ return self._onedal_gpu_predict_supported(method_name, *data)
250
+ raise RuntimeError(
251
+ f"Unknown method {method_name} in {self.__class__.__name__}"
252
+ )
253
+
254
+ def _onedal_cpu_supported(self, method_name, *data):
255
+ class_name = self.__class__.__name__
256
+ patching_status = PatchingConditionsChain(
257
+ f"sklearn.linear_model.{class_name}.{method_name}"
258
+ )
259
+
260
+ return patching_status
261
+
262
+ def _initialize_onedal_estimator(self):
263
+ onedal_params = {
264
+ "tol": self.tol,
265
+ "C": self.C,
266
+ "fit_intercept": self.fit_intercept,
267
+ "solver": self.solver,
268
+ "max_iter": self.max_iter,
269
+ }
270
+ self._onedal_estimator = onedal_LogisticRegression(**onedal_params)
271
+
272
+ def _onedal_fit(self, X, y, sample_weight, queue=None):
273
+ if queue is None or queue.sycl_device.is_cpu:
274
+ return self._onedal_cpu_fit(X, y, sample_weight)
275
+
276
+ assert sample_weight is None
277
+
278
+ check_params = {
279
+ "X": X,
280
+ "y": y,
281
+ "dtype": [np.float64, np.float32],
282
+ "accept_sparse": False,
283
+ "multi_output": False,
284
+ "force_all_finite": True,
285
+ }
286
+ if sklearn_check_version("1.2"):
287
+ X, y = self._validate_data(**check_params)
288
+ else:
289
+ X, y = check_X_y(**check_params)
290
+ self._initialize_onedal_estimator()
291
+ try:
292
+ self._onedal_estimator.fit(X, y, queue=queue)
293
+ self._save_attributes()
294
+ except RuntimeError:
295
+ logging.getLogger("sklearnex").info(
296
+ f"{self.__class__.__name__}.fit "
297
+ + get_patch_message("sklearn_after_onedal")
298
+ )
299
+
300
+ del self._onedal_estimator
301
+ super().fit(X, y)
302
+
303
+ def _onedal_predict(self, X, queue=None):
304
+ if queue is None or queue.sycl_device.is_cpu:
305
+ return daal4py_predict(self, X, "computeClassLabels")
306
+
307
+ X = self._validate_data(X, accept_sparse=False, reset=False)
308
+ assert hasattr(self, "_onedal_estimator")
309
+ return self._onedal_estimator.predict(X, queue=queue)
310
+
311
+ def _onedal_predict_proba(self, X, queue=None):
312
+ if queue is None or queue.sycl_device.is_cpu:
313
+ return daal4py_predict(self, X, "computeClassProbabilities")
314
+
315
+ X = self._validate_data(X, accept_sparse=False, reset=False)
316
+ assert hasattr(self, "_onedal_estimator")
317
+ return self._onedal_estimator.predict_proba(X, queue=queue)
318
+
319
+ def _onedal_predict_log_proba(self, X, queue=None):
320
+ if queue is None or queue.sycl_device.is_cpu:
321
+ return daal4py_predict(self, X, "computeClassLogProbabilities")
322
+
323
+ X = self._validate_data(X, accept_sparse=False, reset=False)
324
+ assert hasattr(self, "_onedal_estimator")
325
+ return self._onedal_estimator.predict_log_proba(X, queue=queue)
326
+
327
+ else:
328
+ LogisticRegression = LogisticRegression_daal4py
329
+
330
+ logging.warning(
331
+ "Sklearnex LogisticRegression requires oneDAL version >= 2024.0.1 "
332
+ "but it was not found"
333
+ )
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -29,14 +28,20 @@ from onedal.tests.utils._dataframes_support import (
29
28
 
30
29
 
31
30
  @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
32
- def test_sklearnex_import_linear(dataframe, queue):
31
+ @pytest.mark.parametrize("macro_block", [None, 1024])
32
+ def test_sklearnex_import_linear(dataframe, queue, macro_block):
33
33
  from sklearnex.linear_model import LinearRegression
34
34
 
35
35
  X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
36
36
  y = np.dot(X, np.array([1, 2])) + 3
37
37
  X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
38
38
  y = _convert_to_dataframe(y, sycl_queue=queue, target_df=dataframe)
39
- linreg = LinearRegression().fit(X, y)
39
+ linreg = LinearRegression()
40
+ if daal_check_version((2024, "P", 0)) and macro_block is not None:
41
+ hparams = linreg.get_hyperparameters("fit")
42
+ hparams.cpu_macro_block = macro_block
43
+ hparams.gpu_macro_block = macro_block
44
+ linreg.fit(X, y)
40
45
  if daal_check_version((2023, "P", 100)):
41
46
  assert hasattr(linreg, "_onedal_estimator")
42
47
  assert "sklearnex" in linreg.__module__
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -16,14 +15,79 @@
16
15
  # ===============================================================================
17
16
 
18
17
  import numpy as np
18
+ import pytest
19
19
  from numpy.testing import assert_allclose
20
- from sklearn.datasets import load_iris
20
+ from sklearn.datasets import load_breast_cancer, load_iris
21
+ from sklearn.metrics import accuracy_score
22
+ from sklearn.model_selection import train_test_split
21
23
 
24
+ from daal4py.sklearn._utils import daal_check_version
25
+ from onedal.tests.utils._dataframes_support import (
26
+ _as_numpy,
27
+ _convert_to_dataframe,
28
+ get_dataframes_and_queues,
29
+ )
22
30
 
23
- def test_sklearnex_import():
31
+
32
+ def prepare_input(X, y, dataframe, queue):
33
+ X_train, X_test, y_train, y_test = train_test_split(
34
+ X, y, train_size=0.8, random_state=42
35
+ )
36
+ X_train = _convert_to_dataframe(X_train, sycl_queue=queue, target_df=dataframe)
37
+ y_train = _convert_to_dataframe(y_train, sycl_queue=queue, target_df=dataframe)
38
+ X_test = _convert_to_dataframe(X_test, sycl_queue=queue, target_df=dataframe)
39
+ return X_train, X_test, y_train, y_test
40
+
41
+
42
+ @pytest.mark.parametrize(
43
+ "dataframe,queue",
44
+ get_dataframes_and_queues(device_filter_="cpu"),
45
+ )
46
+ def test_sklearnex_multiclass_classification(dataframe, queue):
24
47
  from sklearnex.linear_model import LogisticRegression
25
48
 
26
49
  X, y = load_iris(return_X_y=True)
27
- logreg = LogisticRegression(random_state=0, max_iter=200).fit(X, y)
28
- assert "daal4py" in logreg.__module__
29
- assert_allclose(logreg.score(X, y), 0.9733, atol=1e-3)
50
+ X_train, X_test, y_train, y_test = prepare_input(X, y, dataframe, queue)
51
+
52
+ logreg = LogisticRegression(fit_intercept=True, solver="lbfgs", max_iter=200).fit(
53
+ X_train, y_train
54
+ )
55
+
56
+ if daal_check_version((2024, "P", 1)):
57
+ assert "sklearnex" in logreg.__module__
58
+ else:
59
+ assert "daal4py" in logreg.__module__
60
+
61
+ y_pred = _as_numpy(logreg.predict(X_test))
62
+ assert accuracy_score(y_test, y_pred) > 0.99
63
+
64
+
65
+ @pytest.mark.parametrize(
66
+ "dataframe,queue",
67
+ get_dataframes_and_queues(),
68
+ )
69
+ def test_sklearnex_binary_classification(dataframe, queue):
70
+ from sklearnex.linear_model import LogisticRegression
71
+
72
+ X, y = load_breast_cancer(return_X_y=True)
73
+ X_train, X_test, y_train, y_test = prepare_input(X, y, dataframe, queue)
74
+
75
+ logreg = LogisticRegression(fit_intercept=True, solver="newton-cg", max_iter=100).fit(
76
+ X_train, y_train
77
+ )
78
+
79
+ if daal_check_version((2024, "P", 1)):
80
+ assert "sklearnex" in logreg.__module__
81
+ else:
82
+ assert "daal4py" in logreg.__module__
83
+ if (
84
+ dataframe != "numpy"
85
+ and queue is not None
86
+ and queue.sycl_device.is_gpu
87
+ and daal_check_version((2024, "P", 1))
88
+ ):
89
+ # fit was done on gpu
90
+ assert hasattr(logreg, "_onedal_estimator")
91
+
92
+ y_pred = _as_numpy(logreg.predict(X_test))
93
+ assert accuracy_score(y_test, y_pred) > 0.95
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #