scikit-learn-intelex 2024.0.1__py311-none-manylinux1_x86_64.whl → 2024.4.0__py311-none-manylinux1_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of scikit-learn-intelex might be problematic. Click here for more details.

Files changed (89) hide show
  1. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/METADATA +2 -2
  2. scikit_learn_intelex-2024.4.0.dist-info/RECORD +101 -0
  3. sklearnex/__init__.py +11 -7
  4. sklearnex/__main__.py +0 -1
  5. sklearnex/_device_offload.py +31 -4
  6. sklearnex/_utils.py +15 -1
  7. sklearnex/basic_statistics/__init__.py +2 -2
  8. sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
  9. sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +386 -0
  10. sklearnex/cluster/__init__.py +0 -1
  11. sklearnex/cluster/dbscan.py +5 -2
  12. sklearnex/cluster/k_means.py +0 -1
  13. sklearnex/cluster/tests/test_dbscan.py +0 -1
  14. sklearnex/cluster/tests/test_kmeans.py +0 -1
  15. sklearnex/conftest.py +63 -0
  16. sklearnex/covariance/__init__.py +19 -0
  17. sklearnex/covariance/incremental_covariance.py +130 -0
  18. sklearnex/covariance/tests/test_incremental_covariance.py +143 -0
  19. sklearnex/decomposition/__init__.py +0 -1
  20. sklearnex/decomposition/pca.py +319 -2
  21. sklearnex/decomposition/tests/test_pca.py +34 -6
  22. sklearnex/dispatcher.py +93 -28
  23. sklearnex/ensemble/__init__.py +0 -1
  24. sklearnex/ensemble/_forest.py +93 -89
  25. sklearnex/ensemble/tests/test_forest.py +15 -20
  26. sklearnex/glob/__main__.py +0 -1
  27. sklearnex/glob/dispatcher.py +0 -1
  28. sklearnex/linear_model/__init__.py +1 -3
  29. sklearnex/linear_model/coordinate_descent.py +0 -1
  30. sklearnex/linear_model/linear.py +275 -332
  31. sklearnex/linear_model/logistic_path.py +0 -1
  32. sklearnex/linear_model/logistic_regression.py +385 -0
  33. sklearnex/linear_model/ridge.py +0 -1
  34. sklearnex/linear_model/tests/test_linear.py +47 -7
  35. sklearnex/linear_model/tests/test_logreg.py +70 -8
  36. sklearnex/manifold/__init__.py +0 -1
  37. sklearnex/manifold/t_sne.py +0 -1
  38. sklearnex/manifold/tests/test_tsne.py +0 -1
  39. sklearnex/metrics/__init__.py +0 -1
  40. sklearnex/metrics/pairwise.py +0 -1
  41. sklearnex/metrics/ranking.py +0 -1
  42. sklearnex/metrics/tests/test_metrics.py +0 -1
  43. sklearnex/model_selection/__init__.py +0 -1
  44. sklearnex/model_selection/split.py +0 -1
  45. sklearnex/model_selection/tests/test_model_selection.py +0 -1
  46. sklearnex/neighbors/__init__.py +1 -2
  47. sklearnex/neighbors/_lof.py +221 -0
  48. sklearnex/neighbors/common.py +5 -3
  49. sklearnex/neighbors/knn_classification.py +47 -133
  50. sklearnex/neighbors/knn_regression.py +20 -129
  51. sklearnex/neighbors/knn_unsupervised.py +15 -89
  52. sklearnex/neighbors/tests/test_neighbors.py +12 -17
  53. sklearnex/preview/__init__.py +1 -2
  54. sklearnex/preview/cluster/__init__.py +0 -1
  55. sklearnex/preview/cluster/k_means.py +7 -74
  56. sklearnex/preview/{decomposition → covariance}/__init__.py +19 -20
  57. sklearnex/preview/covariance/covariance.py +133 -0
  58. sklearnex/preview/covariance/tests/test_covariance.py +66 -0
  59. sklearnex/spmd/__init__.py +1 -0
  60. sklearnex/spmd/covariance/__init__.py +19 -0
  61. sklearnex/spmd/covariance/covariance.py +21 -0
  62. sklearnex/spmd/ensemble/forest.py +4 -12
  63. sklearnex/spmd/linear_model/__init__.py +2 -1
  64. sklearnex/spmd/linear_model/logistic_regression.py +21 -0
  65. sklearnex/svm/__init__.py +0 -1
  66. sklearnex/svm/_common.py +4 -7
  67. sklearnex/svm/nusvc.py +73 -49
  68. sklearnex/svm/nusvr.py +8 -52
  69. sklearnex/svm/svc.py +74 -51
  70. sklearnex/svm/svr.py +5 -49
  71. sklearnex/svm/tests/test_svm.py +0 -1
  72. sklearnex/tests/_utils.py +164 -0
  73. sklearnex/tests/test_memory_usage.py +9 -7
  74. sklearnex/tests/test_monkeypatch.py +192 -134
  75. sklearnex/tests/test_n_jobs_support.py +99 -0
  76. sklearnex/tests/test_parallel.py +6 -8
  77. sklearnex/tests/test_patching.py +338 -89
  78. sklearnex/utils/__init__.py +2 -1
  79. sklearnex/utils/_namespace.py +97 -0
  80. sklearnex/utils/validation.py +0 -1
  81. scikit_learn_intelex-2024.0.1.dist-info/RECORD +0 -90
  82. sklearnex/neighbors/lof.py +0 -437
  83. sklearnex/preview/decomposition/pca.py +0 -376
  84. sklearnex/preview/decomposition/tests/test_preview_pca.py +0 -38
  85. sklearnex/tests/_models_info.py +0 -170
  86. sklearnex/tests/utils/_launch_algorithms.py +0 -118
  87. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/LICENSE.txt +0 -0
  88. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/WHEEL +0 -0
  89. {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/top_level.txt +0 -0
@@ -1,376 +0,0 @@
1
- #!/usr/bin/env python
2
- # ===============================================================================
3
- # Copyright 2023 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
- import numbers
19
- from math import sqrt
20
-
21
- import numpy as np
22
- from scipy.sparse import issparse
23
- from sklearn.base import BaseEstimator
24
- from sklearn.utils.extmath import stable_cumsum
25
- from sklearn.utils.validation import check_array, check_is_fitted
26
-
27
- from daal4py.sklearn._utils import sklearn_check_version
28
- from onedal.utils import _check_array
29
-
30
- from ..._device_offload import dispatch
31
- from ..._utils import PatchingConditionsChain
32
-
33
- if sklearn_check_version("1.1") and not sklearn_check_version("1.2"):
34
- from sklearn.utils import check_scalar
35
- if sklearn_check_version("0.23"):
36
- from sklearn.decomposition._pca import _infer_dimension
37
- else:
38
- from sklearn.decomposition._pca import _infer_dimension_
39
-
40
- from sklearn.decomposition import PCA as sklearn_PCA
41
-
42
- from onedal.decomposition import PCA as onedal_PCA
43
-
44
-
45
- class PCA(sklearn_PCA):
46
- if sklearn_check_version("1.2"):
47
- _parameter_constraints: dict = {**sklearn_PCA._parameter_constraints}
48
-
49
- def __init__(
50
- self,
51
- n_components=None,
52
- *,
53
- copy=True,
54
- whiten=False,
55
- svd_solver="auto",
56
- tol=0.0,
57
- iterated_power="auto",
58
- n_oversamples=10,
59
- power_iteration_normalizer="auto",
60
- random_state=None,
61
- ):
62
- self.n_components = n_components
63
- self.copy = copy
64
- self.whiten = whiten
65
- self.svd_solver = svd_solver
66
- self.tol = tol
67
- self.iterated_power = iterated_power
68
- self.n_oversamples = n_oversamples
69
- self.power_iteration_normalizer = power_iteration_normalizer
70
- self.random_state = random_state
71
-
72
- def _validate_n_components(self, n_components, n_samples, n_features, n_sf_min):
73
- if n_components == "mle":
74
- if n_samples < n_features:
75
- raise ValueError(
76
- "n_components='mle' is only supported if" " n_samples >= n_features"
77
- )
78
- elif not 0 <= n_components <= n_sf_min:
79
- raise ValueError(
80
- "n_components=%r must be between 0 and "
81
- "min(n_samples, n_features)=%r with "
82
- "svd_solver='full'" % (n_components, min(n_samples, n_features))
83
- )
84
- elif n_components >= 1:
85
- if not isinstance(n_components, numbers.Integral):
86
- raise ValueError(
87
- "n_components=%r must be of type int "
88
- "when greater than or equal to 1, "
89
- "was of type=%r" % (n_components, type(n_components))
90
- )
91
-
92
- def fit(self, X, y=None):
93
- if sklearn_check_version("1.2"):
94
- self._validate_params()
95
- elif sklearn_check_version("1.1"):
96
- check_scalar(
97
- self.n_oversamples,
98
- "n_oversamples",
99
- min_val=1,
100
- target_type=numbers.Integral,
101
- )
102
- self._fit(X)
103
- return self
104
-
105
- def _fit(self, X):
106
- if issparse(X):
107
- raise TypeError(
108
- "PCA does not support sparse input. See "
109
- "TruncatedSVD for a possible alternative."
110
- )
111
-
112
- if sklearn_check_version("0.23"):
113
- X = self._validate_data(
114
- X, dtype=[np.float64, np.float32], ensure_2d=True, copy=False
115
- )
116
- else:
117
- X = _check_array(
118
- X, dtype=[np.float64, np.float32], ensure_2d=True, copy=False
119
- )
120
-
121
- n_samples, n_features = X.shape
122
- n_sf_min = min(n_samples, n_features)
123
-
124
- if self.n_components is None:
125
- if self.svd_solver == "arpack":
126
- n_components = n_sf_min - 1
127
- else:
128
- n_components = n_sf_min
129
- else:
130
- n_components = self.n_components
131
-
132
- self._validate_n_components(n_components, n_samples, n_features, n_sf_min)
133
-
134
- self._fit_svd_solver = self.svd_solver
135
- shape_good_for_daal = X.shape[1] / X.shape[0] < 2
136
- if self._fit_svd_solver == "auto":
137
- if sklearn_check_version("1.1"):
138
- if max(X.shape) <= 500 or n_components == "mle":
139
- self._fit_svd_solver = "full"
140
- elif 1 <= n_components < 0.8 * n_sf_min:
141
- self._fit_svd_solver = "randomized"
142
- else:
143
- self._fit_svd_solver = "full"
144
- else:
145
- if n_components == "mle":
146
- self._fit_svd_solver = "full"
147
- else:
148
- n, p, k = X.shape[0], X.shape[1], n_components
149
- # check if sklearnex is faster than randomized sklearn
150
- # Refer to daal4py
151
- regression_coefs = np.array(
152
- [
153
- [9.779873e-11, n * p * k],
154
- [-1.122062e-11, n * p * p],
155
- [1.127905e-09, n**2],
156
- ]
157
- )
158
-
159
- if (
160
- n_components >= 1
161
- and np.dot(regression_coefs[:, 0], regression_coefs[:, 1]) <= 0
162
- ):
163
- self._fit_svd_solver = "randomized"
164
- else:
165
- self._fit_svd_solver = "full"
166
-
167
- if not shape_good_for_daal or self._fit_svd_solver != "full":
168
- if sklearn_check_version("0.23"):
169
- X = self._validate_data(X, copy=self.copy)
170
- else:
171
- X = check_array(X, copy=self.copy)
172
-
173
- # Call different fits for either full or truncated SVD
174
- if shape_good_for_daal and self._fit_svd_solver == "full":
175
- return dispatch(
176
- self,
177
- "fit",
178
- {
179
- "onedal": self.__class__._onedal_fit,
180
- "sklearn": sklearn_PCA._fit_full,
181
- },
182
- X,
183
- )
184
- elif not shape_good_for_daal and self._fit_svd_solver == "full":
185
- return sklearn_PCA._fit_full(self, X, n_components)
186
- elif self._fit_svd_solver in ["arpack", "randomized"]:
187
- return sklearn_PCA._fit_truncated(
188
- self,
189
- X,
190
- n_components,
191
- self._fit_svd_solver,
192
- )
193
- else:
194
- raise ValueError("Unrecognized svd_solver='{0}'".format(self._fit_svd_solver))
195
-
196
- def _onedal_supported(self, method_name, *data):
197
- class_name = self.__class__.__name__
198
- if method_name == "fit":
199
- patching_status = PatchingConditionsChain(
200
- f"sklearn.decomposition.{class_name}.{method_name}"
201
- )
202
- patching_status.and_conditions(
203
- [
204
- (
205
- self._fit_svd_solver == "full",
206
- f"'{self._fit_svd_solver}' SVD solver is not supported. "
207
- "Only 'full' solver is supported.",
208
- ),
209
- ]
210
- )
211
- return patching_status
212
- elif method_name == "transform":
213
- patching_status = PatchingConditionsChain(
214
- f"sklearn.decomposition.{class_name}.{method_name}"
215
- )
216
- patching_status.and_conditions(
217
- [
218
- (hasattr(self, "_onedal_estimator"), "oneDAL model was not trained"),
219
- ]
220
- )
221
- return patching_status
222
- raise RuntimeError(f"Unknown method {method_name} in {self.__class__.__name__}")
223
-
224
- def _onedal_cpu_supported(self, method_name, *data):
225
- return self._onedal_supported(method_name, *data)
226
-
227
- def _onedal_gpu_supported(self, method_name, *data):
228
- return self._onedal_supported(method_name, *data)
229
-
230
- def _onedal_fit(self, X, y=None, queue=None):
231
- if self.n_components == "mle" or self.n_components is None:
232
- onedal_n_components = min(X.shape)
233
- elif 0 < self.n_components < 1:
234
- onedal_n_components = min(X.shape)
235
- else:
236
- onedal_n_components = self.n_components
237
-
238
- onedal_params = {
239
- "n_components": onedal_n_components,
240
- "is_deterministic": True,
241
- "method": "precomputed",
242
- }
243
- self._onedal_estimator = onedal_PCA(**onedal_params)
244
- self._onedal_estimator.fit(X, queue=queue)
245
- self._save_attributes()
246
-
247
- U = None
248
- S = self.singular_values_
249
- V = self.components_
250
-
251
- return U, S, V
252
-
253
- def _onedal_predict(self, X, queue=None):
254
- return self._onedal_estimator.predict(X, queue)
255
-
256
- def _onedal_transform(self, X):
257
- X = _check_array(X, dtype=[np.float64, np.float32], ensure_2d=True, copy=False)
258
-
259
- if hasattr(self, "n_features_in_"):
260
- if self.n_features_in_ != X.shape[1]:
261
- raise ValueError(
262
- f"X has {X.shape[1]} features, "
263
- f"but {self.__class__.__name__} is expecting "
264
- f"{self.n_features_in_} features as input"
265
- )
266
- elif hasattr(self, "n_features_"):
267
- if self.n_features_ != X.shape[1]:
268
- raise ValueError(
269
- f"X has {X.shape[1]} features, "
270
- f"but {self.__class__.__name__} is expecting "
271
- f"{self.n_features_} features as input"
272
- )
273
-
274
- # Mean center
275
- X_centered = X - self.mean_
276
- return dispatch(
277
- self,
278
- "transform",
279
- {
280
- "onedal": self.__class__._onedal_predict,
281
- "sklearn": sklearn_PCA.transform,
282
- },
283
- X_centered,
284
- )
285
-
286
- def transform(self, X):
287
- check_is_fitted(self)
288
- if hasattr(self, "_onedal_estimator"):
289
- X_new = self._onedal_transform(X)[:, : self.n_components_]
290
- if self.whiten:
291
- X_new /= np.sqrt(self.explained_variance_)
292
- else:
293
- return sklearn_PCA.transform(self, X)
294
- return X_new
295
-
296
- def fit_transform(self, X, y=None):
297
- """Fit the model with X and apply the dimensionality reduction on X.
298
- Parameters
299
- ----------
300
- X : array-like of shape (n_samples, n_features)
301
- Training data, where `n_samples` is the number of samples
302
- and `n_features` is the number of features.
303
- y : Ignored.
304
-
305
- Returns
306
- -------
307
- X_new : ndarray of shape (n_samples, n_components)
308
- Transformed values of X.
309
- """
310
- if self.svd_solver in ["randomized", "arpack"]:
311
- return sklearn_PCA.fit_transform(self, X)
312
- else:
313
- self.fit(X)
314
- if hasattr(self, "_onedal_estimator"):
315
- X_new = self._onedal_transform(X)[:, : self.n_components_]
316
- if self.whiten:
317
- X_new /= np.sqrt(self.explained_variance_)
318
- return X_new
319
- else:
320
- return sklearn_PCA.transform(self, X)
321
-
322
- def _save_attributes(self):
323
- self.n_samples_ = self._onedal_estimator.n_samples_
324
-
325
- if sklearn_check_version("1.2"):
326
- self.n_features_in_ = self._onedal_estimator.n_features_in_
327
- n_features = self.n_features_in_
328
- elif sklearn_check_version("0.24"):
329
- self.n_features_ = self._onedal_estimator.n_features_
330
- self.n_features_in_ = self._onedal_estimator.n_features_in_
331
- n_features = self.n_features_in_
332
- else:
333
- self.n_features_ = self._onedal_estimator.n_features_
334
- n_features = self.n_features_
335
- n_sf_min = min(self.n_samples_, n_features)
336
-
337
- self.mean_ = self._onedal_estimator.mean_
338
- self.singular_values_ = self._onedal_estimator.singular_values_
339
- self.explained_variance_ = self._onedal_estimator.explained_variance_
340
- self.explained_variance_ratio_ = self._onedal_estimator.explained_variance_ratio_
341
-
342
- if self.n_components is None:
343
- self.n_components_ = self._onedal_estimator.n_components_
344
- elif self.n_components == "mle":
345
- if sklearn_check_version("0.23"):
346
- self.n_components_ = _infer_dimension(
347
- self.explained_variance_, self.n_samples_
348
- )
349
- else:
350
- self.n_components_ = _infer_dimension_(
351
- self.explained_variance_, self.n_samples_, n_features
352
- )
353
- elif 0 < self.n_components < 1.0:
354
- ratio_cumsum = stable_cumsum(self.explained_variance_ratio_)
355
- self.n_components_ = (
356
- np.searchsorted(ratio_cumsum, self.n_components, side="right") + 1
357
- )
358
- else:
359
- self.n_components_ = self._onedal_estimator.n_components_
360
-
361
- if self.n_components_ < n_sf_min:
362
- if self.explained_variance_.shape[0] == n_sf_min:
363
- self.noise_variance_ = self.explained_variance_[
364
- self.n_components_ :
365
- ].mean()
366
- else:
367
- self.noise_variance_ = self._onedal_estimator.noise_variance_
368
- else:
369
- self.noise_variance_ = 0.0
370
-
371
- self.explained_variance_ = self.explained_variance_[: self.n_components_]
372
- self.explained_variance_ratio_ = self.explained_variance_ratio_[
373
- : self.n_components_
374
- ]
375
- self.components_ = self._onedal_estimator.components_[: self.n_components_]
376
- self.singular_values_ = self.singular_values_[: self.n_components_]
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env python
2
- # ===============================================================================
3
- # Copyright 2023 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
- import numpy as np
19
- import pytest
20
- from numpy.testing import assert_allclose
21
-
22
- from onedal.tests.utils._dataframes_support import (
23
- _as_numpy,
24
- _convert_to_dataframe,
25
- get_dataframes_and_queues,
26
- )
27
-
28
-
29
- @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
30
- def test_sklearnex_import(dataframe, queue):
31
- from sklearnex.preview.decomposition import PCA
32
-
33
- X = [[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]]
34
- X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
35
- pca = PCA(n_components=2, svd_solver="full").fit(X)
36
- assert "sklearnex" in pca.__module__
37
- assert hasattr(pca, "_onedal_estimator")
38
- assert_allclose(_as_numpy(pca.singular_values_), [6.30061232, 0.54980396])
@@ -1,170 +0,0 @@
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 numpy as np
18
- from sklearn.cluster import DBSCAN, KMeans
19
- from sklearn.decomposition import PCA
20
- from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
21
- from sklearn.linear_model import (
22
- ElasticNet,
23
- Lasso,
24
- LinearRegression,
25
- LogisticRegression,
26
- LogisticRegressionCV,
27
- Ridge,
28
- )
29
- from sklearn.manifold import TSNE
30
- from sklearn.neighbors import (
31
- KNeighborsClassifier,
32
- KNeighborsRegressor,
33
- LocalOutlierFactor,
34
- NearestNeighbors,
35
- )
36
- from sklearn.svm import SVC
37
-
38
- MODELS_INFO = [
39
- {
40
- "model": KNeighborsClassifier(algorithm="brute"),
41
- "methods": ["kneighbors", "predict", "predict_proba", "score"],
42
- "dataset": "classifier",
43
- },
44
- {
45
- "model": KNeighborsRegressor(algorithm="brute"),
46
- "methods": ["kneighbors", "predict", "score"],
47
- "dataset": "regression",
48
- },
49
- {
50
- "model": NearestNeighbors(algorithm="brute"),
51
- "methods": ["kneighbors"],
52
- "dataset": "blobs",
53
- },
54
- {
55
- "model": LocalOutlierFactor(novelty=False),
56
- "methods": ["fit_predict"],
57
- "dataset": "blobs",
58
- },
59
- {
60
- "model": LocalOutlierFactor(novelty=True),
61
- "methods": ["predict"],
62
- "dataset": "blobs",
63
- },
64
- {
65
- "model": DBSCAN(),
66
- "methods": ["fit_predict"],
67
- "dataset": "blobs",
68
- },
69
- {
70
- "model": SVC(probability=True),
71
- "methods": ["decision_function", "predict", "predict_proba", "score"],
72
- "dataset": "classifier",
73
- },
74
- {
75
- "model": KMeans(),
76
- "methods": ["fit_predict", "fit_transform", "transform", "predict", "score"],
77
- "dataset": "blobs",
78
- },
79
- {
80
- "model": ElasticNet(),
81
- "methods": ["predict", "score"],
82
- "dataset": "regression",
83
- },
84
- {
85
- "model": Lasso(),
86
- "methods": ["predict", "score"],
87
- "dataset": "regression",
88
- },
89
- {
90
- "model": PCA(),
91
- "methods": ["fit_transform", "transform", "score"],
92
- "dataset": "classifier",
93
- },
94
- {
95
- "model": LogisticRegression(max_iter=100, multi_class="multinomial"),
96
- "methods": [
97
- "decision_function",
98
- "predict",
99
- "predict_proba",
100
- "predict_log_proba",
101
- "score",
102
- ],
103
- "dataset": "classifier",
104
- },
105
- {
106
- "model": LogisticRegressionCV(max_iter=100),
107
- "methods": [
108
- "decision_function",
109
- "predict",
110
- "predict_proba",
111
- "predict_log_proba",
112
- "score",
113
- ],
114
- "dataset": "classifier",
115
- },
116
- {
117
- "model": RandomForestClassifier(n_estimators=10),
118
- "methods": ["predict", "predict_proba", "predict_log_proba", "score"],
119
- "dataset": "classifier",
120
- },
121
- {
122
- "model": RandomForestRegressor(n_estimators=10),
123
- "methods": ["predict", "score"],
124
- "dataset": "regression",
125
- },
126
- {
127
- "model": LinearRegression(),
128
- "methods": ["predict", "score"],
129
- "dataset": "regression",
130
- },
131
- {
132
- "model": Ridge(),
133
- "methods": ["predict", "score"],
134
- "dataset": "regression",
135
- },
136
- ]
137
-
138
- TYPES = [
139
- np.int8,
140
- np.int16,
141
- np.int32,
142
- np.int64,
143
- np.float16,
144
- np.float32,
145
- np.float64,
146
- np.uint8,
147
- np.uint16,
148
- np.uint32,
149
- np.uint64,
150
- ]
151
-
152
- TO_SKIP = [
153
- # --------------- NO INFO ---------------
154
- r"KMeans .*transform",
155
- r"KMeans .*score",
156
- r"PCA .*score",
157
- r"LogisticRegression .*decision_function",
158
- r"LogisticRegressionCV .*decision_function",
159
- r"LogisticRegressionCV .*predict",
160
- r"LogisticRegressionCV .*predict_proba",
161
- r"LogisticRegressionCV .*predict_log_proba",
162
- r"LogisticRegressionCV .*score",
163
- # --------------- Scikit ---------------
164
- r"Ridge float16 predict",
165
- r"Ridge float16 score",
166
- r"RandomForestClassifier .*predict_proba",
167
- r"RandomForestClassifier .*predict_log_proba",
168
- r"pairwise_distances .*pairwise_distances", # except float64
169
- r"roc_auc_score .*roc_auc_score",
170
- ]
@@ -1,118 +0,0 @@
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()