scikit-learn-intelex 2024.0.1__py311-none-manylinux1_x86_64.whl → 2024.4.0__py311-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 (89) hide show
  1. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/METADATA +2 -2
  2. scikit_learn_intelex-2024.4.0.dist-info/RECORD +101 -0
  3. sklearnex/__init__.py +11 -7
  4. sklearnex/__main__.py +0 -1
  5. sklearnex/_device_offload.py +31 -4
  6. sklearnex/_utils.py +15 -1
  7. sklearnex/basic_statistics/__init__.py +2 -2
  8. sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
  9. sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +386 -0
  10. sklearnex/cluster/__init__.py +0 -1
  11. sklearnex/cluster/dbscan.py +5 -2
  12. sklearnex/cluster/k_means.py +0 -1
  13. sklearnex/cluster/tests/test_dbscan.py +0 -1
  14. sklearnex/cluster/tests/test_kmeans.py +0 -1
  15. sklearnex/conftest.py +63 -0
  16. sklearnex/covariance/__init__.py +19 -0
  17. sklearnex/covariance/incremental_covariance.py +130 -0
  18. sklearnex/covariance/tests/test_incremental_covariance.py +143 -0
  19. sklearnex/decomposition/__init__.py +0 -1
  20. sklearnex/decomposition/pca.py +319 -2
  21. sklearnex/decomposition/tests/test_pca.py +34 -6
  22. sklearnex/dispatcher.py +93 -28
  23. sklearnex/ensemble/__init__.py +0 -1
  24. sklearnex/ensemble/_forest.py +93 -89
  25. sklearnex/ensemble/tests/test_forest.py +15 -20
  26. sklearnex/glob/__main__.py +0 -1
  27. sklearnex/glob/dispatcher.py +0 -1
  28. sklearnex/linear_model/__init__.py +1 -3
  29. sklearnex/linear_model/coordinate_descent.py +0 -1
  30. sklearnex/linear_model/linear.py +275 -332
  31. sklearnex/linear_model/logistic_path.py +0 -1
  32. sklearnex/linear_model/logistic_regression.py +385 -0
  33. sklearnex/linear_model/ridge.py +0 -1
  34. sklearnex/linear_model/tests/test_linear.py +47 -7
  35. sklearnex/linear_model/tests/test_logreg.py +70 -8
  36. sklearnex/manifold/__init__.py +0 -1
  37. sklearnex/manifold/t_sne.py +0 -1
  38. sklearnex/manifold/tests/test_tsne.py +0 -1
  39. sklearnex/metrics/__init__.py +0 -1
  40. sklearnex/metrics/pairwise.py +0 -1
  41. sklearnex/metrics/ranking.py +0 -1
  42. sklearnex/metrics/tests/test_metrics.py +0 -1
  43. sklearnex/model_selection/__init__.py +0 -1
  44. sklearnex/model_selection/split.py +0 -1
  45. sklearnex/model_selection/tests/test_model_selection.py +0 -1
  46. sklearnex/neighbors/__init__.py +1 -2
  47. sklearnex/neighbors/_lof.py +221 -0
  48. sklearnex/neighbors/common.py +5 -3
  49. sklearnex/neighbors/knn_classification.py +47 -133
  50. sklearnex/neighbors/knn_regression.py +20 -129
  51. sklearnex/neighbors/knn_unsupervised.py +15 -89
  52. sklearnex/neighbors/tests/test_neighbors.py +12 -17
  53. sklearnex/preview/__init__.py +1 -2
  54. sklearnex/preview/cluster/__init__.py +0 -1
  55. sklearnex/preview/cluster/k_means.py +7 -74
  56. sklearnex/preview/{decomposition → covariance}/__init__.py +19 -20
  57. sklearnex/preview/covariance/covariance.py +133 -0
  58. sklearnex/preview/covariance/tests/test_covariance.py +66 -0
  59. sklearnex/spmd/__init__.py +1 -0
  60. sklearnex/spmd/covariance/__init__.py +19 -0
  61. sklearnex/spmd/covariance/covariance.py +21 -0
  62. sklearnex/spmd/ensemble/forest.py +4 -12
  63. sklearnex/spmd/linear_model/__init__.py +2 -1
  64. sklearnex/spmd/linear_model/logistic_regression.py +21 -0
  65. sklearnex/svm/__init__.py +0 -1
  66. sklearnex/svm/_common.py +4 -7
  67. sklearnex/svm/nusvc.py +73 -49
  68. sklearnex/svm/nusvr.py +8 -52
  69. sklearnex/svm/svc.py +74 -51
  70. sklearnex/svm/svr.py +5 -49
  71. sklearnex/svm/tests/test_svm.py +0 -1
  72. sklearnex/tests/_utils.py +164 -0
  73. sklearnex/tests/test_memory_usage.py +9 -7
  74. sklearnex/tests/test_monkeypatch.py +192 -134
  75. sklearnex/tests/test_n_jobs_support.py +99 -0
  76. sklearnex/tests/test_parallel.py +6 -8
  77. sklearnex/tests/test_patching.py +338 -89
  78. sklearnex/utils/__init__.py +2 -1
  79. sklearnex/utils/_namespace.py +97 -0
  80. sklearnex/utils/validation.py +0 -1
  81. scikit_learn_intelex-2024.0.1.dist-info/RECORD +0 -90
  82. sklearnex/neighbors/lof.py +0 -437
  83. sklearnex/preview/decomposition/pca.py +0 -376
  84. sklearnex/preview/decomposition/tests/test_preview_pca.py +0 -38
  85. sklearnex/tests/_models_info.py +0 -170
  86. sklearnex/tests/utils/_launch_algorithms.py +0 -118
  87. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/LICENSE.txt +0 -0
  88. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/WHEEL +0 -0
  89. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,385 @@
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.metrics import accuracy_score
42
+ from sklearn.utils.multiclass import type_of_target
43
+ from sklearn.utils.validation import check_X_y
44
+
45
+ from daal4py.sklearn._n_jobs_support import control_n_jobs
46
+ from daal4py.sklearn._utils import sklearn_check_version
47
+ from onedal.linear_model import LogisticRegression as onedal_LogisticRegression
48
+ from onedal.utils import _num_samples
49
+
50
+ from .._device_offload import dispatch, wrap_output_data
51
+ from .._utils import PatchingConditionsChain, get_patch_message
52
+ from ..utils.validation import _assert_all_finite
53
+
54
+ @control_n_jobs(
55
+ decorated_methods=[
56
+ "fit",
57
+ "predict",
58
+ "predict_proba",
59
+ "predict_log_proba",
60
+ "score",
61
+ ]
62
+ )
63
+ class LogisticRegression(sklearn_LogisticRegression, BaseLogisticRegression):
64
+ __doc__ = sklearn_LogisticRegression.__doc__
65
+ intercept_, coef_, n_iter_ = None, None, None
66
+
67
+ if sklearn_check_version("1.2"):
68
+ _parameter_constraints: dict = {
69
+ **sklearn_LogisticRegression._parameter_constraints
70
+ }
71
+
72
+ def __init__(
73
+ self,
74
+ penalty="l2",
75
+ *,
76
+ dual=False,
77
+ tol=1e-4,
78
+ C=1.0,
79
+ fit_intercept=True,
80
+ intercept_scaling=1,
81
+ class_weight=None,
82
+ random_state=None,
83
+ solver="lbfgs",
84
+ max_iter=100,
85
+ multi_class="auto",
86
+ verbose=0,
87
+ warm_start=False,
88
+ n_jobs=None,
89
+ l1_ratio=None,
90
+ ):
91
+ super().__init__(
92
+ penalty=penalty,
93
+ dual=dual,
94
+ tol=tol,
95
+ C=C,
96
+ fit_intercept=fit_intercept,
97
+ intercept_scaling=intercept_scaling,
98
+ class_weight=class_weight,
99
+ random_state=random_state,
100
+ solver=solver,
101
+ max_iter=max_iter,
102
+ multi_class=multi_class,
103
+ verbose=verbose,
104
+ warm_start=warm_start,
105
+ n_jobs=n_jobs,
106
+ l1_ratio=l1_ratio,
107
+ )
108
+
109
+ _onedal_cpu_fit = daal4py_fit
110
+
111
+ def fit(self, X, y, sample_weight=None):
112
+ if sklearn_check_version("1.0"):
113
+ self._check_feature_names(X, reset=True)
114
+ if sklearn_check_version("1.2"):
115
+ self._validate_params()
116
+ dispatch(
117
+ self,
118
+ "fit",
119
+ {
120
+ "onedal": self.__class__._onedal_fit,
121
+ "sklearn": sklearn_LogisticRegression.fit,
122
+ },
123
+ X,
124
+ y,
125
+ sample_weight,
126
+ )
127
+ return self
128
+
129
+ @wrap_output_data
130
+ def predict(self, X):
131
+ if sklearn_check_version("1.0"):
132
+ self._check_feature_names(X, reset=False)
133
+ return dispatch(
134
+ self,
135
+ "predict",
136
+ {
137
+ "onedal": self.__class__._onedal_predict,
138
+ "sklearn": sklearn_LogisticRegression.predict,
139
+ },
140
+ X,
141
+ )
142
+
143
+ @wrap_output_data
144
+ def predict_proba(self, X):
145
+ if sklearn_check_version("1.0"):
146
+ self._check_feature_names(X, reset=False)
147
+ return dispatch(
148
+ self,
149
+ "predict",
150
+ {
151
+ "onedal": self.__class__._onedal_predict_proba,
152
+ "sklearn": sklearn_LogisticRegression.predict_proba,
153
+ },
154
+ X,
155
+ )
156
+
157
+ @wrap_output_data
158
+ def predict_log_proba(self, X):
159
+ if sklearn_check_version("1.0"):
160
+ self._check_feature_names(X, reset=False)
161
+ return dispatch(
162
+ self,
163
+ "predict",
164
+ {
165
+ "onedal": self.__class__._onedal_predict_log_proba,
166
+ "sklearn": sklearn_LogisticRegression.predict_log_proba,
167
+ },
168
+ X,
169
+ )
170
+
171
+ @wrap_output_data
172
+ def score(self, X, y, sample_weight=None):
173
+ if sklearn_check_version("1.0"):
174
+ self._check_feature_names(X, reset=False)
175
+ return dispatch(
176
+ self,
177
+ "score",
178
+ {
179
+ "onedal": self.__class__._onedal_score,
180
+ "sklearn": sklearn_LogisticRegression.score,
181
+ },
182
+ X,
183
+ y,
184
+ sample_weight=sample_weight,
185
+ )
186
+
187
+ def _onedal_score(self, X, y, sample_weight=None, queue=None):
188
+ return accuracy_score(
189
+ y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
190
+ )
191
+
192
+ def _test_type_and_finiteness(self, X_in):
193
+ X = np.asarray(X_in)
194
+
195
+ if np.iscomplexobj(X):
196
+ return False
197
+ try:
198
+ _assert_all_finite(X)
199
+ except BaseException:
200
+ return False
201
+ return True
202
+
203
+ def _onedal_gpu_fit_supported(self, method_name, *data):
204
+ assert method_name == "fit"
205
+ assert len(data) == 3
206
+ X, y, sample_weight = data
207
+
208
+ class_name = self.__class__.__name__
209
+ patching_status = PatchingConditionsChain(
210
+ f"sklearn.linear_model.{class_name}.fit"
211
+ )
212
+
213
+ dal_ready = patching_status.and_conditions(
214
+ [
215
+ (self.penalty == "l2", "Only l2 penalty is supported."),
216
+ (self.dual == False, "dual=True is not supported."),
217
+ (
218
+ self.intercept_scaling == 1,
219
+ "Intercept scaling is not supported.",
220
+ ),
221
+ (self.class_weight is None, "Class weight is not supported"),
222
+ (self.solver == "newton-cg", "Only newton-cg solver is supported."),
223
+ (
224
+ self.multi_class != "multinomial",
225
+ "multi_class parameter is not supported.",
226
+ ),
227
+ (self.warm_start == False, "Warm start is not supported."),
228
+ (self.l1_ratio is None, "l1 ratio is not supported."),
229
+ (sample_weight is None, "Sample weight is not supported."),
230
+ (
231
+ type_of_target(y) == "binary",
232
+ "Only binary classification is supported",
233
+ ),
234
+ ]
235
+ )
236
+
237
+ if not dal_ready:
238
+ return patching_status
239
+
240
+ if not patching_status.and_condition(
241
+ self._test_type_and_finiteness(X), "Input X is not supported."
242
+ ):
243
+ return patching_status
244
+
245
+ patching_status.and_condition(
246
+ self._test_type_and_finiteness(y), "Input y is not supported."
247
+ )
248
+
249
+ return patching_status
250
+
251
+ def _onedal_gpu_predict_supported(self, method_name, *data):
252
+ assert method_name in [
253
+ "predict",
254
+ "predict_proba",
255
+ "predict_log_proba",
256
+ "score",
257
+ ]
258
+
259
+ class_name = self.__class__.__name__
260
+ patching_status = PatchingConditionsChain(
261
+ f"sklearn.linear_model.{class_name}.{method_name}"
262
+ )
263
+
264
+ n_samples = _num_samples(data[0])
265
+ model_is_sparse = issparse(self.coef_) or (
266
+ self.fit_intercept and issparse(self.intercept_)
267
+ )
268
+ dal_ready = patching_status.and_conditions(
269
+ [
270
+ (n_samples > 0, "Number of samples is less than 1."),
271
+ (
272
+ not any([issparse(i) for i in data]),
273
+ "Sparse input is not supported.",
274
+ ),
275
+ (not model_is_sparse, "Sparse coefficients are not supported."),
276
+ (
277
+ hasattr(self, "_onedal_estimator"),
278
+ "oneDAL model was not trained.",
279
+ ),
280
+ ]
281
+ )
282
+ if not dal_ready:
283
+ return patching_status
284
+
285
+ patching_status.and_condition(
286
+ self._test_type_and_finiteness(*data), "Input X is not supported."
287
+ )
288
+
289
+ return patching_status
290
+
291
+ def _onedal_gpu_supported(self, method_name, *data):
292
+ if method_name == "fit":
293
+ return self._onedal_gpu_fit_supported(method_name, *data)
294
+ if method_name in ["predict", "predict_proba", "predict_log_proba", "score"]:
295
+ return self._onedal_gpu_predict_supported(method_name, *data)
296
+ raise RuntimeError(
297
+ f"Unknown method {method_name} in {self.__class__.__name__}"
298
+ )
299
+
300
+ def _onedal_cpu_supported(self, method_name, *data):
301
+ class_name = self.__class__.__name__
302
+ patching_status = PatchingConditionsChain(
303
+ f"sklearn.linear_model.{class_name}.{method_name}"
304
+ )
305
+
306
+ return patching_status
307
+
308
+ def _initialize_onedal_estimator(self):
309
+ onedal_params = {
310
+ "tol": self.tol,
311
+ "C": self.C,
312
+ "fit_intercept": self.fit_intercept,
313
+ "solver": self.solver,
314
+ "max_iter": self.max_iter,
315
+ }
316
+ self._onedal_estimator = onedal_LogisticRegression(**onedal_params)
317
+
318
+ def _onedal_fit(self, X, y, sample_weight, queue=None):
319
+ if queue is None or queue.sycl_device.is_cpu:
320
+ return self._onedal_cpu_fit(X, y, sample_weight)
321
+
322
+ assert sample_weight is None
323
+
324
+ check_params = {
325
+ "X": X,
326
+ "y": y,
327
+ "dtype": [np.float64, np.float32],
328
+ "accept_sparse": False,
329
+ "multi_output": False,
330
+ "force_all_finite": True,
331
+ }
332
+ if sklearn_check_version("1.2"):
333
+ X, y = self._validate_data(**check_params)
334
+ else:
335
+ X, y = check_X_y(**check_params)
336
+ self._initialize_onedal_estimator()
337
+ try:
338
+ self._onedal_estimator.fit(X, y, queue=queue)
339
+ self._save_attributes()
340
+ except RuntimeError:
341
+ logging.getLogger("sklearnex").info(
342
+ f"{self.__class__.__name__}.fit "
343
+ + get_patch_message("sklearn_after_onedal")
344
+ )
345
+
346
+ del self._onedal_estimator
347
+ super().fit(X, y)
348
+
349
+ def _onedal_predict(self, X, queue=None):
350
+ if queue is None or queue.sycl_device.is_cpu:
351
+ return daal4py_predict(self, X, "computeClassLabels")
352
+
353
+ X = self._validate_data(X, accept_sparse=False, reset=False)
354
+ assert hasattr(self, "_onedal_estimator")
355
+ return self._onedal_estimator.predict(X, queue=queue)
356
+
357
+ def _onedal_predict_proba(self, X, queue=None):
358
+ if queue is None or queue.sycl_device.is_cpu:
359
+ return daal4py_predict(self, X, "computeClassProbabilities")
360
+
361
+ X = self._validate_data(X, accept_sparse=False, reset=False)
362
+ assert hasattr(self, "_onedal_estimator")
363
+ return self._onedal_estimator.predict_proba(X, queue=queue)
364
+
365
+ def _onedal_predict_log_proba(self, X, queue=None):
366
+ if queue is None or queue.sycl_device.is_cpu:
367
+ return daal4py_predict(self, X, "computeClassLogProbabilities")
368
+
369
+ X = self._validate_data(X, accept_sparse=False, reset=False)
370
+ assert hasattr(self, "_onedal_estimator")
371
+ return self._onedal_estimator.predict_log_proba(X, queue=queue)
372
+
373
+ fit.__doc__ = sklearn_LogisticRegression.fit.__doc__
374
+ predict.__doc__ = sklearn_LogisticRegression.predict.__doc__
375
+ predict_proba.__doc__ = sklearn_LogisticRegression.predict_proba.__doc__
376
+ predict_log_proba.__doc__ = sklearn_LogisticRegression.predict_log_proba.__doc__
377
+ score.__doc__ = sklearn_LogisticRegression.score.__doc__
378
+
379
+ else:
380
+ LogisticRegression = LogisticRegression_daal4py
381
+
382
+ logging.warning(
383
+ "Sklearnex LogisticRegression requires oneDAL version >= 2024.0.1 "
384
+ "but it was not found"
385
+ )
@@ -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,20 +28,33 @@ 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("dtype", [np.float32, np.float64])
32
+ @pytest.mark.parametrize("macro_block", [None, 1024])
33
+ def test_sklearnex_import_linear(dataframe, queue, dtype, macro_block):
33
34
  from sklearnex.linear_model import LinearRegression
34
35
 
35
36
  X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
36
37
  y = np.dot(X, np.array([1, 2])) + 3
38
+ X = X.astype(dtype=dtype)
39
+ y = y.astype(dtype=dtype)
37
40
  X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
38
41
  y = _convert_to_dataframe(y, sycl_queue=queue, target_df=dataframe)
39
- linreg = LinearRegression().fit(X, y)
40
- if daal_check_version((2023, "P", 100)):
41
- assert hasattr(linreg, "_onedal_estimator")
42
+
43
+ linreg = LinearRegression()
44
+ if daal_check_version((2024, "P", 0)) and macro_block is not None:
45
+ hparams = linreg.get_hyperparameters("fit")
46
+ hparams.cpu_macro_block = macro_block
47
+ hparams.gpu_macro_block = macro_block
48
+
49
+ linreg.fit(X, y)
50
+
51
+ assert hasattr(linreg, "_onedal_estimator")
42
52
  assert "sklearnex" in linreg.__module__
43
53
  assert linreg.n_features_in_ == 2
44
- assert_allclose(_as_numpy(linreg.intercept_), 3.0)
45
- assert_allclose(_as_numpy(linreg.coef_), [1.0, 2.0])
54
+
55
+ tol = 1e-5 if X.dtype == np.float32 else 1e-7
56
+ assert_allclose(_as_numpy(linreg.intercept_), 3.0, rtol=tol)
57
+ assert_allclose(_as_numpy(linreg.coef_), [1.0, 2.0], rtol=tol)
46
58
 
47
59
 
48
60
  def test_sklearnex_import_ridge():
@@ -75,3 +87,31 @@ def test_sklearnex_import_elastic():
75
87
  assert "daal4py" in elasticnet.__module__
76
88
  assert_allclose(elasticnet.intercept_, 1.451, atol=1e-3)
77
89
  assert_allclose(elasticnet.coef_, [18.838, 64.559], atol=1e-3)
90
+
91
+
92
+ @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
93
+ @pytest.mark.parametrize("dtype", [np.float32, np.float64])
94
+ def test_sklearnex_reconstruct_model(dataframe, queue, dtype):
95
+ from sklearnex.linear_model import LinearRegression
96
+
97
+ seed = 42
98
+ num_samples = 3500
99
+ num_features, num_targets = 14, 9
100
+
101
+ gen = np.random.default_rng(seed)
102
+ intercept = gen.random(size=num_targets, dtype=dtype)
103
+ coef = gen.random(size=(num_targets, num_features), dtype=dtype).T
104
+
105
+ X = gen.random(size=(num_samples, num_features), dtype=dtype)
106
+ gtr = X @ coef + intercept[np.newaxis, :]
107
+
108
+ X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
109
+
110
+ linreg = LinearRegression(fit_intercept=True)
111
+ linreg.coef_ = coef.T
112
+ linreg.intercept_ = intercept
113
+
114
+ y_pred = linreg.predict(X)
115
+
116
+ tol = 1e-5 if X.dtype == np.float32 else 1e-7
117
+ assert_allclose(gtr, _as_numpy(y_pred), rtol=tol)
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -15,15 +14,78 @@
15
14
  # limitations under the License.
16
15
  # ===============================================================================
17
16
 
18
- import numpy as np
19
- from numpy.testing import assert_allclose
20
- from sklearn.datasets import load_iris
17
+ import pytest
18
+ from sklearn.datasets import load_breast_cancer, load_iris
19
+ from sklearn.metrics import accuracy_score
20
+ from sklearn.model_selection import train_test_split
21
21
 
22
+ from daal4py.sklearn._utils import daal_check_version
23
+ from onedal.tests.utils._dataframes_support import (
24
+ _as_numpy,
25
+ _convert_to_dataframe,
26
+ get_dataframes_and_queues,
27
+ )
22
28
 
23
- def test_sklearnex_import():
29
+
30
+ def prepare_input(X, y, dataframe, queue):
31
+ X_train, X_test, y_train, y_test = train_test_split(
32
+ X, y, train_size=0.8, random_state=42
33
+ )
34
+ X_train = _convert_to_dataframe(X_train, sycl_queue=queue, target_df=dataframe)
35
+ y_train = _convert_to_dataframe(y_train, sycl_queue=queue, target_df=dataframe)
36
+ X_test = _convert_to_dataframe(X_test, sycl_queue=queue, target_df=dataframe)
37
+ return X_train, X_test, y_train, y_test
38
+
39
+
40
+ @pytest.mark.parametrize(
41
+ "dataframe,queue",
42
+ get_dataframes_and_queues(device_filter_="cpu"),
43
+ )
44
+ def test_sklearnex_multiclass_classification(dataframe, queue):
24
45
  from sklearnex.linear_model import LogisticRegression
25
46
 
26
47
  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)
48
+ X_train, X_test, y_train, y_test = prepare_input(X, y, dataframe, queue)
49
+
50
+ logreg = LogisticRegression(fit_intercept=True, solver="lbfgs", max_iter=200).fit(
51
+ X_train, y_train
52
+ )
53
+
54
+ if daal_check_version((2024, "P", 1)):
55
+ assert "sklearnex" in logreg.__module__
56
+ else:
57
+ assert "daal4py" in logreg.__module__
58
+
59
+ y_pred = _as_numpy(logreg.predict(X_test))
60
+ assert accuracy_score(y_test, y_pred) > 0.99
61
+
62
+
63
+ @pytest.mark.parametrize(
64
+ "dataframe,queue",
65
+ get_dataframes_and_queues(),
66
+ )
67
+ def test_sklearnex_binary_classification(dataframe, queue):
68
+ from sklearnex.linear_model import LogisticRegression
69
+
70
+ X, y = load_breast_cancer(return_X_y=True)
71
+ X_train, X_test, y_train, y_test = prepare_input(X, y, dataframe, queue)
72
+
73
+ logreg = LogisticRegression(fit_intercept=True, solver="newton-cg", max_iter=100).fit(
74
+ X_train, y_train
75
+ )
76
+
77
+ if daal_check_version((2024, "P", 1)):
78
+ assert "sklearnex" in logreg.__module__
79
+ else:
80
+ assert "daal4py" in logreg.__module__
81
+ if (
82
+ dataframe != "numpy"
83
+ and queue is not None
84
+ and queue.sycl_device.is_gpu
85
+ and daal_check_version((2024, "P", 1))
86
+ ):
87
+ # fit was done on gpu
88
+ assert hasattr(logreg, "_onedal_estimator")
89
+
90
+ y_pred = _as_numpy(logreg.predict(X_test))
91
+ 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
  #
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
1
  # ===============================================================================
3
2
  # Copyright 2021 Intel Corporation
4
3
  #
@@ -15,10 +14,10 @@
15
14
  # limitations under the License.
16
15
  # ===============================================================================
17
16
 
17
+ from ._lof import LocalOutlierFactor
18
18
  from .knn_classification import KNeighborsClassifier
19
19
  from .knn_regression import KNeighborsRegressor
20
20
  from .knn_unsupervised import NearestNeighbors
21
- from .lof import LocalOutlierFactor
22
21
 
23
22
  __all__ = [
24
23
  "KNeighborsClassifier",