scikit-learn-intelex 2024.1.0__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 (62) hide show
  1. {scikit_learn_intelex-2024.1.0.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 +9 -7
  4. sklearnex/_device_offload.py +31 -4
  5. sklearnex/basic_statistics/__init__.py +2 -1
  6. sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
  7. sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +386 -0
  8. sklearnex/cluster/dbscan.py +6 -4
  9. sklearnex/conftest.py +63 -0
  10. sklearnex/{preview/decomposition → covariance}/__init__.py +19 -19
  11. sklearnex/covariance/incremental_covariance.py +130 -0
  12. sklearnex/covariance/tests/test_incremental_covariance.py +143 -0
  13. sklearnex/decomposition/pca.py +319 -1
  14. sklearnex/decomposition/tests/test_pca.py +34 -5
  15. sklearnex/dispatcher.py +93 -61
  16. sklearnex/ensemble/_forest.py +81 -97
  17. sklearnex/ensemble/tests/test_forest.py +15 -19
  18. sklearnex/linear_model/__init__.py +1 -2
  19. sklearnex/linear_model/linear.py +275 -347
  20. sklearnex/{preview/linear_model → linear_model}/logistic_regression.py +83 -50
  21. sklearnex/linear_model/tests/test_linear.py +40 -5
  22. sklearnex/linear_model/tests/test_logreg.py +70 -7
  23. sklearnex/neighbors/__init__.py +1 -1
  24. sklearnex/neighbors/_lof.py +221 -0
  25. sklearnex/neighbors/common.py +4 -1
  26. sklearnex/neighbors/knn_classification.py +47 -137
  27. sklearnex/neighbors/knn_regression.py +20 -132
  28. sklearnex/neighbors/knn_unsupervised.py +16 -93
  29. sklearnex/neighbors/tests/test_neighbors.py +12 -16
  30. sklearnex/preview/__init__.py +1 -1
  31. sklearnex/preview/cluster/k_means.py +8 -81
  32. sklearnex/preview/covariance/covariance.py +51 -16
  33. sklearnex/preview/covariance/tests/test_covariance.py +18 -5
  34. sklearnex/spmd/__init__.py +1 -0
  35. sklearnex/{preview/linear_model → spmd/covariance}/__init__.py +5 -5
  36. sklearnex/spmd/covariance/covariance.py +21 -0
  37. sklearnex/spmd/ensemble/forest.py +4 -12
  38. sklearnex/spmd/linear_model/__init__.py +2 -1
  39. sklearnex/spmd/linear_model/logistic_regression.py +21 -0
  40. sklearnex/svm/_common.py +4 -7
  41. sklearnex/svm/nusvc.py +74 -55
  42. sklearnex/svm/nusvr.py +9 -56
  43. sklearnex/svm/svc.py +74 -56
  44. sklearnex/svm/svr.py +6 -53
  45. sklearnex/tests/_utils.py +164 -0
  46. sklearnex/tests/test_memory_usage.py +9 -7
  47. sklearnex/tests/test_monkeypatch.py +179 -138
  48. sklearnex/tests/test_n_jobs_support.py +77 -9
  49. sklearnex/tests/test_parallel.py +6 -8
  50. sklearnex/tests/test_patching.py +338 -89
  51. sklearnex/utils/__init__.py +2 -1
  52. sklearnex/utils/_namespace.py +97 -0
  53. scikit_learn_intelex-2024.1.0.dist-info/RECORD +0 -97
  54. sklearnex/neighbors/lof.py +0 -436
  55. sklearnex/preview/decomposition/pca.py +0 -376
  56. sklearnex/preview/decomposition/tests/test_preview_pca.py +0 -42
  57. sklearnex/preview/linear_model/tests/test_preview_logistic_regression.py +0 -59
  58. sklearnex/tests/_models_info.py +0 -170
  59. sklearnex/tests/utils/_launch_algorithms.py +0 -118
  60. {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/LICENSE.txt +0 -0
  61. {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/WHEEL +0 -0
  62. {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/top_level.txt +0 -0
@@ -14,7 +14,6 @@
14
14
  # limitations under the License.
15
15
  # ===============================================================================
16
16
 
17
- import numpy as np
18
17
  import pytest
19
18
  from numpy.testing import assert_allclose
20
19
 
@@ -23,12 +22,16 @@ from onedal.tests.utils._dataframes_support import (
23
22
  _convert_to_dataframe,
24
23
  get_dataframes_and_queues,
25
24
  )
25
+ from sklearnex.neighbors import (
26
+ KNeighborsClassifier,
27
+ KNeighborsRegressor,
28
+ LocalOutlierFactor,
29
+ NearestNeighbors,
30
+ )
26
31
 
27
32
 
28
33
  @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
29
34
  def test_sklearnex_import_knn_classifier(dataframe, queue):
30
- from sklearnex.neighbors import KNeighborsClassifier
31
-
32
35
  X = _convert_to_dataframe([[0], [1], [2], [3]], sycl_queue=queue, target_df=dataframe)
33
36
  y = _convert_to_dataframe([0, 0, 1, 1], sycl_queue=queue, target_df=dataframe)
34
37
  neigh = KNeighborsClassifier(n_neighbors=3).fit(X, y)
@@ -40,8 +43,6 @@ def test_sklearnex_import_knn_classifier(dataframe, queue):
40
43
 
41
44
  @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
42
45
  def test_sklearnex_import_knn_regression(dataframe, queue):
43
- from sklearnex.neighbors import KNeighborsRegressor
44
-
45
46
  X = _convert_to_dataframe([[0], [1], [2], [3]], sycl_queue=queue, target_df=dataframe)
46
47
  y = _convert_to_dataframe([0, 0, 1, 1], sycl_queue=queue, target_df=dataframe)
47
48
  neigh = KNeighborsRegressor(n_neighbors=2).fit(X, y)
@@ -51,18 +52,16 @@ def test_sklearnex_import_knn_regression(dataframe, queue):
51
52
  assert_allclose(pred, [0.5])
52
53
 
53
54
 
54
- # TODO:
55
- # investigate failure for `dpnp.ndarrays` and `dpctl.tensors`.
55
+ @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
56
56
  @pytest.mark.parametrize(
57
- "dataframe,queue", get_dataframes_and_queues(dataframe_filter_="numpy")
57
+ "estimator",
58
+ [LocalOutlierFactor, NearestNeighbors],
58
59
  )
59
- def test_sklearnex_import_nn(dataframe, queue):
60
- from sklearnex.neighbors import NearestNeighbors
61
-
60
+ def test_sklearnex_kneighbors(estimator, dataframe, queue):
62
61
  X = [[0, 0, 2], [1, 0, 0], [0, 0, 1]]
63
62
  X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
64
63
  test = _convert_to_dataframe([[0, 0, 1.3]], sycl_queue=queue, target_df=dataframe)
65
- neigh = NearestNeighbors(n_neighbors=2).fit(X)
64
+ neigh = estimator(n_neighbors=2).fit(X)
66
65
  result = neigh.kneighbors(test, 2, return_distance=False)
67
66
  result = _as_numpy(result)
68
67
  assert "sklearnex" in neigh.__module__
@@ -71,14 +70,11 @@ def test_sklearnex_import_nn(dataframe, queue):
71
70
 
72
71
  @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
73
72
  def test_sklearnex_import_lof(dataframe, queue):
74
- from sklearnex.neighbors import LocalOutlierFactor
75
-
76
73
  X = [[7, 7, 7], [1, 0, 0], [0, 0, 1], [0, 0, 1]]
77
74
  X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
78
75
  lof = LocalOutlierFactor(n_neighbors=2)
79
76
  result = lof.fit_predict(X)
80
77
  result = _as_numpy(result)
81
- assert hasattr(lof, "_knn")
78
+ assert hasattr(lof, "_onedal_estimator")
82
79
  assert "sklearnex" in lof.__module__
83
- assert "sklearnex" in lof._knn.__module__
84
80
  assert_allclose(result, [-1, 1, 1, 1])
@@ -14,4 +14,4 @@
14
14
  # limitations under the License.
15
15
  # ==============================================================================
16
16
 
17
- __all__ = ["cluster", "covariance", "decomposition", "linear_model"]
17
+ __all__ = ["cluster", "covariance"]
@@ -29,18 +29,15 @@ if daal_check_version((2023, "P", 200)):
29
29
  check_is_fitted,
30
30
  )
31
31
 
32
- from daal4py.sklearn._utils import (
33
- control_n_jobs,
34
- run_with_n_jobs,
35
- sklearn_check_version,
36
- )
32
+ from daal4py.sklearn._n_jobs_support import control_n_jobs
33
+ from daal4py.sklearn._utils import sklearn_check_version
37
34
  from onedal.cluster import KMeans as onedal_KMeans
38
35
 
39
36
  from ..._device_offload import dispatch, wrap_output_data
40
37
  from ..._utils import PatchingConditionsChain
41
38
  from ._common import BaseKMeans
42
39
 
43
- @control_n_jobs
40
+ @control_n_jobs(decorated_methods=["fit", "predict"])
44
41
  class KMeans(sklearn_KMeans, BaseKMeans):
45
42
  __doc__ = sklearn_KMeans.__doc__
46
43
  n_iter_, inertia_ = None, None
@@ -175,24 +172,6 @@ if daal_check_version((2023, "P", 200)):
175
172
  return patching_status
176
173
 
177
174
  def fit(self, X, y=None, sample_weight=None):
178
- """Compute k-means clustering.
179
-
180
- Parameters
181
- ----------
182
- X : array-like or sparse matrix, shape=(n_samples, n_features)
183
- Training instances to cluster. It must be noted that the data
184
- will be converted to C ordering, which will cause a memory
185
- copy if the given data is not C-contiguous.
186
-
187
- y : Ignored
188
- not used, present here for API consistency by convention.
189
-
190
- sample_weight : array-like, shape (n_samples,), optional
191
- The weights for each observation in X. If None, all observations
192
- are assigned equal weight (default: None)
193
-
194
- """
195
-
196
175
  if sklearn_check_version("1.0"):
197
176
  self._check_feature_names(X, reset=True)
198
177
  if sklearn_check_version("1.2"):
@@ -212,7 +191,6 @@ if daal_check_version((2023, "P", 200)):
212
191
 
213
192
  return self
214
193
 
215
- @run_with_n_jobs
216
194
  def _onedal_fit(self, X, _, sample_weight, queue=None):
217
195
  assert sample_weight is None
218
196
 
@@ -261,24 +239,6 @@ if daal_check_version((2023, "P", 200)):
261
239
 
262
240
  @wrap_output_data
263
241
  def predict(self, X):
264
- """Compute k-means clustering.
265
-
266
- Parameters
267
- ----------
268
- X : array-like or sparse matrix, shape=(n_samples, n_features)
269
- Training instances to cluster. It must be noted that the data
270
- will be converted to C ordering, which will cause a memory
271
- copy if the given data is not C-contiguous.
272
-
273
- y : Ignored
274
- not used, present here for API consistency by convention.
275
-
276
- sample_weight : array-like, shape (n_samples,), optional
277
- The weights for each observation in X. If None, all observations
278
- are assigned equal weight (default: None)
279
-
280
- """
281
-
282
242
  if sklearn_check_version("1.0"):
283
243
  self._check_feature_names(X, reset=True)
284
244
  if sklearn_check_version("1.2"):
@@ -294,7 +254,6 @@ if daal_check_version((2023, "P", 200)):
294
254
  X,
295
255
  )
296
256
 
297
- @run_with_n_jobs
298
257
  def _onedal_predict(self, X, queue=None):
299
258
  X = self._validate_data(
300
259
  X, accept_sparse=False, reset=False, dtype=[np.float64, np.float32]
@@ -322,52 +281,20 @@ if daal_check_version((2023, "P", 200)):
322
281
 
323
282
  @wrap_output_data
324
283
  def fit_transform(self, X, y=None, sample_weight=None):
325
- """Compute clustering and transform X to cluster-distance space.
326
-
327
- Equivalent to fit(X).transform(X), but more efficiently implemented.
328
-
329
- Parameters
330
- ----------
331
- X : {array-like, sparse matrix} of shape (n_samples, n_features)
332
- New data to transform.
333
-
334
- y : Ignored
335
- Not used, present here for API consistency by convention.
336
-
337
- sample_weight : array-like of shape (n_samples,), default=None
338
- The weights for each observation in X. If None, all observations
339
- are assigned equal weight.
340
-
341
- Returns
342
- -------
343
- X_new : ndarray of shape (n_samples, n_clusters)
344
- X transformed in the new space.
345
- """
346
284
  return self.fit(X, sample_weight=sample_weight)._transform(X)
347
285
 
348
286
  @wrap_output_data
349
287
  def transform(self, X):
350
- """Transform X to a cluster-distance space.
351
-
352
- In the new space, each dimension is the distance to the cluster
353
- centers. Note that even if X is sparse, the array returned by
354
- `transform` will typically be dense.
355
-
356
- Parameters
357
- ----------
358
- X : {array-like, sparse matrix} of shape (n_samples, n_features)
359
- New data to transform.
360
-
361
- Returns
362
- -------
363
- X_new : ndarray of shape (n_samples, n_clusters)
364
- X transformed in the new space.
365
- """
366
288
  check_is_fitted(self)
367
289
 
368
290
  X = self._check_test_data(X)
369
291
  return self._transform(X)
370
292
 
293
+ fit.__doc__ = sklearn_KMeans.fit.__doc__
294
+ predict.__doc__ = sklearn_KMeans.predict.__doc__
295
+ transform.__doc__ = sklearn_KMeans.transform.__doc__
296
+ fit_transform.__doc__ = sklearn_KMeans.fit_transform.__doc__
297
+
371
298
  else:
372
299
  from daal4py.sklearn.cluster import KMeans
373
300
 
@@ -14,35 +14,55 @@
14
14
  # limitations under the License.
15
15
  # ===============================================================================
16
16
 
17
+ import warnings
18
+
19
+ import numpy as np
17
20
  from scipy import sparse as sp
18
21
  from sklearn.covariance import EmpiricalCovariance as sklearn_EmpiricalCovariance
19
22
  from sklearn.utils import check_array
20
23
 
21
- from daal4py.sklearn._utils import control_n_jobs, run_with_n_jobs, sklearn_check_version
24
+ from daal4py.sklearn._n_jobs_support import control_n_jobs
25
+ from daal4py.sklearn._utils import daal_check_version, sklearn_check_version
22
26
  from onedal.common.hyperparameters import get_hyperparameters
23
27
  from onedal.covariance import EmpiricalCovariance as onedal_EmpiricalCovariance
28
+ from sklearnex import config_context
29
+ from sklearnex.metrics import pairwise_distances
24
30
 
25
- from ..._device_offload import dispatch
31
+ from ..._device_offload import dispatch, wrap_output_data
26
32
  from ..._utils import PatchingConditionsChain, register_hyperparameters
27
33
 
28
34
 
29
35
  @register_hyperparameters({"fit": get_hyperparameters("covariance", "compute")})
30
- @control_n_jobs
36
+ @control_n_jobs(decorated_methods=["fit", "mahalanobis"])
31
37
  class EmpiricalCovariance(sklearn_EmpiricalCovariance):
32
38
  __doc__ = sklearn_EmpiricalCovariance.__doc__
33
39
 
40
+ if sklearn_check_version("1.2"):
41
+ _parameter_constraints: dict = {
42
+ **sklearn_EmpiricalCovariance._parameter_constraints,
43
+ }
44
+
34
45
  def _save_attributes(self):
35
46
  assert hasattr(self, "_onedal_estimator")
36
- self.covariance_ = self._onedal_estimator.covariance_
47
+ if not daal_check_version((2024, "P", 400)) and self.assume_centered:
48
+ location = self._onedal_estimator.location_[None, :]
49
+ self._onedal_estimator.covariance_ += np.dot(location.T, location)
50
+ self._onedal_estimator.location_ = np.zeros_like(np.squeeze(location))
51
+ self._set_covariance(self._onedal_estimator.covariance_)
37
52
  self.location_ = self._onedal_estimator.location_
38
53
 
39
54
  _onedal_covariance = staticmethod(onedal_EmpiricalCovariance)
40
55
 
41
- @run_with_n_jobs
42
56
  def _onedal_fit(self, X, queue=None):
57
+ if X.shape[0] == 1:
58
+ warnings.warn(
59
+ "Only one sample available. You may want to reshape your data array"
60
+ )
61
+
43
62
  onedal_params = {
44
63
  "method": "dense",
45
64
  "bias": True,
65
+ "assume_centered": self.assume_centered,
46
66
  }
47
67
 
48
68
  self._onedal_estimator = self._onedal_covariance(**onedal_params)
@@ -54,18 +74,10 @@ class EmpiricalCovariance(sklearn_EmpiricalCovariance):
54
74
  patching_status = PatchingConditionsChain(
55
75
  f"sklearn.covariance.{class_name}.{method_name}"
56
76
  )
57
- if method_name == "fit":
77
+ if method_name in ["fit", "mahalanobis"]:
58
78
  (X,) = data
59
79
  patching_status.and_conditions(
60
80
  [
61
- (
62
- self.assume_centered == False,
63
- "assume_centered parameter is not supported on oneDAL side",
64
- ),
65
- (
66
- self.store_precision == False,
67
- "precision matrix calculation is not supported on oneDAL side",
68
- ),
69
81
  (not sp.issparse(X), "X is sparse. Sparse input is not supported."),
70
82
  ]
71
83
  )
@@ -79,9 +91,9 @@ class EmpiricalCovariance(sklearn_EmpiricalCovariance):
79
91
  if sklearn_check_version("1.2"):
80
92
  self._validate_params()
81
93
  if sklearn_check_version("0.23"):
82
- self._validate_data(X)
94
+ X = self._validate_data(X, force_all_finite=False)
83
95
  else:
84
- check_array(X)
96
+ X = check_array(X, force_all_finite=False)
85
97
 
86
98
  dispatch(
87
99
  self,
@@ -95,4 +107,27 @@ class EmpiricalCovariance(sklearn_EmpiricalCovariance):
95
107
 
96
108
  return self
97
109
 
110
+ # expose sklearnex pairwise_distances if mahalanobis distance eventually supported
111
+ @wrap_output_data
112
+ def mahalanobis(self, X):
113
+ if sklearn_check_version("1.0"):
114
+ X = self._validate_data(X, reset=False)
115
+ else:
116
+ X = check_array(X)
117
+
118
+ precision = self.get_precision()
119
+ with config_context(assume_finite=True):
120
+ # compute mahalanobis distances
121
+ dist = pairwise_distances(
122
+ X, self.location_[np.newaxis, :], metric="mahalanobis", VI=precision
123
+ )
124
+
125
+ return np.reshape(dist, (len(X),)) ** 2
126
+
127
+ error_norm = wrap_output_data(sklearn_EmpiricalCovariance.error_norm)
128
+ score = wrap_output_data(sklearn_EmpiricalCovariance.score)
129
+
98
130
  fit.__doc__ = sklearn_EmpiricalCovariance.fit.__doc__
131
+ mahalanobis.__doc__ = sklearn_EmpiricalCovariance.mahalanobis
132
+ error_norm.__doc__ = sklearn_EmpiricalCovariance.error_norm.__doc__
133
+ score.__doc__ = sklearn_EmpiricalCovariance.score.__doc__
@@ -27,27 +27,40 @@ from onedal.tests.utils._dataframes_support import (
27
27
 
28
28
  @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
29
29
  @pytest.mark.parametrize("macro_block", [None, 1024])
30
- def test_sklearnex_import_covariance(dataframe, queue, macro_block):
30
+ @pytest.mark.parametrize("assume_centered", [True, False])
31
+ def test_sklearnex_import_covariance(dataframe, queue, macro_block, assume_centered):
31
32
  from sklearnex.preview.covariance import EmpiricalCovariance
32
33
 
33
34
  X = np.array([[0, 1], [0, 1]])
35
+
34
36
  X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
35
- empcov = EmpiricalCovariance()
37
+ empcov = EmpiricalCovariance(assume_centered=assume_centered)
36
38
  if daal_check_version((2024, "P", 0)) and macro_block is not None:
37
39
  hparams = empcov.get_hyperparameters("fit")
38
40
  hparams.cpu_macro_block = macro_block
39
41
  result = empcov.fit(X)
42
+
40
43
  expected_covariance = np.array([[0, 0], [0, 0]])
41
- expected_means = np.array([0, 1])
44
+ expected_means = np.array([0, 0])
45
+
46
+ if assume_centered:
47
+ expected_covariance = np.array([[0, 0], [0, 1]])
48
+ else:
49
+ expected_means = np.array([0, 1])
42
50
 
43
51
  assert_allclose(expected_covariance, result.covariance_)
44
52
  assert_allclose(expected_means, result.location_)
45
53
 
46
54
  X = np.array([[1, 2], [3, 6]])
55
+
47
56
  X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
48
57
  result = empcov.fit(X)
49
- expected_covariance = np.array([[1, 2], [2, 4]])
50
- expected_means = np.array([2, 4])
58
+
59
+ if assume_centered:
60
+ expected_covariance = np.array([[5, 10], [10, 20]])
61
+ else:
62
+ expected_covariance = np.array([[1, 2], [2, 4]])
63
+ expected_means = np.array([2, 4])
51
64
 
52
65
  assert_allclose(expected_covariance, result.covariance_)
53
66
  assert_allclose(expected_means, result.location_)
@@ -17,6 +17,7 @@
17
17
  __all__ = [
18
18
  "basic_statistics",
19
19
  "cluster",
20
+ "covariance",
20
21
  "decomposition",
21
22
  "ensemble",
22
23
  "linear_model",
@@ -1,5 +1,5 @@
1
- # ===============================================================================
2
- # Copyright 2023 Intel Corporation
1
+ # ==============================================================================
2
+ # Copyright 2024 Intel Corporation
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -12,8 +12,8 @@
12
12
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
- # ===============================================================================
15
+ # ==============================================================================
16
16
 
17
- from .logistic_regression import LogisticRegression
17
+ from .covariance import EmpiricalCovariance
18
18
 
19
- __all__ = ["LogisticRegression"]
19
+ __all__ = ["EmpiricalCovariance"]
@@ -0,0 +1,21 @@
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
+ from onedal.spmd.covariance import EmpiricalCovariance
18
+
19
+ # TODO:
20
+ # Currently it uses `onedal` module interface.
21
+ # Add sklearnex dispatching.
@@ -14,8 +14,6 @@
14
14
  # limitations under the License.
15
15
  # ==============================================================================
16
16
 
17
- from abc import ABC
18
-
19
17
  from onedal.spmd.ensemble import RandomForestClassifier as onedal_RandomForestClassifier
20
18
  from onedal.spmd.ensemble import RandomForestRegressor as onedal_RandomForestRegressor
21
19
 
@@ -23,16 +21,9 @@ from ...ensemble import RandomForestClassifier as RandomForestClassifier_Batch
23
21
  from ...ensemble import RandomForestRegressor as RandomForestRegressor_Batch
24
22
 
25
23
 
26
- class BaseForestSPMD(ABC):
27
- def _onedal_classifier(self, **onedal_params):
28
- return onedal_RandomForestClassifier(**onedal_params)
29
-
30
- def _onedal_regressor(self, **onedal_params):
31
- return onedal_RandomForestRegressor(**onedal_params)
32
-
33
-
34
- class RandomForestClassifier(BaseForestSPMD, RandomForestClassifier_Batch):
24
+ class RandomForestClassifier(RandomForestClassifier_Batch):
35
25
  __doc__ = RandomForestClassifier_Batch.__doc__
26
+ _onedal_factory = onedal_RandomForestClassifier
36
27
 
37
28
  def _onedal_cpu_supported(self, method_name, *data):
38
29
  # TODO:
@@ -55,8 +46,9 @@ class RandomForestClassifier(BaseForestSPMD, RandomForestClassifier_Batch):
55
46
  return ready
56
47
 
57
48
 
58
- class RandomForestRegressor(BaseForestSPMD, RandomForestRegressor_Batch):
49
+ class RandomForestRegressor(RandomForestRegressor_Batch):
59
50
  __doc__ = RandomForestRegressor_Batch.__doc__
51
+ _onedal_factory = onedal_RandomForestRegressor
60
52
 
61
53
  def _onedal_cpu_supported(self, method_name, *data):
62
54
  # TODO:
@@ -15,5 +15,6 @@
15
15
  # ==============================================================================
16
16
 
17
17
  from .linear_model import LinearRegression
18
+ from .logistic_regression import LogisticRegression
18
19
 
19
- __all__ = ["LinearRegression"]
20
+ __all__ = ["LinearRegression", "LogisticRegression"]
@@ -0,0 +1,21 @@
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
+ from onedal.spmd.linear_model import LogisticRegression
18
+
19
+ # TODO:
20
+ # Currently it uses `onedal` module interface.
21
+ # Add sklearnex dispatching.
sklearnex/svm/_common.py CHANGED
@@ -76,7 +76,7 @@ class BaseSVM(ABC):
76
76
  inference_methods = (
77
77
  ["predict"]
78
78
  if class_name.endswith("R")
79
- else ["predict", "predict_proba", "decision_function"]
79
+ else ["predict", "predict_proba", "decision_function", "score"]
80
80
  )
81
81
  if method_name in inference_methods:
82
82
  patching_status.and_conditions(
@@ -111,12 +111,9 @@ class BaseSVC(BaseSVM):
111
111
  cv = StratifiedKFold(
112
112
  n_splits=n_splits, shuffle=True, random_state=self.random_state
113
113
  )
114
- if sklearn_check_version("0.24"):
115
- self.clf_prob = CalibratedClassifierCV(
116
- clf_base, ensemble=False, cv=cv, method="sigmoid", n_jobs=n_jobs
117
- )
118
- else:
119
- self.clf_prob = CalibratedClassifierCV(clf_base, cv=cv, method="sigmoid")
114
+ self.clf_prob = CalibratedClassifierCV(
115
+ clf_base, ensemble=False, cv=cv, method="sigmoid", n_jobs=n_jobs
116
+ )
120
117
  self.clf_prob.fit(X, y, sample_weight)
121
118
  except ValueError:
122
119
  clf_base = clf_base.fit(X, y, sample_weight)