scikit-learn-intelex 2024.5.0__py311-none-manylinux1_x86_64.whl → 2024.6.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 (35) hide show
  1. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.6.0.dist-info}/METADATA +2 -2
  2. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.6.0.dist-info}/RECORD +34 -30
  3. sklearnex/cluster/dbscan.py +3 -0
  4. sklearnex/cluster/tests/test_dbscan.py +8 -6
  5. sklearnex/conftest.py +11 -1
  6. sklearnex/decomposition/tests/test_pca.py +4 -2
  7. sklearnex/dispatcher.py +15 -1
  8. sklearnex/ensemble/_forest.py +114 -23
  9. sklearnex/ensemble/tests/test_forest.py +13 -3
  10. sklearnex/glob/dispatcher.py +16 -2
  11. sklearnex/linear_model/incremental_linear.py +102 -25
  12. sklearnex/linear_model/linear.py +25 -7
  13. sklearnex/linear_model/logistic_regression.py +13 -15
  14. sklearnex/linear_model/tests/test_incremental_linear.py +10 -10
  15. sklearnex/linear_model/tests/test_linear.py +2 -2
  16. sklearnex/neighbors/knn_regression.py +24 -0
  17. sklearnex/preview/__init__.py +1 -1
  18. sklearnex/preview/decomposition/__init__.py +19 -0
  19. sklearnex/preview/decomposition/incremental_pca.py +228 -0
  20. sklearnex/preview/decomposition/tests/test_incremental_pca.py +266 -0
  21. sklearnex/svm/_common.py +165 -20
  22. sklearnex/svm/nusvc.py +40 -4
  23. sklearnex/svm/nusvr.py +31 -2
  24. sklearnex/svm/svc.py +40 -4
  25. sklearnex/svm/svr.py +31 -2
  26. sklearnex/tests/_utils.py +49 -17
  27. sklearnex/tests/test_common.py +54 -0
  28. sklearnex/tests/test_memory_usage.py +185 -126
  29. sklearnex/tests/test_patching.py +5 -12
  30. sklearnex/tests/test_run_to_run_stability.py +283 -0
  31. sklearnex/utils/_namespace.py +1 -1
  32. sklearnex/tests/test_run_to_run_stability_tests.py +0 -428
  33. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.6.0.dist-info}/LICENSE.txt +0 -0
  34. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.6.0.dist-info}/WHEEL +0 -0
  35. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.6.0.dist-info}/top_level.txt +0 -0
@@ -1,428 +0,0 @@
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="covariance_eigh", 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
- )