scikit-learn-intelex 2024.2.0__py39-none-manylinux1_x86_64.whl → 2024.4.0__py39-none-manylinux1_x86_64.whl

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

Potentially problematic release.


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

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