scikit-learn-intelex 2024.0.1__py312-none-win_amd64.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 (90) hide show
  1. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/__init__.py +61 -0
  2. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/__main__.py +59 -0
  3. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/_config.py +110 -0
  4. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/_device_offload.py +223 -0
  5. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/_utils.py +95 -0
  6. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/basic_statistics/__init__.py +20 -0
  7. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/basic_statistics/basic_statistics.py +17 -0
  8. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/cluster/__init__.py +21 -0
  9. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/cluster/dbscan.py +187 -0
  10. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/cluster/k_means.py +18 -0
  11. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/cluster/tests/test_dbscan.py +37 -0
  12. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/cluster/tests/test_kmeans.py +31 -0
  13. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/decomposition/__init__.py +20 -0
  14. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/decomposition/pca.py +18 -0
  15. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/decomposition/tests/test_pca.py +28 -0
  16. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/dispatcher.py +329 -0
  17. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/doc/third-party-programs.txt +424 -0
  18. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/ensemble/__init__.py +30 -0
  19. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/ensemble/_forest.py +1947 -0
  20. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/ensemble/tests/test_forest.py +118 -0
  21. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/glob/__main__.py +73 -0
  22. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/glob/dispatcher.py +88 -0
  23. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/__init__.py +30 -0
  24. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/coordinate_descent.py +18 -0
  25. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/linear.py +373 -0
  26. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/logistic_path.py +18 -0
  27. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/ridge.py +18 -0
  28. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/tests/test_linear.py +77 -0
  29. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/tests/test_logreg.py +29 -0
  30. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/manifold/__init__.py +20 -0
  31. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/manifold/t_sne.py +18 -0
  32. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/manifold/tests/test_tsne.py +27 -0
  33. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/metrics/__init__.py +24 -0
  34. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/metrics/pairwise.py +18 -0
  35. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/metrics/ranking.py +18 -0
  36. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/metrics/tests/test_metrics.py +40 -0
  37. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/model_selection/__init__.py +22 -0
  38. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/model_selection/split.py +18 -0
  39. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/model_selection/tests/test_model_selection.py +35 -0
  40. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/__init__.py +28 -0
  41. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/common.py +264 -0
  42. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/knn_classification.py +331 -0
  43. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/knn_regression.py +307 -0
  44. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/knn_unsupervised.py +220 -0
  45. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/lof.py +437 -0
  46. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/tests/test_neighbors.py +85 -0
  47. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/__init__.py +18 -0
  48. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/cluster/__init__.py +20 -0
  49. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/cluster/_common.py +84 -0
  50. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/cluster/k_means.py +370 -0
  51. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/decomposition/__init__.py +20 -0
  52. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/decomposition/pca.py +376 -0
  53. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/decomposition/tests/test_preview_pca.py +38 -0
  54. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/__init__.py +24 -0
  55. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/basic_statistics/__init__.py +19 -0
  56. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/basic_statistics/basic_statistics.py +21 -0
  57. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/cluster/__init__.py +30 -0
  58. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/cluster/dbscan.py +50 -0
  59. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/cluster/kmeans.py +21 -0
  60. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/decomposition/__init__.py +19 -0
  61. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/decomposition/pca.py +21 -0
  62. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/ensemble/__init__.py +19 -0
  63. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/ensemble/forest.py +79 -0
  64. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/linear_model/__init__.py +19 -0
  65. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/linear_model/linear_model.py +21 -0
  66. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/neighbors/__init__.py +19 -0
  67. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/neighbors/neighbors.py +25 -0
  68. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/__init__.py +30 -0
  69. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/_common.py +188 -0
  70. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/nusvc.py +272 -0
  71. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/nusvr.py +163 -0
  72. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/svc.py +301 -0
  73. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/svr.py +164 -0
  74. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/tests/test_svm.py +102 -0
  75. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/_models_info.py +170 -0
  76. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_config.py +39 -0
  77. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_memory_usage.py +225 -0
  78. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_monkeypatch.py +210 -0
  79. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_parallel.py +50 -0
  80. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_patching.py +122 -0
  81. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_run_to_run_stability_tests.py +428 -0
  82. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/utils/_launch_algorithms.py +118 -0
  83. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/utils/__init__.py +19 -0
  84. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/utils/parallel.py +59 -0
  85. scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/utils/validation.py +18 -0
  86. scikit_learn_intelex-2024.0.1.dist-info/LICENSE.txt +202 -0
  87. scikit_learn_intelex-2024.0.1.dist-info/METADATA +230 -0
  88. scikit_learn_intelex-2024.0.1.dist-info/RECORD +90 -0
  89. scikit_learn_intelex-2024.0.1.dist-info/WHEEL +5 -0
  90. scikit_learn_intelex-2024.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,428 @@
1
+ # ===============================================================================
2
+ # Copyright 2020 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 random
18
+
19
+ import numpy as np
20
+ import pytest
21
+
22
+ import daal4py as d4p
23
+ from sklearnex import patch_sklearn
24
+
25
+ patch_sklearn()
26
+
27
+ from scipy import sparse
28
+ from sklearn.cluster import DBSCAN, KMeans
29
+ from sklearn.datasets import (
30
+ load_breast_cancer,
31
+ load_diabetes,
32
+ load_iris,
33
+ make_classification,
34
+ make_regression,
35
+ )
36
+ from sklearn.decomposition import PCA
37
+ from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
38
+ from sklearn.linear_model import (
39
+ ElasticNet,
40
+ Lasso,
41
+ LinearRegression,
42
+ LogisticRegression,
43
+ LogisticRegressionCV,
44
+ Ridge,
45
+ )
46
+ from sklearn.manifold import TSNE
47
+ from sklearn.metrics import pairwise_distances, roc_auc_score
48
+ from sklearn.model_selection import train_test_split
49
+ from sklearn.neighbors import (
50
+ KNeighborsClassifier,
51
+ KNeighborsRegressor,
52
+ LocalOutlierFactor,
53
+ NearestNeighbors,
54
+ )
55
+ from sklearn.svm import SVC, SVR, NuSVC, NuSVR
56
+
57
+ from daal4py.sklearn._utils import daal_check_version
58
+
59
+ # to reproduce errors even in CI
60
+ d4p.daalinit(nthreads=100)
61
+
62
+
63
+ def get_class_name(x):
64
+ return x.__class__.__name__
65
+
66
+
67
+ def method_processing(X, clf, methods):
68
+ res = []
69
+ name = []
70
+ for i in methods:
71
+ if i == "predict":
72
+ res.append(clf.predict(X))
73
+ name.append(get_class_name(clf) + ".predict(X)")
74
+ elif i == "predict_proba":
75
+ res.append(clf.predict_proba(X))
76
+ name.append(get_class_name(clf) + ".predict_proba(X)")
77
+ elif i == "decision_function":
78
+ res.append(clf.decision_function(X))
79
+ name.append(get_class_name(clf) + ".decision_function(X)")
80
+ elif i == "kneighbors":
81
+ dist, idx = clf.kneighbors(X)
82
+ res.append(dist)
83
+ name.append("dist")
84
+ res.append(idx)
85
+ name.append("idx")
86
+ elif i == "fit_predict":
87
+ predict = clf.fit_predict(X)
88
+ res.append(predict)
89
+ name.append(get_class_name(clf) + ".fit_predict")
90
+ elif i == "fit_transform":
91
+ res.append(clf.fit_transform(X))
92
+ name.append(get_class_name(clf) + ".fit_transform")
93
+ elif i == "transform":
94
+ res.append(clf.transform(X))
95
+ name.append(get_class_name(clf) + ".transform(X)")
96
+ elif i == "get_covariance":
97
+ res.append(clf.get_covariance())
98
+ name.append(get_class_name(clf) + ".get_covariance()")
99
+ elif i == "get_precision":
100
+ res.append(clf.get_precision())
101
+ name.append(get_class_name(clf) + ".get_precision()")
102
+ elif i == "score_samples":
103
+ res.append(clf.score_samples(X))
104
+ name.append(get_class_name(clf) + ".score_samples(X)")
105
+ return res, name
106
+
107
+
108
+ def func(X, Y, clf, methods):
109
+ clf.fit(X, Y)
110
+ res, name = method_processing(X, clf, methods)
111
+
112
+ for i in clf.__dict__.keys():
113
+ ans = getattr(clf, i)
114
+ if isinstance(ans, (bool, float, int, np.ndarray, np.float64)):
115
+ if isinstance(ans, np.ndarray) and None in ans:
116
+ continue
117
+ res.append(ans)
118
+ name.append(get_class_name(clf) + "." + i)
119
+ return res, name
120
+
121
+
122
+ def _run_test(model, methods, dataset):
123
+ datasets = []
124
+ if dataset in ["blobs", "classifier", "sparse"]:
125
+ X1, y1 = load_iris(return_X_y=True)
126
+ if dataset == "sparse":
127
+ X1 = sparse.csr_matrix(X1)
128
+ datasets.append((X1, y1))
129
+ X2, y2 = load_breast_cancer(return_X_y=True)
130
+ if dataset == "sparse":
131
+ X2 = sparse.csr_matrix(X2)
132
+ datasets.append((X2, y2))
133
+ elif dataset == "regression":
134
+ X1, y1 = make_regression(
135
+ n_samples=500, n_features=10, noise=64.0, random_state=42
136
+ )
137
+ datasets.append((X1, y1))
138
+ X2, y2 = load_diabetes(return_X_y=True)
139
+ datasets.append((X2, y2))
140
+ else:
141
+ raise ValueError("Unknown dataset type")
142
+
143
+ for X, y in datasets:
144
+ baseline, name = func(X, y, model, methods)
145
+ for i in range(10):
146
+ res, _ = func(X, y, model, methods)
147
+
148
+ for a, b, n in zip(res, baseline, name):
149
+ np.testing.assert_allclose(
150
+ a, b, rtol=0.0, atol=0.0, err_msg=str(n + " is incorrect")
151
+ )
152
+
153
+
154
+ MODELS_INFO = [
155
+ {
156
+ "model": KNeighborsClassifier(
157
+ n_neighbors=10, algorithm="brute", weights="uniform"
158
+ ),
159
+ "methods": ["predict", "predict_proba", "kneighbors"],
160
+ "dataset": "classifier",
161
+ },
162
+ {
163
+ "model": KNeighborsClassifier(
164
+ n_neighbors=10, algorithm="brute", weights="distance"
165
+ ),
166
+ "methods": ["predict", "predict_proba", "kneighbors"],
167
+ "dataset": "classifier",
168
+ },
169
+ {
170
+ "model": KNeighborsClassifier(
171
+ n_neighbors=10, algorithm="kd_tree", weights="uniform"
172
+ ),
173
+ "methods": ["predict", "predict_proba", "kneighbors"],
174
+ "dataset": "classifier",
175
+ },
176
+ {
177
+ "model": KNeighborsClassifier(
178
+ n_neighbors=10, algorithm="kd_tree", weights="distance"
179
+ ),
180
+ "methods": ["predict", "predict_proba", "kneighbors"],
181
+ "dataset": "classifier",
182
+ },
183
+ {
184
+ "model": KNeighborsRegressor(
185
+ n_neighbors=10, algorithm="kd_tree", weights="distance"
186
+ ),
187
+ "methods": ["predict", "kneighbors"],
188
+ "dataset": "regression",
189
+ },
190
+ {
191
+ "model": KNeighborsRegressor(
192
+ n_neighbors=10, algorithm="kd_tree", weights="uniform"
193
+ ),
194
+ "methods": ["predict", "kneighbors"],
195
+ "dataset": "regression",
196
+ },
197
+ {
198
+ "model": KNeighborsRegressor(
199
+ n_neighbors=10, algorithm="brute", weights="distance"
200
+ ),
201
+ "methods": ["predict", "kneighbors"],
202
+ "dataset": "regression",
203
+ },
204
+ {
205
+ "model": KNeighborsRegressor(
206
+ n_neighbors=10, algorithm="brute", weights="uniform"
207
+ ),
208
+ "methods": ["predict", "kneighbors"],
209
+ "dataset": "regression",
210
+ },
211
+ {
212
+ "model": NearestNeighbors(n_neighbors=10, algorithm="brute"),
213
+ "methods": ["kneighbors"],
214
+ "dataset": "blobs",
215
+ },
216
+ {
217
+ "model": NearestNeighbors(n_neighbors=10, algorithm="kd_tree"),
218
+ "methods": ["kneighbors"],
219
+ "dataset": "blobs",
220
+ },
221
+ {
222
+ "model": LocalOutlierFactor(n_neighbors=10, novelty=False),
223
+ "methods": ["fit_predict"],
224
+ "dataset": "blobs",
225
+ },
226
+ {
227
+ "model": LocalOutlierFactor(n_neighbors=10, novelty=True),
228
+ "methods": ["predict"],
229
+ "dataset": "blobs",
230
+ },
231
+ {
232
+ "model": DBSCAN(algorithm="brute", n_jobs=-1),
233
+ "methods": [],
234
+ "dataset": "blobs",
235
+ },
236
+ {
237
+ "model": SVC(kernel="rbf"),
238
+ "methods": ["predict", "decision_function"],
239
+ "dataset": "classifier",
240
+ },
241
+ {
242
+ "model": SVC(kernel="rbf"),
243
+ "methods": ["predict", "decision_function"],
244
+ "dataset": "sparse",
245
+ },
246
+ {
247
+ "model": NuSVC(kernel="rbf"),
248
+ "methods": ["predict", "decision_function"],
249
+ "dataset": "classifier",
250
+ },
251
+ {
252
+ "model": SVR(kernel="rbf"),
253
+ "methods": ["predict"],
254
+ "dataset": "regression",
255
+ },
256
+ {
257
+ "model": NuSVR(kernel="rbf"),
258
+ "methods": ["predict"],
259
+ "dataset": "regression",
260
+ },
261
+ {
262
+ "model": TSNE(random_state=0),
263
+ "methods": ["fit_transform"],
264
+ "dataset": "classifier",
265
+ },
266
+ {
267
+ "model": KMeans(random_state=0, init="k-means++"),
268
+ "methods": ["predict"],
269
+ "dataset": "blobs",
270
+ },
271
+ {
272
+ "model": KMeans(random_state=0, init="random"),
273
+ "methods": ["predict"],
274
+ "dataset": "blobs",
275
+ },
276
+ {
277
+ "model": KMeans(random_state=0, init="k-means++"),
278
+ "methods": ["predict"],
279
+ "dataset": "sparse",
280
+ },
281
+ {
282
+ "model": KMeans(random_state=0, init="random"),
283
+ "methods": ["predict"],
284
+ "dataset": "sparse",
285
+ },
286
+ {
287
+ "model": ElasticNet(random_state=0),
288
+ "methods": ["predict"],
289
+ "dataset": "regression",
290
+ },
291
+ {
292
+ "model": Lasso(random_state=0),
293
+ "methods": ["predict"],
294
+ "dataset": "regression",
295
+ },
296
+ {
297
+ "model": PCA(n_components=0.5, svd_solver="full", random_state=0),
298
+ "methods": ["transform", "get_covariance", "get_precision", "score_samples"],
299
+ "dataset": "classifier",
300
+ },
301
+ {
302
+ "model": RandomForestClassifier(
303
+ random_state=0, oob_score=True, max_samples=0.5, max_features="sqrt"
304
+ ),
305
+ "methods": ["predict", "predict_proba"],
306
+ "dataset": "classifier",
307
+ },
308
+ {
309
+ "model": LogisticRegression(random_state=0, solver="newton-cg", max_iter=1000),
310
+ "methods": ["predict", "predict_proba"],
311
+ "dataset": "classifier",
312
+ },
313
+ {
314
+ "model": LogisticRegression(random_state=0, solver="lbfgs", max_iter=1000),
315
+ "methods": ["predict", "predict_proba"],
316
+ "dataset": "classifier",
317
+ },
318
+ {
319
+ "model": LogisticRegressionCV(
320
+ random_state=0, solver="newton-cg", n_jobs=-1, max_iter=1000
321
+ ),
322
+ "methods": ["predict", "predict_proba"],
323
+ "dataset": "classifier",
324
+ },
325
+ {
326
+ "model": LogisticRegressionCV(
327
+ random_state=0, solver="lbfgs", n_jobs=-1, max_iter=1000
328
+ ),
329
+ "methods": ["predict", "predict_proba"],
330
+ "dataset": "classifier",
331
+ },
332
+ {
333
+ "model": RandomForestRegressor(
334
+ random_state=0, oob_score=True, max_samples=0.5, max_features="sqrt"
335
+ ),
336
+ "methods": ["predict"],
337
+ "dataset": "regression",
338
+ },
339
+ {
340
+ "model": LinearRegression(),
341
+ "methods": ["predict"],
342
+ "dataset": "regression",
343
+ },
344
+ {
345
+ "model": Ridge(random_state=0),
346
+ "methods": ["predict"],
347
+ "dataset": "regression",
348
+ },
349
+ ]
350
+
351
+ TO_SKIP = [
352
+ "TSNE", # Absolute diff is 1e-10, potential problem in KNN,
353
+ # will be fixed for next release. (UPD. KNN is fixed but there is a problem
354
+ # with stability of stock sklearn. It is already stable in master, so, we
355
+ # need to wait for the next sklearn release)
356
+ "LogisticRegression", # Absolute diff is 1e-8, will be fixed for next release
357
+ "LogisticRegressionCV", # Absolute diff is 1e-10, will be fixed for next release
358
+ "RandomForestRegressor", # Absolute diff is 1e-14 in OOB score,
359
+ # will be fixed for next release
360
+ ]
361
+
362
+
363
+ @pytest.mark.parametrize("model_head", MODELS_INFO)
364
+ def test_models(model_head):
365
+ stable_algos = []
366
+ if get_class_name(model_head["model"]) in stable_algos and daal_check_version(
367
+ (2021, "P", 300)
368
+ ):
369
+ try:
370
+ TO_SKIP.remove(get_class_name(model_head["model"]))
371
+ except ValueError:
372
+ pass
373
+ if get_class_name(model_head["model"]) in TO_SKIP:
374
+ pytest.skip("Unstable", allow_module_level=False)
375
+ _run_test(model_head["model"], model_head["methods"], model_head["dataset"])
376
+
377
+
378
+ @pytest.mark.parametrize("features", range(5, 10))
379
+ def test_train_test_split(features):
380
+ X, y = make_classification(
381
+ n_samples=4000,
382
+ n_features=features,
383
+ n_informative=features,
384
+ n_redundant=0,
385
+ n_clusters_per_class=8,
386
+ random_state=0,
387
+ )
388
+ (
389
+ baseline_X_train,
390
+ baseline_X_test,
391
+ baseline_y_train,
392
+ baseline_y_test,
393
+ ) = train_test_split(X, y, test_size=0.33, random_state=0)
394
+ baseline = [baseline_X_train, baseline_X_test, baseline_y_train, baseline_y_test]
395
+ for _ in range(10):
396
+ X_train, X_test, y_train, y_test = train_test_split(
397
+ X, y, test_size=0.33, random_state=0
398
+ )
399
+ res = [X_train, X_test, y_train, y_test]
400
+ for a, b in zip(res, baseline):
401
+ np.testing.assert_allclose(
402
+ a, b, rtol=0.0, atol=0.0, err_msg=str("train_test_split is incorrect")
403
+ )
404
+
405
+
406
+ @pytest.mark.parametrize("metric", ["cosine", "correlation"])
407
+ def test_pairwise_distances(metric):
408
+ X = np.random.rand(1000)
409
+ X = np.array(X, dtype=np.float64)
410
+ baseline = pairwise_distances(X.reshape(1, -1), metric=metric)
411
+ for _ in range(5):
412
+ res = pairwise_distances(X.reshape(1, -1), metric=metric)
413
+ for a, b in zip(res, baseline):
414
+ np.testing.assert_allclose(
415
+ a, b, rtol=0.0, atol=0.0, err_msg=str("pairwise_distances is incorrect")
416
+ )
417
+
418
+
419
+ @pytest.mark.parametrize("array_size", [100, 1000, 10000])
420
+ def test_roc_auc(array_size):
421
+ a = [random.randint(0, 1) for i in range(array_size)]
422
+ b = [random.randint(0, 1) for i in range(array_size)]
423
+ baseline = roc_auc_score(a, b)
424
+ for _ in range(5):
425
+ res = roc_auc_score(a, b)
426
+ np.testing.assert_allclose(
427
+ baseline, res, rtol=0.0, atol=0.0, err_msg=str("roc_auc is incorrect")
428
+ )
@@ -0,0 +1,118 @@
1
+ # ==============================================================================
2
+ # Copyright 2021 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
+ import random
19
+
20
+ import numpy as np
21
+
22
+ from sklearnex import patch_sklearn
23
+
24
+ patch_sklearn()
25
+
26
+ import pathlib
27
+ import sys
28
+
29
+ from sklearn.datasets import load_diabetes, load_iris, make_regression
30
+ from sklearn.metrics import pairwise_distances, roc_auc_score
31
+
32
+ absolute_path = str(pathlib.Path(__file__).parent.absolute())
33
+ sys.path.append(absolute_path + "/../")
34
+ from _models_info import MODELS_INFO, TYPES
35
+
36
+
37
+ def get_class_name(x):
38
+ return x.__class__.__name__
39
+
40
+
41
+ def generate_dataset(name, dtype, model_name):
42
+ if model_name == "LinearRegression":
43
+ X, y = make_regression(n_samples=1000, n_features=5)
44
+ elif name in ["blobs", "classifier"]:
45
+ X, y = load_iris(return_X_y=True)
46
+ elif name == "regression":
47
+ X, y = load_diabetes(return_X_y=True)
48
+ else:
49
+ raise ValueError("Unknown dataset type")
50
+ X = np.array(X, dtype=dtype)
51
+ y = np.array(y, dtype=dtype)
52
+ return (X, y)
53
+
54
+
55
+ def run_patch(model_info, dtype):
56
+ print(get_class_name(model_info["model"]), dtype.__name__)
57
+ X, y = generate_dataset(
58
+ model_info["dataset"], dtype, get_class_name(model_info["model"])
59
+ )
60
+ model = model_info["model"]
61
+ model.fit(X, y)
62
+ logging.info("fit")
63
+ for i in model_info["methods"]:
64
+ if i == "predict":
65
+ model.predict(X)
66
+ elif i == "predict_proba":
67
+ model.predict_proba(X)
68
+ elif i == "predict_log_proba":
69
+ model.predict_log_proba(X)
70
+ elif i == "decision_function":
71
+ model.decision_function(X)
72
+ elif i == "fit_predict":
73
+ model.fit_predict(X)
74
+ elif i == "transform":
75
+ model.transform(X)
76
+ elif i == "fit_transform":
77
+ model.fit_transform(X)
78
+ elif i == "kneighbors":
79
+ model.kneighbors(X)
80
+ elif i == "score":
81
+ model.score(X, y)
82
+ else:
83
+ raise ValueError(i + " is wrong method")
84
+ logging.info(i)
85
+
86
+
87
+ def run_algotithms():
88
+ for info in MODELS_INFO:
89
+ for t in TYPES:
90
+ model_name = get_class_name(info["model"])
91
+ if model_name in ["Ridge", "LinearRegression"] and t.__name__ == "uint32":
92
+ continue
93
+ run_patch(info, t)
94
+
95
+
96
+ def run_utils():
97
+ # pairwise_distances
98
+ for metric in ["cosine", "correlation"]:
99
+ for t in TYPES:
100
+ X = np.random.rand(1000)
101
+ X = np.array(X, dtype=t)
102
+ print("pairwise_distances", t.__name__)
103
+ _ = pairwise_distances(X.reshape(1, -1), metric=metric)
104
+ logging.info("pairwise_distances")
105
+ # roc_auc_score
106
+ for t in [np.float32, np.float64]:
107
+ a = [random.randint(0, 1) for i in range(1000)]
108
+ b = [random.randint(0, 1) for i in range(1000)]
109
+ a = np.array(a, dtype=t)
110
+ b = np.array(b, dtype=t)
111
+ print("roc_auc_score", t.__name__)
112
+ _ = roc_auc_score(a, b)
113
+ logging.info("roc_auc_score")
114
+
115
+
116
+ if __name__ == "__main__":
117
+ run_algotithms()
118
+ run_utils()
@@ -0,0 +1,19 @@
1
+ # ===============================================================================
2
+ # Copyright 2022 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 .validation import _assert_all_finite
18
+
19
+ __all__ = ["_assert_all_finite"]
@@ -0,0 +1,59 @@
1
+ # ===============================================================================
2
+ # Copyright 2023 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 warnings
18
+ from functools import update_wrapper
19
+
20
+ from .._config import config_context, get_config
21
+
22
+
23
+ class _FuncWrapper:
24
+ """Load the global configuration before calling the function."""
25
+
26
+ def __init__(self, function):
27
+ self.function = function
28
+ update_wrapper(self, self.function)
29
+
30
+ def with_config(self, config):
31
+ self.config = config
32
+ return self
33
+
34
+ def __call__(self, *args, **kwargs):
35
+ config = getattr(self, "config", None)
36
+ if config is None:
37
+ warnings.warn(
38
+ "`sklearn.utils.parallel.delayed` should be used with "
39
+ "`sklearn.utils.parallel.Parallel` to make it possible to propagate "
40
+ "the scikit-learn configuration of the current thread to the "
41
+ "joblib workers.",
42
+ UserWarning,
43
+ )
44
+ config = {}
45
+ with config_context(**config):
46
+ return self.function(*args, **kwargs)
47
+
48
+
49
+ class _FuncWrapperOld:
50
+ """Load the global configuration before calling the function."""
51
+
52
+ def __init__(self, function):
53
+ self.function = function
54
+ self.config = get_config()
55
+ update_wrapper(self, self.function)
56
+
57
+ def __call__(self, *args, **kwargs):
58
+ with config_context(**self.config):
59
+ return self.function(*args, **kwargs)
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env python
2
+ # ===============================================================================
3
+ # Copyright 2022 Intel Corporation
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ # ===============================================================================
17
+
18
+ from daal4py.sklearn.utils.validation import _assert_all_finite