scikit-learn-intelex 2024.2.0__py38-none-manylinux1_x86_64.whl → 2024.4.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 (50) hide show
  1. {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/METADATA +2 -2
  2. {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/RECORD +45 -45
  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 +3 -1
  9. sklearnex/conftest.py +63 -0
  10. sklearnex/decomposition/pca.py +319 -1
  11. sklearnex/decomposition/tests/test_pca.py +34 -5
  12. sklearnex/dispatcher.py +74 -43
  13. sklearnex/ensemble/_forest.py +78 -89
  14. sklearnex/ensemble/tests/test_forest.py +15 -19
  15. sklearnex/linear_model/linear.py +275 -340
  16. sklearnex/linear_model/logistic_regression.py +63 -11
  17. sklearnex/linear_model/tests/test_linear.py +40 -5
  18. sklearnex/linear_model/tests/test_logreg.py +0 -2
  19. sklearnex/neighbors/_lof.py +74 -20
  20. sklearnex/neighbors/common.py +4 -1
  21. sklearnex/neighbors/knn_classification.py +44 -131
  22. sklearnex/neighbors/knn_regression.py +16 -126
  23. sklearnex/neighbors/knn_unsupervised.py +11 -86
  24. sklearnex/neighbors/tests/test_neighbors.py +0 -5
  25. sklearnex/preview/__init__.py +1 -1
  26. sklearnex/preview/cluster/k_means.py +5 -73
  27. sklearnex/preview/covariance/covariance.py +6 -5
  28. sklearnex/preview/covariance/tests/test_covariance.py +18 -5
  29. sklearnex/spmd/ensemble/forest.py +4 -12
  30. sklearnex/svm/_common.py +4 -7
  31. sklearnex/svm/nusvc.py +70 -50
  32. sklearnex/svm/nusvr.py +6 -52
  33. sklearnex/svm/svc.py +70 -51
  34. sklearnex/svm/svr.py +3 -49
  35. sklearnex/tests/_utils.py +164 -0
  36. sklearnex/tests/test_memory_usage.py +8 -3
  37. sklearnex/tests/test_monkeypatch.py +177 -149
  38. sklearnex/tests/test_n_jobs_support.py +8 -2
  39. sklearnex/tests/test_parallel.py +6 -8
  40. sklearnex/tests/test_patching.py +322 -87
  41. sklearnex/utils/__init__.py +2 -1
  42. sklearnex/utils/_namespace.py +97 -0
  43. sklearnex/preview/decomposition/__init__.py +0 -19
  44. sklearnex/preview/decomposition/pca.py +0 -374
  45. sklearnex/preview/decomposition/tests/test_preview_pca.py +0 -42
  46. sklearnex/tests/_models_info.py +0 -170
  47. sklearnex/tests/utils/_launch_algorithms.py +0 -118
  48. {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/LICENSE.txt +0 -0
  49. {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/WHEEL +0 -0
  50. {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/top_level.txt +0 -0
@@ -14,133 +14,27 @@
14
14
  # limitations under the License.
15
15
  # ==============================================================================
16
16
 
17
- import warnings
18
-
19
- from sklearn.neighbors._ball_tree import BallTree
20
- from sklearn.neighbors._base import NeighborsBase as sklearn_NeighborsBase
21
- from sklearn.neighbors._kd_tree import KDTree
22
-
23
- from daal4py.sklearn._n_jobs_support import control_n_jobs
24
- from daal4py.sklearn._utils import sklearn_check_version
25
-
26
- if not sklearn_check_version("1.2"):
27
- from sklearn.neighbors._base import _check_weights
28
-
29
- import numpy as np
30
- from sklearn.neighbors._base import VALID_METRICS
31
17
  from sklearn.neighbors._regression import (
32
18
  KNeighborsRegressor as sklearn_KNeighborsRegressor,
33
19
  )
34
20
  from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestNeighbors
35
21
  from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted
36
22
 
23
+ from daal4py.sklearn._n_jobs_support import control_n_jobs
24
+ from daal4py.sklearn._utils import sklearn_check_version
37
25
  from onedal.neighbors import KNeighborsRegressor as onedal_KNeighborsRegressor
38
- from onedal.utils import _check_array, _num_features, _num_samples
39
26
 
40
27
  from .._device_offload import dispatch, wrap_output_data
41
28
  from .common import KNeighborsDispatchingBase
42
29
 
43
- if sklearn_check_version("0.24"):
44
-
45
- class KNeighborsRegressor_(sklearn_KNeighborsRegressor):
46
- if sklearn_check_version("1.2"):
47
- _parameter_constraints: dict = {
48
- **sklearn_KNeighborsRegressor._parameter_constraints
49
- }
50
-
51
- @_deprecate_positional_args
52
- def __init__(
53
- self,
54
- n_neighbors=5,
55
- *,
56
- weights="uniform",
57
- algorithm="auto",
58
- leaf_size=30,
59
- p=2,
60
- metric="minkowski",
61
- metric_params=None,
62
- n_jobs=None,
63
- **kwargs,
64
- ):
65
- super().__init__(
66
- n_neighbors=n_neighbors,
67
- algorithm=algorithm,
68
- leaf_size=leaf_size,
69
- metric=metric,
70
- p=p,
71
- metric_params=metric_params,
72
- n_jobs=n_jobs,
73
- **kwargs,
74
- )
75
- self.weights = (
76
- weights if sklearn_check_version("1.0") else _check_weights(weights)
77
- )
78
-
79
- elif sklearn_check_version("0.22"):
80
- from sklearn.neighbors._base import SupervisedFloatMixin as BaseSupervisedFloatMixin
81
-
82
- class KNeighborsRegressor_(sklearn_KNeighborsRegressor, BaseSupervisedFloatMixin):
83
- @_deprecate_positional_args
84
- def __init__(
85
- self,
86
- n_neighbors=5,
87
- *,
88
- weights="uniform",
89
- algorithm="auto",
90
- leaf_size=30,
91
- p=2,
92
- metric="minkowski",
93
- metric_params=None,
94
- n_jobs=None,
95
- **kwargs,
96
- ):
97
- super().__init__(
98
- n_neighbors=n_neighbors,
99
- algorithm=algorithm,
100
- leaf_size=leaf_size,
101
- metric=metric,
102
- p=p,
103
- metric_params=metric_params,
104
- n_jobs=n_jobs,
105
- **kwargs,
106
- )
107
- self.weights = _check_weights(weights)
108
-
109
- else:
110
- from sklearn.neighbors.base import SupervisedFloatMixin as BaseSupervisedFloatMixin
111
-
112
- class KNeighborsRegressor_(sklearn_KNeighborsRegressor, BaseSupervisedFloatMixin):
113
- @_deprecate_positional_args
114
- def __init__(
115
- self,
116
- n_neighbors=5,
117
- *,
118
- weights="uniform",
119
- algorithm="auto",
120
- leaf_size=30,
121
- p=2,
122
- metric="minkowski",
123
- metric_params=None,
124
- n_jobs=None,
125
- **kwargs,
126
- ):
127
- super().__init__(
128
- n_neighbors=n_neighbors,
129
- algorithm=algorithm,
130
- leaf_size=leaf_size,
131
- metric=metric,
132
- p=p,
133
- metric_params=metric_params,
134
- n_jobs=n_jobs,
135
- **kwargs,
136
- )
137
- self.weights = _check_weights(weights)
138
-
139
30
 
140
31
  @control_n_jobs(decorated_methods=["fit", "predict", "kneighbors"])
141
- class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
32
+ class KNeighborsRegressor(sklearn_KNeighborsRegressor, KNeighborsDispatchingBase):
33
+ __doc__ = sklearn_KNeighborsRegressor.__doc__
142
34
  if sklearn_check_version("1.2"):
143
- _parameter_constraints: dict = {**KNeighborsRegressor_._parameter_constraints}
35
+ _parameter_constraints: dict = {
36
+ **sklearn_KNeighborsRegressor._parameter_constraints
37
+ }
144
38
 
145
39
  if sklearn_check_version("1.0"):
146
40
 
@@ -196,7 +90,6 @@ class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
196
90
  )
197
91
 
198
92
  def fit(self, X, y):
199
- self._fit_validation(X, y)
200
93
  dispatch(
201
94
  self,
202
95
  "fit",
@@ -252,18 +145,10 @@ class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
252
145
  or getattr(self, "_tree", 0) is None
253
146
  and self._fit_method == "kd_tree"
254
147
  ):
255
- if sklearn_check_version("0.24"):
256
- sklearn_NearestNeighbors.fit(self, self._fit_X, getattr(self, "_y", None))
257
- else:
258
- sklearn_NearestNeighbors.fit(self, self._fit_X)
259
- if sklearn_check_version("0.22"):
260
- result = sklearn_NearestNeighbors.radius_neighbors(
261
- self, X, radius, return_distance, sort_results
262
- )
263
- else:
264
- result = sklearn_NearestNeighbors.radius_neighbors(
265
- self, X, radius, return_distance
266
- )
148
+ sklearn_NearestNeighbors.fit(self, self._fit_X, getattr(self, "_y", None))
149
+ result = sklearn_NearestNeighbors.radius_neighbors(
150
+ self, X, radius, return_distance, sort_results
151
+ )
267
152
 
268
153
  return result
269
154
 
@@ -306,3 +191,8 @@ class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
306
191
  self._y = self._onedal_estimator._y
307
192
  self._fit_method = self._onedal_estimator._fit_method
308
193
  self._tree = self._onedal_estimator._tree
194
+
195
+ fit.__doc__ = sklearn_KNeighborsRegressor.__doc__
196
+ predict.__doc__ = sklearn_KNeighborsRegressor.predict.__doc__
197
+ kneighbors.__doc__ = sklearn_KNeighborsRegressor.kneighbors.__doc__
198
+ radius_neighbors.__doc__ = sklearn_NearestNeighbors.radius_neighbors.__doc__
@@ -14,92 +14,22 @@
14
14
  # limitations under the License.
15
15
  # ===============================================================================
16
16
 
17
- try:
18
- from packaging.version import Version
19
- except ImportError:
20
- from distutils.version import LooseVersion as Version
21
-
22
- import warnings
23
-
24
- import numpy as np
25
- from sklearn import __version__ as sklearn_version
26
- from sklearn.neighbors._ball_tree import BallTree
27
- from sklearn.neighbors._base import VALID_METRICS
28
- from sklearn.neighbors._base import NeighborsBase as sklearn_NeighborsBase
29
- from sklearn.neighbors._kd_tree import KDTree
30
17
  from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestNeighbors
31
18
  from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted
32
19
 
33
20
  from daal4py.sklearn._n_jobs_support import control_n_jobs
34
21
  from daal4py.sklearn._utils import sklearn_check_version
35
22
  from onedal.neighbors import NearestNeighbors as onedal_NearestNeighbors
36
- from onedal.utils import _check_array, _num_features, _num_samples
37
23
 
38
24
  from .._device_offload import dispatch, wrap_output_data
39
25
  from .common import KNeighborsDispatchingBase
40
26
 
41
- if sklearn_check_version("0.22") and Version(sklearn_version) < Version("0.23"):
42
-
43
- class NearestNeighbors_(sklearn_NearestNeighbors):
44
- def __init__(
45
- self,
46
- n_neighbors=5,
47
- radius=1.0,
48
- algorithm="auto",
49
- leaf_size=30,
50
- metric="minkowski",
51
- p=2,
52
- metric_params=None,
53
- n_jobs=None,
54
- ):
55
- super().__init__(
56
- n_neighbors=n_neighbors,
57
- radius=radius,
58
- algorithm=algorithm,
59
- leaf_size=leaf_size,
60
- metric=metric,
61
- p=p,
62
- metric_params=metric_params,
63
- n_jobs=n_jobs,
64
- )
65
-
66
- else:
67
-
68
- class NearestNeighbors_(sklearn_NearestNeighbors):
69
- if sklearn_check_version("1.2"):
70
- _parameter_constraints: dict = {
71
- **sklearn_NearestNeighbors._parameter_constraints
72
- }
73
-
74
- @_deprecate_positional_args
75
- def __init__(
76
- self,
77
- *,
78
- n_neighbors=5,
79
- radius=1.0,
80
- algorithm="auto",
81
- leaf_size=30,
82
- metric="minkowski",
83
- p=2,
84
- metric_params=None,
85
- n_jobs=None,
86
- ):
87
- super().__init__(
88
- n_neighbors=n_neighbors,
89
- radius=radius,
90
- algorithm=algorithm,
91
- leaf_size=leaf_size,
92
- metric=metric,
93
- p=p,
94
- metric_params=metric_params,
95
- n_jobs=n_jobs,
96
- )
97
-
98
27
 
99
28
  @control_n_jobs(decorated_methods=["fit", "kneighbors"])
100
- class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
29
+ class NearestNeighbors(sklearn_NearestNeighbors, KNeighborsDispatchingBase):
30
+ __doc__ = sklearn_NearestNeighbors.__doc__
101
31
  if sklearn_check_version("1.2"):
102
- _parameter_constraints: dict = {**NearestNeighbors_._parameter_constraints}
32
+ _parameter_constraints: dict = {**sklearn_NearestNeighbors._parameter_constraints}
103
33
 
104
34
  @_deprecate_positional_args
105
35
  def __init__(
@@ -125,7 +55,6 @@ class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
125
55
  )
126
56
 
127
57
  def fit(self, X, y=None):
128
- self._fit_validation(X, y)
129
58
  dispatch(
130
59
  self,
131
60
  "fit",
@@ -166,18 +95,10 @@ class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
166
95
  or getattr(self, "_tree", 0) is None
167
96
  and self._fit_method == "kd_tree"
168
97
  ):
169
- if sklearn_check_version("0.24"):
170
- sklearn_NearestNeighbors.fit(self, self._fit_X, getattr(self, "_y", None))
171
- else:
172
- sklearn_NearestNeighbors.fit(self, self._fit_X)
173
- if sklearn_check_version("0.22"):
174
- result = sklearn_NearestNeighbors.radius_neighbors(
175
- self, X, radius, return_distance, sort_results
176
- )
177
- else:
178
- result = sklearn_NearestNeighbors.radius_neighbors(
179
- self, X, radius, return_distance
180
- )
98
+ sklearn_NearestNeighbors.fit(self, self._fit_X, getattr(self, "_y", None))
99
+ result = sklearn_NearestNeighbors.radius_neighbors(
100
+ self, X, radius, return_distance, sort_results
101
+ )
181
102
 
182
103
  return result
183
104
 
@@ -219,3 +140,7 @@ class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
219
140
  self._fit_X = self._onedal_estimator._fit_X
220
141
  self._fit_method = self._onedal_estimator._fit_method
221
142
  self._tree = self._onedal_estimator._tree
143
+
144
+ fit.__doc__ = sklearn_NearestNeighbors.__doc__
145
+ kneighbors.__doc__ = sklearn_NearestNeighbors.kneighbors.__doc__
146
+ radius_neighbors.__doc__ = sklearn_NearestNeighbors.radius_neighbors.__doc__
@@ -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
 
@@ -33,7 +32,6 @@ from sklearnex.neighbors import (
33
32
 
34
33
  @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
35
34
  def test_sklearnex_import_knn_classifier(dataframe, queue):
36
-
37
35
  X = _convert_to_dataframe([[0], [1], [2], [3]], sycl_queue=queue, target_df=dataframe)
38
36
  y = _convert_to_dataframe([0, 0, 1, 1], sycl_queue=queue, target_df=dataframe)
39
37
  neigh = KNeighborsClassifier(n_neighbors=3).fit(X, y)
@@ -45,7 +43,6 @@ def test_sklearnex_import_knn_classifier(dataframe, queue):
45
43
 
46
44
  @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
47
45
  def test_sklearnex_import_knn_regression(dataframe, queue):
48
-
49
46
  X = _convert_to_dataframe([[0], [1], [2], [3]], sycl_queue=queue, target_df=dataframe)
50
47
  y = _convert_to_dataframe([0, 0, 1, 1], sycl_queue=queue, target_df=dataframe)
51
48
  neigh = KNeighborsRegressor(n_neighbors=2).fit(X, y)
@@ -61,7 +58,6 @@ def test_sklearnex_import_knn_regression(dataframe, queue):
61
58
  [LocalOutlierFactor, NearestNeighbors],
62
59
  )
63
60
  def test_sklearnex_kneighbors(estimator, dataframe, queue):
64
-
65
61
  X = [[0, 0, 2], [1, 0, 0], [0, 0, 1]]
66
62
  X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
67
63
  test = _convert_to_dataframe([[0, 0, 1.3]], sycl_queue=queue, target_df=dataframe)
@@ -74,7 +70,6 @@ def test_sklearnex_kneighbors(estimator, dataframe, queue):
74
70
 
75
71
  @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
76
72
  def test_sklearnex_import_lof(dataframe, queue):
77
-
78
73
  X = [[7, 7, 7], [1, 0, 0], [0, 0, 1], [0, 0, 1]]
79
74
  X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
80
75
  lof = LocalOutlierFactor(n_neighbors=2)
@@ -14,4 +14,4 @@
14
14
  # limitations under the License.
15
15
  # ==============================================================================
16
16
 
17
- __all__ = ["cluster", "covariance", "decomposition"]
17
+ __all__ = ["cluster", "covariance"]
@@ -172,24 +172,6 @@ if daal_check_version((2023, "P", 200)):
172
172
  return patching_status
173
173
 
174
174
  def fit(self, X, y=None, sample_weight=None):
175
- """Compute k-means clustering.
176
-
177
- Parameters
178
- ----------
179
- X : array-like or sparse matrix, shape=(n_samples, n_features)
180
- Training instances to cluster. It must be noted that the data
181
- will be converted to C ordering, which will cause a memory
182
- copy if the given data is not C-contiguous.
183
-
184
- y : Ignored
185
- not used, present here for API consistency by convention.
186
-
187
- sample_weight : array-like, shape (n_samples,), optional
188
- The weights for each observation in X. If None, all observations
189
- are assigned equal weight (default: None)
190
-
191
- """
192
-
193
175
  if sklearn_check_version("1.0"):
194
176
  self._check_feature_names(X, reset=True)
195
177
  if sklearn_check_version("1.2"):
@@ -257,24 +239,6 @@ if daal_check_version((2023, "P", 200)):
257
239
 
258
240
  @wrap_output_data
259
241
  def predict(self, X):
260
- """Compute k-means clustering.
261
-
262
- Parameters
263
- ----------
264
- X : array-like or sparse matrix, shape=(n_samples, n_features)
265
- Training instances to cluster. It must be noted that the data
266
- will be converted to C ordering, which will cause a memory
267
- copy if the given data is not C-contiguous.
268
-
269
- y : Ignored
270
- not used, present here for API consistency by convention.
271
-
272
- sample_weight : array-like, shape (n_samples,), optional
273
- The weights for each observation in X. If None, all observations
274
- are assigned equal weight (default: None)
275
-
276
- """
277
-
278
242
  if sklearn_check_version("1.0"):
279
243
  self._check_feature_names(X, reset=True)
280
244
  if sklearn_check_version("1.2"):
@@ -317,52 +281,20 @@ if daal_check_version((2023, "P", 200)):
317
281
 
318
282
  @wrap_output_data
319
283
  def fit_transform(self, X, y=None, sample_weight=None):
320
- """Compute clustering and transform X to cluster-distance space.
321
-
322
- Equivalent to fit(X).transform(X), but more efficiently implemented.
323
-
324
- Parameters
325
- ----------
326
- X : {array-like, sparse matrix} of shape (n_samples, n_features)
327
- New data to transform.
328
-
329
- y : Ignored
330
- Not used, present here for API consistency by convention.
331
-
332
- sample_weight : array-like of shape (n_samples,), default=None
333
- The weights for each observation in X. If None, all observations
334
- are assigned equal weight.
335
-
336
- Returns
337
- -------
338
- X_new : ndarray of shape (n_samples, n_clusters)
339
- X transformed in the new space.
340
- """
341
284
  return self.fit(X, sample_weight=sample_weight)._transform(X)
342
285
 
343
286
  @wrap_output_data
344
287
  def transform(self, X):
345
- """Transform X to a cluster-distance space.
346
-
347
- In the new space, each dimension is the distance to the cluster
348
- centers. Note that even if X is sparse, the array returned by
349
- `transform` will typically be dense.
350
-
351
- Parameters
352
- ----------
353
- X : {array-like, sparse matrix} of shape (n_samples, n_features)
354
- New data to transform.
355
-
356
- Returns
357
- -------
358
- X_new : ndarray of shape (n_samples, n_clusters)
359
- X transformed in the new space.
360
- """
361
288
  check_is_fitted(self)
362
289
 
363
290
  X = self._check_test_data(X)
364
291
  return self._transform(X)
365
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
+
366
298
  else:
367
299
  from daal4py.sklearn.cluster import KMeans
368
300
 
@@ -22,7 +22,7 @@ from sklearn.covariance import EmpiricalCovariance as sklearn_EmpiricalCovarianc
22
22
  from sklearn.utils import check_array
23
23
 
24
24
  from daal4py.sklearn._n_jobs_support import control_n_jobs
25
- from daal4py.sklearn._utils import sklearn_check_version
25
+ from daal4py.sklearn._utils import daal_check_version, sklearn_check_version
26
26
  from onedal.common.hyperparameters import get_hyperparameters
27
27
  from onedal.covariance import EmpiricalCovariance as onedal_EmpiricalCovariance
28
28
  from sklearnex import config_context
@@ -44,6 +44,10 @@ class EmpiricalCovariance(sklearn_EmpiricalCovariance):
44
44
 
45
45
  def _save_attributes(self):
46
46
  assert hasattr(self, "_onedal_estimator")
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))
47
51
  self._set_covariance(self._onedal_estimator.covariance_)
48
52
  self.location_ = self._onedal_estimator.location_
49
53
 
@@ -58,6 +62,7 @@ class EmpiricalCovariance(sklearn_EmpiricalCovariance):
58
62
  onedal_params = {
59
63
  "method": "dense",
60
64
  "bias": True,
65
+ "assume_centered": self.assume_centered,
61
66
  }
62
67
 
63
68
  self._onedal_estimator = self._onedal_covariance(**onedal_params)
@@ -73,10 +78,6 @@ class EmpiricalCovariance(sklearn_EmpiricalCovariance):
73
78
  (X,) = data
74
79
  patching_status.and_conditions(
75
80
  [
76
- (
77
- self.assume_centered == False,
78
- "assume_centered parameter is not supported on oneDAL side",
79
- ),
80
81
  (not sp.issparse(X), "X is sparse. Sparse input is not supported."),
81
82
  ]
82
83
  )
@@ -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_)
@@ -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:
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)