scikit-learn-intelex 2024.5.0__py311-none-manylinux1_x86_64.whl → 2024.7.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 (73) hide show
  1. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/METADATA +2 -2
  2. scikit_learn_intelex-2024.7.0.dist-info/RECORD +122 -0
  3. sklearnex/_config.py +3 -15
  4. sklearnex/_device_offload.py +9 -168
  5. sklearnex/basic_statistics/basic_statistics.py +127 -1
  6. sklearnex/basic_statistics/tests/test_basic_statistics.py +251 -0
  7. sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +1 -1
  8. sklearnex/cluster/dbscan.py +3 -1
  9. sklearnex/cluster/k_means.py +8 -0
  10. sklearnex/cluster/tests/test_dbscan.py +8 -6
  11. sklearnex/cluster/tests/test_kmeans.py +15 -3
  12. sklearnex/conftest.py +11 -1
  13. sklearnex/covariance/incremental_covariance.py +64 -13
  14. sklearnex/covariance/tests/test_incremental_covariance.py +35 -0
  15. sklearnex/decomposition/pca.py +25 -1
  16. sklearnex/decomposition/tests/test_pca.py +4 -2
  17. sklearnex/dispatcher.py +109 -1
  18. sklearnex/ensemble/_forest.py +121 -57
  19. sklearnex/ensemble/tests/test_forest.py +7 -0
  20. sklearnex/glob/dispatcher.py +16 -2
  21. sklearnex/linear_model/coordinate_descent.py +13 -0
  22. sklearnex/linear_model/incremental_linear.py +102 -25
  23. sklearnex/linear_model/linear.py +25 -39
  24. sklearnex/linear_model/logistic_regression.py +92 -74
  25. sklearnex/linear_model/ridge.py +7 -0
  26. sklearnex/linear_model/tests/test_incremental_linear.py +10 -10
  27. sklearnex/linear_model/tests/test_linear.py +30 -5
  28. sklearnex/linear_model/tests/test_logreg.py +45 -3
  29. sklearnex/manifold/t_sne.py +4 -0
  30. sklearnex/metrics/pairwise.py +5 -0
  31. sklearnex/metrics/ranking.py +3 -0
  32. sklearnex/model_selection/split.py +3 -0
  33. sklearnex/neighbors/_lof.py +9 -0
  34. sklearnex/neighbors/common.py +45 -1
  35. sklearnex/neighbors/knn_classification.py +1 -20
  36. sklearnex/neighbors/knn_regression.py +25 -20
  37. sklearnex/neighbors/knn_unsupervised.py +31 -7
  38. sklearnex/preview/__init__.py +1 -1
  39. sklearnex/preview/decomposition/__init__.py +19 -0
  40. sklearnex/preview/decomposition/incremental_pca.py +228 -0
  41. sklearnex/preview/decomposition/tests/test_incremental_pca.py +266 -0
  42. sklearnex/preview/linear_model/__init__.py +19 -0
  43. sklearnex/preview/linear_model/ridge.py +419 -0
  44. sklearnex/preview/linear_model/tests/test_ridge.py +102 -0
  45. sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py +107 -0
  46. sklearnex/spmd/cluster/tests/test_dbscan_spmd.py +97 -0
  47. sklearnex/spmd/cluster/tests/test_kmeans_spmd.py +172 -0
  48. sklearnex/spmd/covariance/tests/test_covariance_spmd.py +107 -0
  49. sklearnex/spmd/decomposition/tests/test_pca_spmd.py +128 -0
  50. sklearnex/spmd/ensemble/tests/test_forest_spmd.py +265 -0
  51. sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py +145 -0
  52. sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py +163 -0
  53. sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py +288 -0
  54. sklearnex/svm/_common.py +163 -20
  55. sklearnex/svm/nusvc.py +40 -4
  56. sklearnex/svm/nusvr.py +31 -2
  57. sklearnex/svm/svc.py +40 -4
  58. sklearnex/svm/svr.py +31 -2
  59. sklearnex/svm/tests/test_svm.py +12 -20
  60. sklearnex/tests/_utils.py +185 -30
  61. sklearnex/tests/_utils_spmd.py +185 -0
  62. sklearnex/tests/test_common.py +54 -0
  63. sklearnex/tests/test_config.py +4 -0
  64. sklearnex/tests/test_memory_usage.py +185 -126
  65. sklearnex/tests/test_monkeypatch.py +12 -4
  66. sklearnex/tests/test_patching.py +21 -25
  67. sklearnex/tests/test_run_to_run_stability.py +295 -0
  68. sklearnex/utils/_namespace.py +1 -1
  69. scikit_learn_intelex-2024.5.0.dist-info/RECORD +0 -104
  70. sklearnex/tests/test_run_to_run_stability_tests.py +0 -428
  71. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/LICENSE.txt +0 -0
  72. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/WHEEL +0 -0
  73. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/top_level.txt +0 -0
@@ -47,7 +47,7 @@ def test_sklearnex_fit_on_gold_data(dataframe, queue, fit_intercept, macro_block
47
47
 
48
48
  y_pred = inclin.predict(X_df)
49
49
 
50
- tol = 2e-6 if dtype == np.float32 else 1e-7
50
+ tol = 2e-6 if y_pred.dtype == np.float32 else 1e-7
51
51
  assert_allclose(inclin.coef_, [1], atol=tol)
52
52
  if fit_intercept:
53
53
  assert_allclose(inclin.intercept_, [0], atol=tol)
@@ -82,15 +82,15 @@ def test_sklearnex_partial_fit_on_gold_data(
82
82
  )
83
83
  inclin.partial_fit(X_split_df, y_split_df)
84
84
 
85
+ X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
86
+ y_pred = inclin.predict(X_df)
87
+
85
88
  assert inclin.n_features_in_ == 1
86
- tol = 2e-6 if dtype == np.float32 else 1e-7
89
+ tol = 2e-6 if y_pred.dtype == np.float32 else 1e-7
87
90
  assert_allclose(inclin.coef_, [[1]], atol=tol)
88
91
  if fit_intercept:
89
92
  assert_allclose(inclin.intercept_, 3, atol=tol)
90
93
 
91
- X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
92
- y_pred = inclin.predict(X_df)
93
-
94
94
  assert_allclose(_as_numpy(y_pred), y, atol=tol)
95
95
 
96
96
 
@@ -122,15 +122,15 @@ def test_sklearnex_partial_fit_multitarget_on_gold_data(
122
122
  )
123
123
  inclin.partial_fit(X_split_df, y_split_df)
124
124
 
125
+ X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
126
+ y_pred = inclin.predict(X_df)
127
+
125
128
  assert inclin.n_features_in_ == 2
126
- tol = 7e-6 if dtype == np.float32 else 1e-7
129
+ tol = 7e-6 if y_pred.dtype == np.float32 else 1e-7
127
130
  assert_allclose(inclin.coef_, [1.0, 2.0], atol=tol)
128
131
  if fit_intercept:
129
132
  assert_allclose(inclin.intercept_, 3.0, atol=tol)
130
133
 
131
- X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
132
- y_pred = inclin.predict(X_df)
133
-
134
134
  assert_allclose(_as_numpy(y_pred), y, atol=tol)
135
135
 
136
136
 
@@ -181,7 +181,7 @@ def test_sklearnex_partial_fit_on_random_data(
181
181
  )
182
182
  inclin.partial_fit(X_split_df, y_split_df)
183
183
 
184
- tol = 1e-4 if dtype == np.float32 else 1e-7
184
+ tol = 1e-4 if inclin.coef_.dtype == np.float32 else 1e-7
185
185
  assert_allclose(coef, inclin.coef_.T, atol=tol)
186
186
 
187
187
  if fit_intercept:
@@ -20,6 +20,10 @@ from numpy.testing import assert_allclose
20
20
  from sklearn.datasets import make_regression
21
21
 
22
22
  from daal4py.sklearn._utils import daal_check_version
23
+ from daal4py.sklearn.linear_model.tests.test_ridge import (
24
+ _test_multivariate_ridge_alpha_shape,
25
+ _test_multivariate_ridge_coefficients,
26
+ )
23
27
  from onedal.tests.utils._dataframes_support import (
24
28
  _as_numpy,
25
29
  _convert_to_dataframe,
@@ -52,37 +56,46 @@ def test_sklearnex_import_linear(dataframe, queue, dtype, macro_block):
52
56
  assert "sklearnex" in linreg.__module__
53
57
  assert linreg.n_features_in_ == 2
54
58
 
55
- tol = 1e-5 if dtype == np.float32 else 1e-7
59
+ tol = 1e-5 if _as_numpy(linreg.coef_).dtype == np.float32 else 1e-7
56
60
  assert_allclose(_as_numpy(linreg.intercept_), 3.0, rtol=tol)
57
61
  assert_allclose(_as_numpy(linreg.coef_), [1.0, 2.0], rtol=tol)
58
62
 
59
63
 
60
- def test_sklearnex_import_ridge():
64
+ @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
65
+ def test_sklearnex_import_ridge(dataframe, queue):
61
66
  from sklearnex.linear_model import Ridge
62
67
 
63
68
  X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
64
69
  y = np.dot(X, np.array([1, 2])) + 3
70
+ X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
71
+ y = _convert_to_dataframe(y, sycl_queue=queue, target_df=dataframe)
65
72
  ridgereg = Ridge().fit(X, y)
66
73
  assert "daal4py" in ridgereg.__module__
67
74
  assert_allclose(ridgereg.intercept_, 4.5)
68
75
  assert_allclose(ridgereg.coef_, [0.8, 1.4])
69
76
 
70
77
 
71
- def test_sklearnex_import_lasso():
78
+ @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
79
+ def test_sklearnex_import_lasso(dataframe, queue):
72
80
  from sklearnex.linear_model import Lasso
73
81
 
74
82
  X = [[0, 0], [1, 1], [2, 2]]
75
83
  y = [0, 1, 2]
84
+ X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
85
+ y = _convert_to_dataframe(y, sycl_queue=queue, target_df=dataframe)
76
86
  lasso = Lasso(alpha=0.1).fit(X, y)
77
87
  assert "daal4py" in lasso.__module__
78
88
  assert_allclose(lasso.intercept_, 0.15)
79
89
  assert_allclose(lasso.coef_, [0.85, 0.0])
80
90
 
81
91
 
82
- def test_sklearnex_import_elastic():
92
+ @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
93
+ def test_sklearnex_import_elastic(dataframe, queue):
83
94
  from sklearnex.linear_model import ElasticNet
84
95
 
85
96
  X, y = make_regression(n_features=2, random_state=0)
97
+ X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
98
+ y = _convert_to_dataframe(y, sycl_queue=queue, target_df=dataframe)
86
99
  elasticnet = ElasticNet(random_state=0).fit(X, y)
87
100
  assert "daal4py" in elasticnet.__module__
88
101
  assert_allclose(elasticnet.intercept_, 1.451, atol=1e-3)
@@ -113,5 +126,17 @@ def test_sklearnex_reconstruct_model(dataframe, queue, dtype):
113
126
 
114
127
  y_pred = linreg.predict(X)
115
128
 
116
- tol = 1e-5 if dtype == np.float32 else 1e-7
129
+ tol = 1e-5 if _as_numpy(y_pred).dtype == np.float32 else 1e-7
117
130
  assert_allclose(gtr, _as_numpy(y_pred), rtol=tol)
131
+
132
+
133
+ def test_sklearnex_multivariate_ridge_coefs():
134
+ from sklearnex.linear_model import Ridge
135
+
136
+ _test_multivariate_ridge_coefficients(Ridge, random_state=0)
137
+
138
+
139
+ def test_sklearnex_multivariate_ridge_alpha_shape():
140
+ from sklearnex.linear_model import Ridge
141
+
142
+ _test_multivariate_ridge_alpha_shape(Ridge, random_state=0)
@@ -14,8 +14,11 @@
14
14
  # limitations under the License.
15
15
  # ===============================================================================
16
16
 
17
+ import numpy as np
17
18
  import pytest
18
- from sklearn.datasets import load_breast_cancer, load_iris
19
+ from numpy.testing import assert_allclose, assert_array_equal
20
+ from scipy.sparse import csr_matrix
21
+ from sklearn.datasets import load_breast_cancer, load_iris, make_classification
19
22
  from sklearn.metrics import accuracy_score
20
23
  from sklearn.model_selection import train_test_split
21
24
 
@@ -24,7 +27,9 @@ from onedal.tests.utils._dataframes_support import (
24
27
  _as_numpy,
25
28
  _convert_to_dataframe,
26
29
  get_dataframes_and_queues,
30
+ get_queues,
27
31
  )
32
+ from sklearnex import config_context
28
33
 
29
34
 
30
35
  def prepare_input(X, y, dataframe, queue):
@@ -38,8 +43,7 @@ def prepare_input(X, y, dataframe, queue):
38
43
 
39
44
 
40
45
  @pytest.mark.parametrize(
41
- "dataframe,queue",
42
- get_dataframes_and_queues(device_filter_="cpu"),
46
+ "dataframe,queue", get_dataframes_and_queues(device_filter_="cpu")
43
47
  )
44
48
  def test_sklearnex_multiclass_classification(dataframe, queue):
45
49
  from sklearnex.linear_model import LogisticRegression
@@ -89,3 +93,41 @@ def test_sklearnex_binary_classification(dataframe, queue):
89
93
 
90
94
  y_pred = _as_numpy(logreg.predict(X_test))
91
95
  assert accuracy_score(y_test, y_pred) > 0.95
96
+
97
+
98
+ if daal_check_version((2024, "P", 700)):
99
+
100
+ @pytest.mark.parametrize("queue", get_queues("gpu"))
101
+ @pytest.mark.parametrize("dtype", [np.float32, np.float64])
102
+ @pytest.mark.parametrize(
103
+ "dims", [(3007, 17, 0.05), (50000, 100, 0.01), (512, 10, 0.5)]
104
+ )
105
+ def test_csr(queue, dtype, dims):
106
+ from sklearnex.linear_model import LogisticRegression
107
+
108
+ n, p, density = dims
109
+
110
+ # Create sparse dataset for classification
111
+ X, y = make_classification(n, p, random_state=42)
112
+ X = X.astype(dtype)
113
+ y = y.astype(dtype)
114
+ np.random.seed(2007 + n + p)
115
+ mask = np.random.binomial(1, density, (n, p))
116
+ X = X * mask
117
+ X_sp = csr_matrix(X)
118
+
119
+ model = LogisticRegression(fit_intercept=True, solver="newton-cg")
120
+ model_sp = LogisticRegression(fit_intercept=True, solver="newton-cg")
121
+
122
+ with config_context(target_offload="gpu:0"):
123
+ model.fit(X, y)
124
+ pred = model.predict(X)
125
+ prob = model.predict_proba(X)
126
+ model_sp.fit(X_sp, y)
127
+ pred_sp = model_sp.predict(X_sp)
128
+ prob_sp = model_sp.predict_proba(X_sp)
129
+
130
+ assert_allclose(pred, pred_sp)
131
+ assert_allclose(prob, prob_sp)
132
+ assert_allclose(model.coef_, model_sp.coef_, rtol=1e-4)
133
+ assert_allclose(model.intercept_, model_sp.intercept_, rtol=1e-4)
@@ -15,3 +15,7 @@
15
15
  # ===============================================================================
16
16
 
17
17
  from daal4py.sklearn.manifold import TSNE
18
+ from onedal._device_offload import support_usm_ndarray
19
+
20
+ TSNE.fit = support_usm_ndarray(queue_param=False)(TSNE.fit)
21
+ TSNE.fit_transform = support_usm_ndarray(queue_param=False)(TSNE.fit_transform)
@@ -15,3 +15,8 @@
15
15
  # ===============================================================================
16
16
 
17
17
  from daal4py.sklearn.metrics import pairwise_distances
18
+ from onedal._device_offload import support_usm_ndarray
19
+
20
+ pairwise_distances = support_usm_ndarray(freefunc=True, queue_param=False)(
21
+ pairwise_distances
22
+ )
@@ -15,3 +15,6 @@
15
15
  # ===============================================================================
16
16
 
17
17
  from daal4py.sklearn.metrics import roc_auc_score
18
+ from onedal._device_offload import support_usm_ndarray
19
+
20
+ roc_auc_score = support_usm_ndarray(freefunc=True, queue_param=False)(roc_auc_score)
@@ -15,3 +15,6 @@
15
15
  # ===============================================================================
16
16
 
17
17
  from daal4py.sklearn.model_selection import train_test_split
18
+ from onedal._device_offload import support_usm_ndarray
19
+
20
+ train_test_split = support_usm_ndarray(freefunc=True, queue_param=False)(train_test_split)
@@ -97,6 +97,15 @@ class LocalOutlierFactor(KNeighborsDispatchingBase, sklearn_LocalOutlierFactor):
97
97
  self.negative_outlier_factor_, 100.0 * self.contamination
98
98
  )
99
99
 
100
+ # adoption of warning for data with duplicated samples from
101
+ # https://github.com/scikit-learn/scikit-learn/pull/28773
102
+ if sklearn_check_version("1.6"):
103
+ if np.min(self.negative_outlier_factor_) < -1e7 and not self.novelty:
104
+ warnings.warn(
105
+ "Duplicate values are leading to incorrect results. "
106
+ "Increase the number of neighbors for more accurate results."
107
+ )
108
+
100
109
  return self
101
110
 
102
111
  def fit(self, X, y=None):
@@ -19,14 +19,16 @@ import warnings
19
19
  import numpy as np
20
20
  from scipy import sparse as sp
21
21
  from sklearn.neighbors._ball_tree import BallTree
22
- from sklearn.neighbors._base import VALID_METRICS
22
+ from sklearn.neighbors._base import VALID_METRICS, KNeighborsMixin
23
23
  from sklearn.neighbors._base import NeighborsBase as sklearn_NeighborsBase
24
24
  from sklearn.neighbors._kd_tree import KDTree
25
+ from sklearn.utils.validation import check_is_fitted
25
26
 
26
27
  from daal4py.sklearn._utils import sklearn_check_version
27
28
  from onedal.utils import _check_array, _num_features, _num_samples
28
29
 
29
30
  from .._utils import PatchingConditionsChain
31
+ from ..utils import get_namespace
30
32
 
31
33
 
32
34
  class KNeighborsDispatchingBase:
@@ -147,6 +149,10 @@ class KNeighborsDispatchingBase:
147
149
  patching_status = PatchingConditionsChain(
148
150
  f"sklearn.neighbors.{class_name}.{method_name}"
149
151
  )
152
+ if not patching_status.and_condition(
153
+ "radius" not in method_name, "RadiusNeighbors not implemented in sklearnex"
154
+ ):
155
+ return patching_status
150
156
 
151
157
  if not patching_status.and_condition(
152
158
  not isinstance(data[0], (KDTree, BallTree, sklearn_NeighborsBase)),
@@ -264,3 +270,41 @@ class KNeighborsDispatchingBase:
264
270
 
265
271
  def _onedal_cpu_supported(self, method_name, *data):
266
272
  return self._onedal_supported("cpu", method_name, *data)
273
+
274
+ def kneighbors_graph(self, X=None, n_neighbors=None, mode="connectivity"):
275
+ check_is_fitted(self)
276
+ if n_neighbors is None:
277
+ n_neighbors = self.n_neighbors
278
+
279
+ # check the input only in self.kneighbors
280
+
281
+ # construct CSR matrix representation of the k-NN graph
282
+ if mode == "connectivity":
283
+ A_ind = self.kneighbors(X, n_neighbors, return_distance=False)
284
+ xp, _ = get_namespace(A_ind)
285
+ n_queries = A_ind.shape[0]
286
+ A_data = xp.ones(n_queries * n_neighbors)
287
+
288
+ elif mode == "distance":
289
+ A_data, A_ind = self.kneighbors(X, n_neighbors, return_distance=True)
290
+ xp, _ = get_namespace(A_ind)
291
+ A_data = xp.reshape(A_data, (-1,))
292
+
293
+ else:
294
+ raise ValueError(
295
+ 'Unsupported mode, must be one of "connectivity", '
296
+ f'or "distance" but got "{mode}" instead'
297
+ )
298
+
299
+ n_queries = A_ind.shape[0]
300
+ n_samples_fit = self.n_samples_fit_
301
+ n_nonzero = n_queries * n_neighbors
302
+ A_indptr = xp.arange(0, n_nonzero + 1, n_neighbors)
303
+
304
+ kneighbors_graph = sp.csr_matrix(
305
+ (A_data, xp.reshape(A_ind, (-1,)), A_indptr), shape=(n_queries, n_samples_fit)
306
+ )
307
+
308
+ return kneighbors_graph
309
+
310
+ kneighbors_graph.__doc__ = KNeighborsMixin.kneighbors_graph.__doc__
@@ -32,7 +32,7 @@ from .common import KNeighborsDispatchingBase
32
32
  @control_n_jobs(
33
33
  decorated_methods=["fit", "predict", "predict_proba", "kneighbors", "score"]
34
34
  )
35
- class KNeighborsClassifier(sklearn_KNeighborsClassifier, KNeighborsDispatchingBase):
35
+ class KNeighborsClassifier(KNeighborsDispatchingBase, sklearn_KNeighborsClassifier):
36
36
  __doc__ = sklearn_KNeighborsClassifier.__doc__
37
37
  if sklearn_check_version("1.2"):
38
38
  _parameter_constraints: dict = {
@@ -169,24 +169,6 @@ class KNeighborsClassifier(sklearn_KNeighborsClassifier, KNeighborsDispatchingBa
169
169
  return_distance=return_distance,
170
170
  )
171
171
 
172
- @wrap_output_data
173
- def radius_neighbors(
174
- self, X=None, radius=None, return_distance=True, sort_results=False
175
- ):
176
- _onedal_estimator = getattr(self, "_onedal_estimator", None)
177
-
178
- if (
179
- _onedal_estimator is not None
180
- or getattr(self, "_tree", 0) is None
181
- and self._fit_method == "kd_tree"
182
- ):
183
- sklearn_NearestNeighbors.fit(self, self._fit_X, getattr(self, "_y", None))
184
- result = sklearn_NearestNeighbors.radius_neighbors(
185
- self, X, radius, return_distance, sort_results
186
- )
187
-
188
- return result
189
-
190
172
  def _onedal_fit(self, X, y, queue=None):
191
173
  onedal_params = {
192
174
  "n_neighbors": self.n_neighbors,
@@ -242,4 +224,3 @@ class KNeighborsClassifier(sklearn_KNeighborsClassifier, KNeighborsDispatchingBa
242
224
  predict_proba.__doc__ = sklearn_KNeighborsClassifier.predict_proba.__doc__
243
225
  score.__doc__ = sklearn_KNeighborsClassifier.score.__doc__
244
226
  kneighbors.__doc__ = sklearn_KNeighborsClassifier.kneighbors.__doc__
245
- radius_neighbors.__doc__ = sklearn_NearestNeighbors.radius_neighbors.__doc__
@@ -14,6 +14,7 @@
14
14
  # limitations under the License.
15
15
  # ==============================================================================
16
16
 
17
+ from sklearn.metrics import r2_score
17
18
  from sklearn.neighbors._regression import (
18
19
  KNeighborsRegressor as sklearn_KNeighborsRegressor,
19
20
  )
@@ -29,7 +30,7 @@ from .common import KNeighborsDispatchingBase
29
30
 
30
31
 
31
32
  @control_n_jobs(decorated_methods=["fit", "predict", "kneighbors"])
32
- class KNeighborsRegressor(sklearn_KNeighborsRegressor, KNeighborsDispatchingBase):
33
+ class KNeighborsRegressor(KNeighborsDispatchingBase, sklearn_KNeighborsRegressor):
33
34
  __doc__ = sklearn_KNeighborsRegressor.__doc__
34
35
  if sklearn_check_version("1.2"):
35
36
  _parameter_constraints: dict = {
@@ -117,6 +118,23 @@ class KNeighborsRegressor(sklearn_KNeighborsRegressor, KNeighborsDispatchingBase
117
118
  X,
118
119
  )
119
120
 
121
+ @wrap_output_data
122
+ def score(self, X, y, sample_weight=None):
123
+ check_is_fitted(self)
124
+ if sklearn_check_version("1.0"):
125
+ self._check_feature_names(X, reset=False)
126
+ return dispatch(
127
+ self,
128
+ "score",
129
+ {
130
+ "onedal": self.__class__._onedal_score,
131
+ "sklearn": sklearn_KNeighborsRegressor.score,
132
+ },
133
+ X,
134
+ y,
135
+ sample_weight=sample_weight,
136
+ )
137
+
120
138
  @wrap_output_data
121
139
  def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
122
140
  check_is_fitted(self)
@@ -134,24 +152,6 @@ class KNeighborsRegressor(sklearn_KNeighborsRegressor, KNeighborsDispatchingBase
134
152
  return_distance=return_distance,
135
153
  )
136
154
 
137
- @wrap_output_data
138
- def radius_neighbors(
139
- self, X=None, radius=None, return_distance=True, sort_results=False
140
- ):
141
- _onedal_estimator = getattr(self, "_onedal_estimator", None)
142
-
143
- if (
144
- _onedal_estimator is not None
145
- or getattr(self, "_tree", 0) is None
146
- and self._fit_method == "kd_tree"
147
- ):
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
- )
152
-
153
- return result
154
-
155
155
  def _onedal_fit(self, X, y, queue=None):
156
156
  onedal_params = {
157
157
  "n_neighbors": self.n_neighbors,
@@ -184,6 +184,11 @@ class KNeighborsRegressor(sklearn_KNeighborsRegressor, KNeighborsDispatchingBase
184
184
  X, n_neighbors, return_distance, queue=queue
185
185
  )
186
186
 
187
+ def _onedal_score(self, X, y, sample_weight=None, queue=None):
188
+ return r2_score(
189
+ y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
190
+ )
191
+
187
192
  def _save_attributes(self):
188
193
  self.n_features_in_ = self._onedal_estimator.n_features_in_
189
194
  self.n_samples_fit_ = self._onedal_estimator.n_samples_fit_
@@ -195,4 +200,4 @@ class KNeighborsRegressor(sklearn_KNeighborsRegressor, KNeighborsDispatchingBase
195
200
  fit.__doc__ = sklearn_KNeighborsRegressor.__doc__
196
201
  predict.__doc__ = sklearn_KNeighborsRegressor.predict.__doc__
197
202
  kneighbors.__doc__ = sklearn_KNeighborsRegressor.kneighbors.__doc__
198
- radius_neighbors.__doc__ = sklearn_NearestNeighbors.radius_neighbors.__doc__
203
+ score.__doc__ = sklearn_KNeighborsRegressor.score.__doc__
@@ -26,7 +26,7 @@ from .common import KNeighborsDispatchingBase
26
26
 
27
27
 
28
28
  @control_n_jobs(decorated_methods=["fit", "kneighbors"])
29
- class NearestNeighbors(sklearn_NearestNeighbors, KNeighborsDispatchingBase):
29
+ class NearestNeighbors(KNeighborsDispatchingBase, sklearn_NearestNeighbors):
30
30
  __doc__ = sklearn_NearestNeighbors.__doc__
31
31
  if sklearn_check_version("1.2"):
32
32
  _parameter_constraints: dict = {**sklearn_NearestNeighbors._parameter_constraints}
@@ -88,19 +88,40 @@ class NearestNeighbors(sklearn_NearestNeighbors, KNeighborsDispatchingBase):
88
88
  def radius_neighbors(
89
89
  self, X=None, radius=None, return_distance=True, sort_results=False
90
90
  ):
91
- _onedal_estimator = getattr(self, "_onedal_estimator", None)
92
-
93
91
  if (
94
- _onedal_estimator is not None
92
+ hasattr(self, "_onedal_estimator")
95
93
  or getattr(self, "_tree", 0) is None
96
94
  and self._fit_method == "kd_tree"
97
95
  ):
98
96
  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
97
+ return dispatch(
98
+ self,
99
+ "radius_neighbors",
100
+ {
101
+ "onedal": None,
102
+ "sklearn": sklearn_NearestNeighbors.radius_neighbors,
103
+ },
104
+ X,
105
+ radius=radius,
106
+ return_distance=return_distance,
107
+ sort_results=sort_results,
101
108
  )
102
109
 
103
- return result
110
+ def radius_neighbors_graph(
111
+ self, X=None, radius=None, mode="connectivity", sort_results=False
112
+ ):
113
+ return dispatch(
114
+ self,
115
+ "radius_neighbors_graph",
116
+ {
117
+ "onedal": None,
118
+ "sklearn": sklearn_NearestNeighbors.radius_neighbors_graph,
119
+ },
120
+ X,
121
+ radius=radius,
122
+ mode=mode,
123
+ sort_results=sort_results,
124
+ )
104
125
 
105
126
  def _onedal_fit(self, X, y=None, queue=None):
106
127
  onedal_params = {
@@ -144,3 +165,6 @@ class NearestNeighbors(sklearn_NearestNeighbors, KNeighborsDispatchingBase):
144
165
  fit.__doc__ = sklearn_NearestNeighbors.__doc__
145
166
  kneighbors.__doc__ = sklearn_NearestNeighbors.kneighbors.__doc__
146
167
  radius_neighbors.__doc__ = sklearn_NearestNeighbors.radius_neighbors.__doc__
168
+ radius_neighbors_graph.__doc__ = (
169
+ sklearn_NearestNeighbors.radius_neighbors_graph.__doc__
170
+ )
@@ -14,4 +14,4 @@
14
14
  # limitations under the License.
15
15
  # ==============================================================================
16
16
 
17
- __all__ = ["cluster", "covariance"]
17
+ __all__ = ["cluster", "covariance", "decomposition", "linear_model"]
@@ -0,0 +1,19 @@
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 .incremental_pca import IncrementalPCA
18
+
19
+ __all__ = ["IncrementalPCA"]