scikit-learn-intelex 2025.1.0__py39-none-manylinux_2_28_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.
- daal4py/__init__.py +73 -0
- daal4py/__main__.py +58 -0
- daal4py/_daal4py.cpython-39-x86_64-linux-gnu.so +0 -0
- daal4py/doc/third-party-programs.txt +424 -0
- daal4py/mb/__init__.py +19 -0
- daal4py/mb/model_builders.py +377 -0
- daal4py/mpi_transceiver.cpython-39-x86_64-linux-gnu.so +0 -0
- daal4py/sklearn/__init__.py +40 -0
- daal4py/sklearn/_n_jobs_support.py +248 -0
- daal4py/sklearn/_utils.py +245 -0
- daal4py/sklearn/cluster/__init__.py +20 -0
- daal4py/sklearn/cluster/dbscan.py +165 -0
- daal4py/sklearn/cluster/k_means.py +597 -0
- daal4py/sklearn/cluster/tests/test_dbscan.py +109 -0
- daal4py/sklearn/decomposition/__init__.py +19 -0
- daal4py/sklearn/decomposition/_pca.py +524 -0
- daal4py/sklearn/ensemble/AdaBoostClassifier.py +196 -0
- daal4py/sklearn/ensemble/GBTDAAL.py +337 -0
- daal4py/sklearn/ensemble/__init__.py +27 -0
- daal4py/sklearn/ensemble/_forest.py +1397 -0
- daal4py/sklearn/ensemble/tests/test_decision_forest.py +206 -0
- daal4py/sklearn/linear_model/__init__.py +29 -0
- daal4py/sklearn/linear_model/_coordinate_descent.py +848 -0
- daal4py/sklearn/linear_model/_linear.py +272 -0
- daal4py/sklearn/linear_model/_ridge.py +325 -0
- daal4py/sklearn/linear_model/coordinate_descent.py +17 -0
- daal4py/sklearn/linear_model/linear.py +17 -0
- daal4py/sklearn/linear_model/logistic_loss.py +195 -0
- daal4py/sklearn/linear_model/logistic_path.py +1026 -0
- daal4py/sklearn/linear_model/ridge.py +17 -0
- daal4py/sklearn/linear_model/tests/test_linear.py +208 -0
- daal4py/sklearn/linear_model/tests/test_ridge.py +69 -0
- daal4py/sklearn/manifold/__init__.py +19 -0
- daal4py/sklearn/manifold/_t_sne.py +405 -0
- daal4py/sklearn/metrics/__init__.py +20 -0
- daal4py/sklearn/metrics/_pairwise.py +236 -0
- daal4py/sklearn/metrics/_ranking.py +210 -0
- daal4py/sklearn/model_selection/__init__.py +19 -0
- daal4py/sklearn/model_selection/_split.py +309 -0
- daal4py/sklearn/model_selection/tests/test_split.py +56 -0
- daal4py/sklearn/monkeypatch/__init__.py +0 -0
- daal4py/sklearn/monkeypatch/dispatcher.py +232 -0
- daal4py/sklearn/monkeypatch/tests/_models_info.py +161 -0
- daal4py/sklearn/monkeypatch/tests/test_monkeypatch.py +71 -0
- daal4py/sklearn/monkeypatch/tests/test_patching.py +90 -0
- daal4py/sklearn/monkeypatch/tests/utils/_launch_algorithms.py +117 -0
- daal4py/sklearn/neighbors/__init__.py +21 -0
- daal4py/sklearn/neighbors/_base.py +503 -0
- daal4py/sklearn/neighbors/_classification.py +139 -0
- daal4py/sklearn/neighbors/_regression.py +74 -0
- daal4py/sklearn/neighbors/_unsupervised.py +55 -0
- daal4py/sklearn/neighbors/tests/test_kneighbors.py +113 -0
- daal4py/sklearn/svm/__init__.py +19 -0
- daal4py/sklearn/svm/svm.py +734 -0
- daal4py/sklearn/utils/__init__.py +21 -0
- daal4py/sklearn/utils/base.py +75 -0
- daal4py/sklearn/utils/tests/test_utils.py +51 -0
- daal4py/sklearn/utils/validation.py +693 -0
- onedal/__init__.py +83 -0
- onedal/_config.py +54 -0
- onedal/_device_offload.py +222 -0
- onedal/_onedal_py_dpc.cpython-39-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_host.cpython-39-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_spmd_dpc.cpython-39-x86_64-linux-gnu.so +0 -0
- onedal/basic_statistics/__init__.py +20 -0
- onedal/basic_statistics/basic_statistics.py +107 -0
- onedal/basic_statistics/incremental_basic_statistics.py +160 -0
- onedal/basic_statistics/tests/test_basic_statistics.py +298 -0
- onedal/basic_statistics/tests/test_incremental_basic_statistics.py +196 -0
- onedal/cluster/__init__.py +27 -0
- onedal/cluster/dbscan.py +110 -0
- onedal/cluster/kmeans.py +564 -0
- onedal/cluster/kmeans_init.py +115 -0
- onedal/cluster/tests/test_dbscan.py +125 -0
- onedal/cluster/tests/test_kmeans.py +88 -0
- onedal/cluster/tests/test_kmeans_init.py +93 -0
- onedal/common/_base.py +38 -0
- onedal/common/_estimator_checks.py +47 -0
- onedal/common/_mixin.py +62 -0
- onedal/common/_policy.py +59 -0
- onedal/common/_spmd_policy.py +30 -0
- onedal/common/hyperparameters.py +125 -0
- onedal/common/tests/test_policy.py +76 -0
- onedal/covariance/__init__.py +20 -0
- onedal/covariance/covariance.py +125 -0
- onedal/covariance/incremental_covariance.py +146 -0
- onedal/covariance/tests/test_covariance.py +50 -0
- onedal/covariance/tests/test_incremental_covariance.py +122 -0
- onedal/datatypes/__init__.py +19 -0
- onedal/datatypes/_data_conversion.py +154 -0
- onedal/datatypes/tests/common.py +126 -0
- onedal/datatypes/tests/test_data.py +414 -0
- onedal/decomposition/__init__.py +20 -0
- onedal/decomposition/incremental_pca.py +204 -0
- onedal/decomposition/pca.py +186 -0
- onedal/decomposition/tests/test_incremental_pca.py +198 -0
- onedal/ensemble/__init__.py +29 -0
- onedal/ensemble/forest.py +727 -0
- onedal/ensemble/tests/test_random_forest.py +97 -0
- onedal/linear_model/__init__.py +27 -0
- onedal/linear_model/incremental_linear_model.py +258 -0
- onedal/linear_model/linear_model.py +329 -0
- onedal/linear_model/logistic_regression.py +249 -0
- onedal/linear_model/tests/test_incremental_linear_regression.py +168 -0
- onedal/linear_model/tests/test_incremental_ridge_regression.py +107 -0
- onedal/linear_model/tests/test_linear_regression.py +250 -0
- onedal/linear_model/tests/test_logistic_regression.py +95 -0
- onedal/linear_model/tests/test_ridge.py +95 -0
- onedal/neighbors/__init__.py +19 -0
- onedal/neighbors/neighbors.py +767 -0
- onedal/neighbors/tests/test_knn_classification.py +49 -0
- onedal/primitives/__init__.py +27 -0
- onedal/primitives/get_tree.py +25 -0
- onedal/primitives/kernel_functions.py +153 -0
- onedal/primitives/tests/test_kernel_functions.py +159 -0
- onedal/spmd/__init__.py +25 -0
- onedal/spmd/_base.py +30 -0
- onedal/spmd/basic_statistics/__init__.py +20 -0
- onedal/spmd/basic_statistics/basic_statistics.py +30 -0
- onedal/spmd/basic_statistics/incremental_basic_statistics.py +69 -0
- onedal/spmd/cluster/__init__.py +28 -0
- onedal/spmd/cluster/dbscan.py +23 -0
- onedal/spmd/cluster/kmeans.py +56 -0
- onedal/spmd/covariance/__init__.py +20 -0
- onedal/spmd/covariance/covariance.py +26 -0
- onedal/spmd/covariance/incremental_covariance.py +82 -0
- onedal/spmd/decomposition/__init__.py +20 -0
- onedal/spmd/decomposition/incremental_pca.py +117 -0
- onedal/spmd/decomposition/pca.py +26 -0
- onedal/spmd/ensemble/__init__.py +19 -0
- onedal/spmd/ensemble/forest.py +28 -0
- onedal/spmd/linear_model/__init__.py +21 -0
- onedal/spmd/linear_model/incremental_linear_model.py +97 -0
- onedal/spmd/linear_model/linear_model.py +30 -0
- onedal/spmd/linear_model/logistic_regression.py +38 -0
- onedal/spmd/neighbors/__init__.py +19 -0
- onedal/spmd/neighbors/neighbors.py +75 -0
- onedal/svm/__init__.py +19 -0
- onedal/svm/svm.py +556 -0
- onedal/svm/tests/test_csr_svm.py +351 -0
- onedal/svm/tests/test_nusvc.py +204 -0
- onedal/svm/tests/test_nusvr.py +210 -0
- onedal/svm/tests/test_svc.py +176 -0
- onedal/svm/tests/test_svr.py +243 -0
- onedal/tests/test_common.py +57 -0
- onedal/tests/utils/_dataframes_support.py +162 -0
- onedal/tests/utils/_device_selection.py +102 -0
- onedal/utils/__init__.py +49 -0
- onedal/utils/_array_api.py +81 -0
- onedal/utils/_dpep_helpers.py +56 -0
- onedal/utils/validation.py +440 -0
- scikit_learn_intelex-2025.1.0.dist-info/LICENSE.txt +202 -0
- scikit_learn_intelex-2025.1.0.dist-info/METADATA +231 -0
- scikit_learn_intelex-2025.1.0.dist-info/RECORD +280 -0
- scikit_learn_intelex-2025.1.0.dist-info/WHEEL +5 -0
- scikit_learn_intelex-2025.1.0.dist-info/top_level.txt +3 -0
- sklearnex/__init__.py +66 -0
- sklearnex/__main__.py +58 -0
- sklearnex/_config.py +116 -0
- sklearnex/_device_offload.py +126 -0
- sklearnex/_utils.py +132 -0
- sklearnex/basic_statistics/__init__.py +20 -0
- sklearnex/basic_statistics/basic_statistics.py +230 -0
- sklearnex/basic_statistics/incremental_basic_statistics.py +345 -0
- sklearnex/basic_statistics/tests/test_basic_statistics.py +270 -0
- sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +404 -0
- sklearnex/cluster/__init__.py +20 -0
- sklearnex/cluster/dbscan.py +197 -0
- sklearnex/cluster/k_means.py +395 -0
- sklearnex/cluster/tests/test_dbscan.py +38 -0
- sklearnex/cluster/tests/test_kmeans.py +159 -0
- sklearnex/conftest.py +82 -0
- sklearnex/covariance/__init__.py +19 -0
- sklearnex/covariance/incremental_covariance.py +398 -0
- sklearnex/covariance/tests/test_incremental_covariance.py +237 -0
- sklearnex/decomposition/__init__.py +19 -0
- sklearnex/decomposition/pca.py +425 -0
- sklearnex/decomposition/tests/test_pca.py +58 -0
- sklearnex/dispatcher.py +543 -0
- sklearnex/doc/third-party-programs.txt +424 -0
- sklearnex/ensemble/__init__.py +29 -0
- sklearnex/ensemble/_forest.py +2029 -0
- sklearnex/ensemble/tests/test_forest.py +135 -0
- sklearnex/glob/__main__.py +72 -0
- sklearnex/glob/dispatcher.py +101 -0
- sklearnex/linear_model/__init__.py +32 -0
- sklearnex/linear_model/coordinate_descent.py +30 -0
- sklearnex/linear_model/incremental_linear.py +482 -0
- sklearnex/linear_model/incremental_ridge.py +425 -0
- sklearnex/linear_model/linear.py +341 -0
- sklearnex/linear_model/logistic_regression.py +413 -0
- sklearnex/linear_model/ridge.py +24 -0
- sklearnex/linear_model/tests/test_incremental_linear.py +207 -0
- sklearnex/linear_model/tests/test_incremental_ridge.py +153 -0
- sklearnex/linear_model/tests/test_linear.py +167 -0
- sklearnex/linear_model/tests/test_logreg.py +134 -0
- sklearnex/manifold/__init__.py +19 -0
- sklearnex/manifold/t_sne.py +21 -0
- sklearnex/manifold/tests/test_tsne.py +26 -0
- sklearnex/metrics/__init__.py +23 -0
- sklearnex/metrics/pairwise.py +22 -0
- sklearnex/metrics/ranking.py +20 -0
- sklearnex/metrics/tests/test_metrics.py +39 -0
- sklearnex/model_selection/__init__.py +21 -0
- sklearnex/model_selection/split.py +22 -0
- sklearnex/model_selection/tests/test_model_selection.py +34 -0
- sklearnex/neighbors/__init__.py +27 -0
- sklearnex/neighbors/_lof.py +236 -0
- sklearnex/neighbors/common.py +310 -0
- sklearnex/neighbors/knn_classification.py +231 -0
- sklearnex/neighbors/knn_regression.py +207 -0
- sklearnex/neighbors/knn_unsupervised.py +178 -0
- sklearnex/neighbors/tests/test_neighbors.py +82 -0
- sklearnex/preview/__init__.py +17 -0
- sklearnex/preview/covariance/__init__.py +19 -0
- sklearnex/preview/covariance/covariance.py +138 -0
- sklearnex/preview/covariance/tests/test_covariance.py +66 -0
- sklearnex/preview/decomposition/__init__.py +19 -0
- sklearnex/preview/decomposition/incremental_pca.py +233 -0
- sklearnex/preview/decomposition/tests/test_incremental_pca.py +266 -0
- sklearnex/preview/linear_model/__init__.py +19 -0
- sklearnex/preview/linear_model/ridge.py +424 -0
- sklearnex/preview/linear_model/tests/test_ridge.py +102 -0
- sklearnex/spmd/__init__.py +25 -0
- sklearnex/spmd/basic_statistics/__init__.py +20 -0
- sklearnex/spmd/basic_statistics/basic_statistics.py +21 -0
- sklearnex/spmd/basic_statistics/incremental_basic_statistics.py +30 -0
- sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py +107 -0
- sklearnex/spmd/basic_statistics/tests/test_incremental_basic_statistics_spmd.py +307 -0
- sklearnex/spmd/cluster/__init__.py +30 -0
- sklearnex/spmd/cluster/dbscan.py +50 -0
- sklearnex/spmd/cluster/kmeans.py +21 -0
- sklearnex/spmd/cluster/tests/test_dbscan_spmd.py +97 -0
- sklearnex/spmd/cluster/tests/test_kmeans_spmd.py +172 -0
- sklearnex/spmd/covariance/__init__.py +20 -0
- sklearnex/spmd/covariance/covariance.py +21 -0
- sklearnex/spmd/covariance/incremental_covariance.py +37 -0
- sklearnex/spmd/covariance/tests/test_covariance_spmd.py +107 -0
- sklearnex/spmd/covariance/tests/test_incremental_covariance_spmd.py +184 -0
- sklearnex/spmd/decomposition/__init__.py +20 -0
- sklearnex/spmd/decomposition/incremental_pca.py +30 -0
- sklearnex/spmd/decomposition/pca.py +21 -0
- sklearnex/spmd/decomposition/tests/test_incremental_pca_spmd.py +269 -0
- sklearnex/spmd/decomposition/tests/test_pca_spmd.py +128 -0
- sklearnex/spmd/ensemble/__init__.py +19 -0
- sklearnex/spmd/ensemble/forest.py +71 -0
- sklearnex/spmd/ensemble/tests/test_forest_spmd.py +265 -0
- sklearnex/spmd/linear_model/__init__.py +21 -0
- sklearnex/spmd/linear_model/incremental_linear_model.py +35 -0
- sklearnex/spmd/linear_model/linear_model.py +21 -0
- sklearnex/spmd/linear_model/logistic_regression.py +21 -0
- sklearnex/spmd/linear_model/tests/test_incremental_linear_spmd.py +329 -0
- sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py +145 -0
- sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py +162 -0
- sklearnex/spmd/neighbors/__init__.py +19 -0
- sklearnex/spmd/neighbors/neighbors.py +25 -0
- sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py +288 -0
- sklearnex/svm/__init__.py +29 -0
- sklearnex/svm/_common.py +339 -0
- sklearnex/svm/nusvc.py +371 -0
- sklearnex/svm/nusvr.py +170 -0
- sklearnex/svm/svc.py +399 -0
- sklearnex/svm/svr.py +167 -0
- sklearnex/svm/tests/test_svm.py +93 -0
- sklearnex/tests/test_common.py +390 -0
- sklearnex/tests/test_config.py +123 -0
- sklearnex/tests/test_memory_usage.py +379 -0
- sklearnex/tests/test_monkeypatch.py +276 -0
- sklearnex/tests/test_n_jobs_support.py +108 -0
- sklearnex/tests/test_parallel.py +48 -0
- sklearnex/tests/test_patching.py +385 -0
- sklearnex/tests/test_run_to_run_stability.py +321 -0
- sklearnex/tests/utils/__init__.py +44 -0
- sklearnex/tests/utils/base.py +371 -0
- sklearnex/tests/utils/spmd.py +198 -0
- sklearnex/utils/__init__.py +19 -0
- sklearnex/utils/_array_api.py +82 -0
- sklearnex/utils/parallel.py +59 -0
- sklearnex/utils/tests/test_finite.py +89 -0
- sklearnex/utils/validation.py +17 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2014 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 sys
|
|
18
|
+
import warnings
|
|
19
|
+
from functools import lru_cache
|
|
20
|
+
|
|
21
|
+
import sklearn.cluster as cluster_module
|
|
22
|
+
import sklearn.decomposition as decomposition_module
|
|
23
|
+
import sklearn.ensemble as ensemble_module
|
|
24
|
+
import sklearn.linear_model as linear_model_module
|
|
25
|
+
import sklearn.linear_model._logistic as logistic_module
|
|
26
|
+
import sklearn.manifold as manifold_module
|
|
27
|
+
import sklearn.neighbors as neighbors_module
|
|
28
|
+
import sklearn.svm as svm_module
|
|
29
|
+
from sklearn import metrics, model_selection
|
|
30
|
+
from sklearn.utils import validation
|
|
31
|
+
|
|
32
|
+
from daal4py.sklearn._utils import set_idp_sklearn_verbose
|
|
33
|
+
|
|
34
|
+
from ..cluster.dbscan import DBSCAN as DBSCAN_daal4py
|
|
35
|
+
from ..cluster.k_means import KMeans as KMeans_daal4py
|
|
36
|
+
from ..decomposition._pca import PCA as PCA_daal4py
|
|
37
|
+
from ..ensemble._forest import RandomForestClassifier as RandomForestClassifier_daal4py
|
|
38
|
+
from ..ensemble._forest import RandomForestRegressor as RandomForestRegressor_daal4py
|
|
39
|
+
from ..linear_model.coordinate_descent import ElasticNet as ElasticNet_daal4py
|
|
40
|
+
from ..linear_model.coordinate_descent import Lasso as Lasso_daal4py
|
|
41
|
+
from ..linear_model.linear import LinearRegression as LinearRegression_daal4py
|
|
42
|
+
from ..linear_model.logistic_path import LogisticRegression as LogisticRegression_daal4py
|
|
43
|
+
from ..linear_model.logistic_path import (
|
|
44
|
+
logistic_regression_path as daal_optimized_logistic_path,
|
|
45
|
+
)
|
|
46
|
+
from ..linear_model.ridge import Ridge as Ridge_daal4py
|
|
47
|
+
from ..manifold import TSNE as TSNE_daal4py
|
|
48
|
+
from ..metrics import pairwise_distances, roc_auc_score
|
|
49
|
+
from ..model_selection import train_test_split
|
|
50
|
+
from ..neighbors import KNeighborsClassifier as KNeighborsClassifier_daal4py
|
|
51
|
+
from ..neighbors import KNeighborsRegressor as KNeighborsRegressor_daal4py
|
|
52
|
+
from ..neighbors import NearestNeighbors as NearestNeighbors_daal4py
|
|
53
|
+
from ..svm.svm import SVC as SVC_daal4py
|
|
54
|
+
from ..utils.validation import _assert_all_finite
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@lru_cache(maxsize=None)
|
|
58
|
+
def _get_map_of_algorithms():
|
|
59
|
+
mapping = {
|
|
60
|
+
"pca": [[(decomposition_module, "PCA", PCA_daal4py), None]],
|
|
61
|
+
"kmeans": [[(cluster_module, "KMeans", KMeans_daal4py), None]],
|
|
62
|
+
"dbscan": [[(cluster_module, "DBSCAN", DBSCAN_daal4py), None]],
|
|
63
|
+
"distances": [[(metrics, "pairwise_distances", pairwise_distances), None]],
|
|
64
|
+
"linear": [
|
|
65
|
+
[(linear_model_module, "LinearRegression", LinearRegression_daal4py), None]
|
|
66
|
+
],
|
|
67
|
+
"ridge": [[(linear_model_module, "Ridge", Ridge_daal4py), None]],
|
|
68
|
+
"elasticnet": [[(linear_model_module, "ElasticNet", ElasticNet_daal4py), None]],
|
|
69
|
+
"lasso": [[(linear_model_module, "Lasso", Lasso_daal4py), None]],
|
|
70
|
+
"svm": [[(svm_module, "SVC", SVC_daal4py), None]],
|
|
71
|
+
"logistic": [
|
|
72
|
+
[
|
|
73
|
+
(
|
|
74
|
+
logistic_module,
|
|
75
|
+
"_logistic_regression_path",
|
|
76
|
+
daal_optimized_logistic_path,
|
|
77
|
+
),
|
|
78
|
+
None,
|
|
79
|
+
]
|
|
80
|
+
],
|
|
81
|
+
"log_reg": [
|
|
82
|
+
[
|
|
83
|
+
(linear_model_module, "LogisticRegression", LogisticRegression_daal4py),
|
|
84
|
+
None,
|
|
85
|
+
]
|
|
86
|
+
],
|
|
87
|
+
"knn_classifier": [
|
|
88
|
+
[
|
|
89
|
+
(neighbors_module, "KNeighborsClassifier", KNeighborsClassifier_daal4py),
|
|
90
|
+
None,
|
|
91
|
+
]
|
|
92
|
+
],
|
|
93
|
+
"nearest_neighbors": [
|
|
94
|
+
[(neighbors_module, "NearestNeighbors", NearestNeighbors_daal4py), None]
|
|
95
|
+
],
|
|
96
|
+
"knn_regressor": [
|
|
97
|
+
[(neighbors_module, "KNeighborsRegressor", KNeighborsRegressor_daal4py), None]
|
|
98
|
+
],
|
|
99
|
+
"random_forest_classifier": [
|
|
100
|
+
[
|
|
101
|
+
(
|
|
102
|
+
ensemble_module,
|
|
103
|
+
"RandomForestClassifier",
|
|
104
|
+
RandomForestClassifier_daal4py,
|
|
105
|
+
),
|
|
106
|
+
None,
|
|
107
|
+
]
|
|
108
|
+
],
|
|
109
|
+
"random_forest_regressor": [
|
|
110
|
+
[
|
|
111
|
+
(ensemble_module, "RandomForestRegressor", RandomForestRegressor_daal4py),
|
|
112
|
+
None,
|
|
113
|
+
]
|
|
114
|
+
],
|
|
115
|
+
"train_test_split": [
|
|
116
|
+
[(model_selection, "train_test_split", train_test_split), None]
|
|
117
|
+
],
|
|
118
|
+
"fin_check": [[(validation, "_assert_all_finite", _assert_all_finite), None]],
|
|
119
|
+
"roc_auc_score": [[(metrics, "roc_auc_score", roc_auc_score), None]],
|
|
120
|
+
"tsne": [[(manifold_module, "TSNE", TSNE_daal4py), None]],
|
|
121
|
+
}
|
|
122
|
+
mapping["svc"] = mapping["svm"]
|
|
123
|
+
mapping["logisticregression"] = mapping["log_reg"]
|
|
124
|
+
mapping["kneighborsclassifier"] = mapping["knn_classifier"]
|
|
125
|
+
mapping["nearestneighbors"] = mapping["nearest_neighbors"]
|
|
126
|
+
mapping["kneighborsregressor"] = mapping["knn_regressor"]
|
|
127
|
+
mapping["randomforestclassifier"] = mapping["random_forest_classifier"]
|
|
128
|
+
mapping["randomforestregressor"] = mapping["random_forest_regressor"]
|
|
129
|
+
mapping["linearregression"] = mapping["linear"]
|
|
130
|
+
mapping["logisticregression"] = mapping["log_reg"]
|
|
131
|
+
mapping["_logistic_regression_path"] = mapping["logistic"]
|
|
132
|
+
mapping["_assert_all_finite"] = mapping["fin_check"]
|
|
133
|
+
mapping["pairwise_distances"] = mapping["distances"]
|
|
134
|
+
return mapping
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def do_patch(name, get_map=_get_map_of_algorithms):
|
|
138
|
+
lname = name.lower()
|
|
139
|
+
if lname in get_map():
|
|
140
|
+
for descriptor in get_map()[lname]:
|
|
141
|
+
which, what, replacer = descriptor[0]
|
|
142
|
+
if descriptor[1] is None:
|
|
143
|
+
descriptor[1] = getattr(which, what, False)
|
|
144
|
+
setattr(which, what, replacer)
|
|
145
|
+
else:
|
|
146
|
+
raise ValueError("Has no patch for: " + name)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def do_unpatch(name, get_map=_get_map_of_algorithms):
|
|
150
|
+
lname = name.lower()
|
|
151
|
+
if lname in get_map():
|
|
152
|
+
for descriptor in get_map()[lname]:
|
|
153
|
+
if descriptor[1] is not None:
|
|
154
|
+
which, what, _ = descriptor[0]
|
|
155
|
+
if descriptor[1]:
|
|
156
|
+
setattr(which, what, descriptor[1])
|
|
157
|
+
elif hasattr(which, what):
|
|
158
|
+
delattr(which, what)
|
|
159
|
+
else:
|
|
160
|
+
raise ValueError("Has no patch for: " + name)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def enable(name=None, verbose=True, deprecation=True, get_map=_get_map_of_algorithms):
|
|
164
|
+
if name is not None:
|
|
165
|
+
do_patch(name, get_map)
|
|
166
|
+
else:
|
|
167
|
+
for key in get_map():
|
|
168
|
+
do_patch(key, get_map)
|
|
169
|
+
if deprecation:
|
|
170
|
+
set_idp_sklearn_verbose()
|
|
171
|
+
warnings.warn_explicit(
|
|
172
|
+
"\nScikit-learn patching with daal4py is deprecated "
|
|
173
|
+
"and will be removed in the future.\n"
|
|
174
|
+
"Use Intel(R) Extension "
|
|
175
|
+
"for Scikit-learn* module instead "
|
|
176
|
+
"(pip install scikit-learn-intelex).\n"
|
|
177
|
+
"To enable patching, please use one of the "
|
|
178
|
+
"following options:\n"
|
|
179
|
+
"1) From the command line:\n"
|
|
180
|
+
" python -m sklearnex <your_script>\n"
|
|
181
|
+
"2) From your script:\n"
|
|
182
|
+
" from sklearnex import patch_sklearn\n"
|
|
183
|
+
" patch_sklearn()",
|
|
184
|
+
FutureWarning,
|
|
185
|
+
"dispatcher.py",
|
|
186
|
+
151,
|
|
187
|
+
)
|
|
188
|
+
if verbose and deprecation and sys.stderr is not None:
|
|
189
|
+
sys.stderr.write(
|
|
190
|
+
"Intel(R) oneAPI Data Analytics Library solvers for sklearn enabled: "
|
|
191
|
+
"https://intelpython.github.io/daal4py/sklearn.html\n"
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def disable(name=None, get_map=_get_map_of_algorithms):
|
|
196
|
+
if name is not None:
|
|
197
|
+
do_unpatch(name, get_map)
|
|
198
|
+
else:
|
|
199
|
+
for key in get_map():
|
|
200
|
+
do_unpatch(key, get_map)
|
|
201
|
+
get_map.cache_clear()
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def _is_enabled(name, get_map=_get_map_of_algorithms):
|
|
205
|
+
lname = name.lower()
|
|
206
|
+
if lname in get_map():
|
|
207
|
+
enabled = True
|
|
208
|
+
for descriptor in get_map()[lname]:
|
|
209
|
+
which, what, replacer = descriptor[0]
|
|
210
|
+
enabled = enabled and getattr(which, what, None) == replacer
|
|
211
|
+
return enabled
|
|
212
|
+
else:
|
|
213
|
+
raise ValueError("Has no patch for: " + name)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def patch_is_enabled(name=None, get_map=_get_map_of_algorithms, return_map=False):
|
|
217
|
+
if name is not None:
|
|
218
|
+
return _is_enabled(name, get_map)
|
|
219
|
+
else:
|
|
220
|
+
if return_map:
|
|
221
|
+
enabled = {}
|
|
222
|
+
for key in get_map():
|
|
223
|
+
enabled[key] = _is_enabled(key, get_map)
|
|
224
|
+
else:
|
|
225
|
+
enabled = True
|
|
226
|
+
for key in get_map():
|
|
227
|
+
enabled = enabled and _is_enabled(key, get_map)
|
|
228
|
+
return enabled
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _patch_names():
|
|
232
|
+
return list(_get_map_of_algorithms().keys())
|
|
@@ -0,0 +1,161 @@
|
|
|
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 KNeighborsClassifier, KNeighborsRegressor, NearestNeighbors
|
|
31
|
+
from sklearn.svm import SVC
|
|
32
|
+
|
|
33
|
+
from daal4py.sklearn._utils import daal_check_version
|
|
34
|
+
|
|
35
|
+
MODELS_INFO = [
|
|
36
|
+
{
|
|
37
|
+
"model": KNeighborsClassifier(algorithm="brute"),
|
|
38
|
+
"methods": ["kneighbors", "predict", "predict_proba", "score"],
|
|
39
|
+
"dataset": "classifier",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"model": KNeighborsRegressor(algorithm="brute"),
|
|
43
|
+
"methods": ["kneighbors", "predict", "score"],
|
|
44
|
+
"dataset": "regression",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"model": NearestNeighbors(algorithm="brute"),
|
|
48
|
+
"methods": ["kneighbors"],
|
|
49
|
+
"dataset": "blobs",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"model": DBSCAN(),
|
|
53
|
+
"methods": ["fit_predict"],
|
|
54
|
+
"dataset": "blobs",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"model": SVC(probability=True),
|
|
58
|
+
"methods": ["decision_function", "predict", "predict_proba", "score"],
|
|
59
|
+
"dataset": "classifier",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"model": KMeans(),
|
|
63
|
+
"methods": ["fit_predict", "fit_transform", "transform", "predict", "score"],
|
|
64
|
+
"dataset": "blobs",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"model": ElasticNet(),
|
|
68
|
+
"methods": ["predict", "score"],
|
|
69
|
+
"dataset": "regression",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"model": Lasso(),
|
|
73
|
+
"methods": ["predict", "score"],
|
|
74
|
+
"dataset": "regression",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"model": PCA(),
|
|
78
|
+
"methods": ["fit_transform", "transform", "score"],
|
|
79
|
+
"dataset": "classifier",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"model": RandomForestClassifier(n_estimators=10),
|
|
83
|
+
"methods": ["predict", "predict_proba", "predict_log_proba", "score"],
|
|
84
|
+
"dataset": "classifier",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"model": LogisticRegression(max_iter=100, multi_class="multinomial"),
|
|
88
|
+
"methods": [
|
|
89
|
+
"decision_function",
|
|
90
|
+
"predict",
|
|
91
|
+
"predict_proba",
|
|
92
|
+
"predict_log_proba",
|
|
93
|
+
"score",
|
|
94
|
+
],
|
|
95
|
+
"dataset": "classifier",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"model": LogisticRegressionCV(max_iter=100),
|
|
99
|
+
"methods": [
|
|
100
|
+
"decision_function",
|
|
101
|
+
"predict",
|
|
102
|
+
"predict_proba",
|
|
103
|
+
"predict_log_proba",
|
|
104
|
+
"score",
|
|
105
|
+
],
|
|
106
|
+
"dataset": "classifier",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"model": RandomForestRegressor(n_estimators=10),
|
|
110
|
+
"methods": ["predict", "score"],
|
|
111
|
+
"dataset": "regression",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"model": LinearRegression(),
|
|
115
|
+
"methods": ["predict", "score"],
|
|
116
|
+
"dataset": "regression",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"model": Ridge(),
|
|
120
|
+
"methods": ["predict", "score"],
|
|
121
|
+
"dataset": "regression",
|
|
122
|
+
},
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
TYPES = [
|
|
126
|
+
np.int8,
|
|
127
|
+
np.int16,
|
|
128
|
+
np.int32,
|
|
129
|
+
np.int64,
|
|
130
|
+
np.float16,
|
|
131
|
+
np.float32,
|
|
132
|
+
np.float64,
|
|
133
|
+
np.uint8,
|
|
134
|
+
np.uint16,
|
|
135
|
+
np.uint32,
|
|
136
|
+
np.uint64,
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
TO_SKIP = [
|
|
140
|
+
# --------------- NO INFO ---------------
|
|
141
|
+
r"KMeans .*transform",
|
|
142
|
+
r"KMeans .*score",
|
|
143
|
+
r"PCA .*score",
|
|
144
|
+
r"LogisticRegression .*decision_function",
|
|
145
|
+
r"LogisticRegressionCV .*decision_function",
|
|
146
|
+
r"LogisticRegressionCV .*predict",
|
|
147
|
+
r"LogisticRegressionCV .*predict_proba",
|
|
148
|
+
r"LogisticRegressionCV .*predict_log_proba",
|
|
149
|
+
r"LogisticRegressionCV .*score",
|
|
150
|
+
# --------------- Scikit ---------------
|
|
151
|
+
r"Ridge float16 predict",
|
|
152
|
+
r"Ridge float16 score",
|
|
153
|
+
r"RandomForestClassifier .*predict_proba",
|
|
154
|
+
r"RandomForestClassifier .*predict_log_proba",
|
|
155
|
+
r"pairwise_distances .*pairwise_distances", # except float64
|
|
156
|
+
(
|
|
157
|
+
r"roc_auc_score .*roc_auc_score"
|
|
158
|
+
if not daal_check_version((2021, "P", 200))
|
|
159
|
+
else None
|
|
160
|
+
),
|
|
161
|
+
]
|
|
@@ -0,0 +1,71 @@
|
|
|
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 daal4py.sklearn
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_monkey_patching():
|
|
21
|
+
_tokens = daal4py.sklearn.sklearn_patch_names()
|
|
22
|
+
_values = daal4py.sklearn.sklearn_patch_map().values()
|
|
23
|
+
_classes = list()
|
|
24
|
+
for v in _values:
|
|
25
|
+
_classes.append(v[0][0])
|
|
26
|
+
|
|
27
|
+
assert len(_tokens) == len(_classes)
|
|
28
|
+
assert (
|
|
29
|
+
isinstance(_tokens, list) and len(_tokens) > 0
|
|
30
|
+
), "Internal Error: list of patched names has unexcepable format."
|
|
31
|
+
|
|
32
|
+
daal4py.sklearn.patch_sklearn()
|
|
33
|
+
|
|
34
|
+
for i, _ in enumerate(_tokens):
|
|
35
|
+
t = _tokens[i]
|
|
36
|
+
p = _classes[i][0]
|
|
37
|
+
n = _classes[i][1]
|
|
38
|
+
|
|
39
|
+
class_module = getattr(p, n).__module__
|
|
40
|
+
assert class_module.startswith("daal4py"), "Patching has completed with error."
|
|
41
|
+
|
|
42
|
+
for i, _ in enumerate(_tokens):
|
|
43
|
+
t = _tokens[i]
|
|
44
|
+
p = _classes[i][0]
|
|
45
|
+
n = _classes[i][1]
|
|
46
|
+
|
|
47
|
+
daal4py.sklearn.unpatch_sklearn(t)
|
|
48
|
+
class_module = getattr(p, n).__module__
|
|
49
|
+
assert class_module.startswith("sklearn"), "Unpatching has completed with error."
|
|
50
|
+
|
|
51
|
+
daal4py.sklearn.unpatch_sklearn()
|
|
52
|
+
|
|
53
|
+
for i, _ in enumerate(_tokens):
|
|
54
|
+
t = _tokens[i]
|
|
55
|
+
p = _classes[i][0]
|
|
56
|
+
n = _classes[i][1]
|
|
57
|
+
|
|
58
|
+
class_module = getattr(p, n).__module__
|
|
59
|
+
assert class_module.startswith("sklearn"), "Unpatching has completed with error."
|
|
60
|
+
|
|
61
|
+
for i, _ in enumerate(_tokens):
|
|
62
|
+
t = _tokens[i]
|
|
63
|
+
p = _classes[i][0]
|
|
64
|
+
n = _classes[i][1]
|
|
65
|
+
|
|
66
|
+
daal4py.sklearn.patch_sklearn(t)
|
|
67
|
+
|
|
68
|
+
class_module = getattr(p, n).__module__
|
|
69
|
+
assert class_module.startswith("daal4py"), "Patching has completed with error."
|
|
70
|
+
|
|
71
|
+
daal4py.sklearn.unpatch_sklearn()
|
|
@@ -0,0 +1,90 @@
|
|
|
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 os
|
|
18
|
+
import pathlib
|
|
19
|
+
import re
|
|
20
|
+
import subprocess
|
|
21
|
+
import sys
|
|
22
|
+
|
|
23
|
+
import pytest
|
|
24
|
+
from _models_info import TO_SKIP
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def get_branch(s):
|
|
28
|
+
if len(s) == 0:
|
|
29
|
+
return "NO INFO"
|
|
30
|
+
for i in s:
|
|
31
|
+
if "failed to run accelerated version, fallback to original Scikit-learn" in i:
|
|
32
|
+
return "was in OPT, but go in Scikit"
|
|
33
|
+
for i in s:
|
|
34
|
+
if "running accelerated version" in i:
|
|
35
|
+
return "OPT"
|
|
36
|
+
return "Scikit"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def run_parse(mas, result):
|
|
40
|
+
name, dtype = mas[0].split()
|
|
41
|
+
temp = []
|
|
42
|
+
INFO_POS = 6
|
|
43
|
+
for i in range(1, len(mas)):
|
|
44
|
+
mas[i] = mas[i][INFO_POS:] # remove 'INFO: '
|
|
45
|
+
if not mas[i].startswith("sklearn"):
|
|
46
|
+
ind = name + " " + dtype + " " + mas[i]
|
|
47
|
+
result[ind] = get_branch(temp)
|
|
48
|
+
temp.clear()
|
|
49
|
+
else:
|
|
50
|
+
temp.append(mas[i])
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def get_result_log():
|
|
54
|
+
os.environ["IDP_SKLEARN_VERBOSE"] = "INFO"
|
|
55
|
+
absolute_path = str(pathlib.Path(__file__).parent.absolute())
|
|
56
|
+
try:
|
|
57
|
+
process = subprocess.check_output(
|
|
58
|
+
[
|
|
59
|
+
sys.executable,
|
|
60
|
+
os.sep.join([absolute_path, "utils", "_launch_algorithms.py"]),
|
|
61
|
+
]
|
|
62
|
+
)
|
|
63
|
+
except subprocess.CalledProcessError as e:
|
|
64
|
+
print(e)
|
|
65
|
+
exit(1)
|
|
66
|
+
|
|
67
|
+
mas = []
|
|
68
|
+
result = {}
|
|
69
|
+
for i in process.decode().split("\n"):
|
|
70
|
+
if not i.startswith("INFO") and len(mas) != 0:
|
|
71
|
+
run_parse(mas, result)
|
|
72
|
+
mas.clear()
|
|
73
|
+
mas.append(i.strip())
|
|
74
|
+
else:
|
|
75
|
+
mas.append(i.strip())
|
|
76
|
+
del os.environ["IDP_SKLEARN_VERBOSE"]
|
|
77
|
+
return result
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
result_log = get_result_log()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@pytest.mark.parametrize("configuration", result_log)
|
|
84
|
+
def test_patching(configuration):
|
|
85
|
+
if "OPT" in result_log[configuration]:
|
|
86
|
+
return
|
|
87
|
+
for skip in TO_SKIP:
|
|
88
|
+
if re.search(skip, configuration) is not None:
|
|
89
|
+
pytest.skip("SKIPPED", allow_module_level=False)
|
|
90
|
+
raise ValueError("Test patching failed: " + configuration)
|
|
@@ -0,0 +1,117 @@
|
|
|
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 daal4py.sklearn 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
|
+
sys.path.append(str(pathlib.Path(__file__).parent.parent.absolute()))
|
|
33
|
+
from _models_info import MODELS_INFO, TYPES
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_class_name(x):
|
|
37
|
+
return x.__class__.__name__
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def generate_dataset(name, dtype, model_name):
|
|
41
|
+
if model_name == "LinearRegression":
|
|
42
|
+
X, y = make_regression(n_samples=1000, n_features=5)
|
|
43
|
+
elif name in ["blobs", "classifier"]:
|
|
44
|
+
X, y = load_iris(return_X_y=True)
|
|
45
|
+
elif name == "regression":
|
|
46
|
+
X, y = load_diabetes(return_X_y=True)
|
|
47
|
+
else:
|
|
48
|
+
raise ValueError("Unknown dataset type")
|
|
49
|
+
X = np.array(X, dtype=dtype)
|
|
50
|
+
y = np.array(y, dtype=dtype)
|
|
51
|
+
return (X, y)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def run_patch(model_info, dtype):
|
|
55
|
+
print(get_class_name(model_info["model"]), dtype.__name__)
|
|
56
|
+
X, y = generate_dataset(
|
|
57
|
+
model_info["dataset"], dtype, get_class_name(model_info["model"])
|
|
58
|
+
)
|
|
59
|
+
model = model_info["model"]
|
|
60
|
+
model.fit(X, y)
|
|
61
|
+
logging.info("fit")
|
|
62
|
+
for i in model_info["methods"]:
|
|
63
|
+
if i == "predict":
|
|
64
|
+
model.predict(X)
|
|
65
|
+
elif i == "predict_proba":
|
|
66
|
+
model.predict_proba(X)
|
|
67
|
+
elif i == "predict_log_proba":
|
|
68
|
+
model.predict_log_proba(X)
|
|
69
|
+
elif i == "decision_function":
|
|
70
|
+
model.decision_function(X)
|
|
71
|
+
elif i == "fit_predict":
|
|
72
|
+
model.fit_predict(X)
|
|
73
|
+
elif i == "transform":
|
|
74
|
+
model.transform(X)
|
|
75
|
+
elif i == "fit_transform":
|
|
76
|
+
model.fit_transform(X)
|
|
77
|
+
elif i == "kneighbors":
|
|
78
|
+
model.kneighbors(X)
|
|
79
|
+
elif i == "score":
|
|
80
|
+
model.score(X, y)
|
|
81
|
+
else:
|
|
82
|
+
raise ValueError(i + " is wrong method")
|
|
83
|
+
logging.info(i)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def run_algorithms():
|
|
87
|
+
for info in MODELS_INFO:
|
|
88
|
+
for t in TYPES:
|
|
89
|
+
model_name = get_class_name(info["model"])
|
|
90
|
+
if model_name in ["Ridge", "LinearRegression"] and t.__name__ == "uint32":
|
|
91
|
+
continue
|
|
92
|
+
run_patch(info, t)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def run_utils():
|
|
96
|
+
# pairwise_distances
|
|
97
|
+
for metric in ["cosine", "correlation"]:
|
|
98
|
+
for t in TYPES:
|
|
99
|
+
X = np.random.rand(1000)
|
|
100
|
+
X = np.array(X, dtype=t)
|
|
101
|
+
print("pairwise_distances", t.__name__)
|
|
102
|
+
_ = pairwise_distances(X.reshape(1, -1), metric=metric)
|
|
103
|
+
logging.info("pairwise_distances")
|
|
104
|
+
# roc_auc_score
|
|
105
|
+
for t in [np.float32, np.float64]:
|
|
106
|
+
a = [random.randint(0, 1) for i in range(1000)]
|
|
107
|
+
b = [random.randint(0, 1) for i in range(1000)]
|
|
108
|
+
a = np.array(a, dtype=t)
|
|
109
|
+
b = np.array(b, dtype=t)
|
|
110
|
+
print("roc_auc_score", t.__name__)
|
|
111
|
+
_ = roc_auc_score(a, b)
|
|
112
|
+
logging.info("roc_auc_score")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if __name__ == "__main__":
|
|
116
|
+
run_algorithms()
|
|
117
|
+
run_utils()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2014 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 ._classification import KNeighborsClassifier
|
|
18
|
+
from ._regression import KNeighborsRegressor
|
|
19
|
+
from ._unsupervised import NearestNeighbors
|
|
20
|
+
|
|
21
|
+
__all__ = ["KNeighborsClassifier", "NearestNeighbors", "KNeighborsRegressor"]
|