scikit-learn-intelex 2025.0.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 +242 -0
- daal4py/sklearn/_utils.py +241 -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 +192 -0
- daal4py/sklearn/ensemble/GBTDAAL.py +318 -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 +196 -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 +155 -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 +87 -0
- daal4py/sklearn/monkeypatch/tests/utils/_launch_algorithms.py +118 -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 +53 -0
- onedal/_device_offload.py +229 -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 +560 -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 +116 -0
- onedal/common/tests/test_policy.py +75 -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 +95 -0
- onedal/datatypes/tests/test_data.py +235 -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 +720 -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 +149 -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 +778 -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 +168 -0
- onedal/svm/tests/test_svr.py +243 -0
- onedal/tests/test_common.py +41 -0
- onedal/tests/utils/_dataframes_support.py +168 -0
- onedal/tests/utils/_device_selection.py +107 -0
- onedal/utils/__init__.py +49 -0
- onedal/utils/_array_api.py +91 -0
- onedal/utils/validation.py +432 -0
- scikit_learn_intelex-2025.0.0.dist-info/LICENSE.txt +202 -0
- scikit_learn_intelex-2025.0.0.dist-info/METADATA +231 -0
- scikit_learn_intelex-2025.0.0.dist-info/RECORD +278 -0
- scikit_learn_intelex-2025.0.0.dist-info/WHEEL +5 -0
- scikit_learn_intelex-2025.0.0.dist-info/top_level.txt +3 -0
- sklearnex/__init__.py +65 -0
- sklearnex/__main__.py +58 -0
- sklearnex/_config.py +98 -0
- sklearnex/_device_offload.py +121 -0
- sklearnex/_utils.py +109 -0
- sklearnex/basic_statistics/__init__.py +20 -0
- sklearnex/basic_statistics/basic_statistics.py +140 -0
- sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
- sklearnex/basic_statistics/tests/test_basic_statistics.py +251 -0
- sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +384 -0
- sklearnex/cluster/__init__.py +20 -0
- sklearnex/cluster/dbscan.py +192 -0
- sklearnex/cluster/k_means.py +383 -0
- sklearnex/cluster/tests/test_dbscan.py +38 -0
- sklearnex/cluster/tests/test_kmeans.py +153 -0
- sklearnex/conftest.py +73 -0
- sklearnex/covariance/__init__.py +19 -0
- sklearnex/covariance/incremental_covariance.py +368 -0
- sklearnex/covariance/tests/test_incremental_covariance.py +226 -0
- sklearnex/decomposition/__init__.py +19 -0
- sklearnex/decomposition/pca.py +414 -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 +2016 -0
- sklearnex/ensemble/tests/test_forest.py +120 -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 +463 -0
- sklearnex/linear_model/incremental_ridge.py +418 -0
- sklearnex/linear_model/linear.py +302 -0
- sklearnex/linear_model/logistic_path.py +17 -0
- sklearnex/linear_model/logistic_regression.py +403 -0
- sklearnex/linear_model/ridge.py +24 -0
- sklearnex/linear_model/tests/test_incremental_linear.py +203 -0
- sklearnex/linear_model/tests/test_incremental_ridge.py +153 -0
- sklearnex/linear_model/tests/test_linear.py +142 -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 +231 -0
- sklearnex/neighbors/common.py +310 -0
- sklearnex/neighbors/knn_classification.py +226 -0
- sklearnex/neighbors/knn_regression.py +203 -0
- sklearnex/neighbors/knn_unsupervised.py +170 -0
- sklearnex/neighbors/tests/test_neighbors.py +80 -0
- sklearnex/preview/__init__.py +17 -0
- sklearnex/preview/covariance/__init__.py +19 -0
- sklearnex/preview/covariance/covariance.py +133 -0
- sklearnex/preview/covariance/tests/test_covariance.py +66 -0
- sklearnex/preview/decomposition/__init__.py +19 -0
- sklearnex/preview/decomposition/incremental_pca.py +228 -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 +419 -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 +166 -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 +328 -0
- sklearnex/svm/nusvc.py +332 -0
- sklearnex/svm/nusvr.py +148 -0
- sklearnex/svm/svc.py +360 -0
- sklearnex/svm/svr.py +149 -0
- sklearnex/svm/tests/test_svm.py +93 -0
- sklearnex/tests/_utils.py +328 -0
- sklearnex/tests/_utils_spmd.py +198 -0
- sklearnex/tests/test_common.py +54 -0
- sklearnex/tests/test_config.py +43 -0
- sklearnex/tests/test_memory_usage.py +291 -0
- sklearnex/tests/test_monkeypatch.py +276 -0
- sklearnex/tests/test_n_jobs_support.py +103 -0
- sklearnex/tests/test_parallel.py +48 -0
- sklearnex/tests/test_patching.py +385 -0
- sklearnex/tests/test_run_to_run_stability.py +296 -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,206 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2020 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
import random
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
import pytest
|
|
21
|
+
from sklearn.datasets import load_iris
|
|
22
|
+
from sklearn.ensemble import RandomForestClassifier as ScikitRandomForestClassifier
|
|
23
|
+
from sklearn.ensemble import RandomForestRegressor as ScikitRandomForestRegressor
|
|
24
|
+
from sklearn.metrics import accuracy_score, log_loss, mean_squared_error, roc_auc_score
|
|
25
|
+
from sklearn.model_selection import train_test_split
|
|
26
|
+
|
|
27
|
+
from daal4py.sklearn._utils import daal_check_version
|
|
28
|
+
from daal4py.sklearn.ensemble import RandomForestClassifier as DaalRandomForestClassifier
|
|
29
|
+
from daal4py.sklearn.ensemble import RandomForestRegressor as DaalRandomForestRegressor
|
|
30
|
+
|
|
31
|
+
ACCURACY_RATIO = 0.95 if daal_check_version((2021, "P", 400)) else 0.85
|
|
32
|
+
MSE_RATIO = 1.07
|
|
33
|
+
LOG_LOSS_RATIO = 1.55
|
|
34
|
+
ROC_AUC_RATIO = 0.96
|
|
35
|
+
RNG = np.random.RandomState(0)
|
|
36
|
+
IRIS = load_iris()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _compare_with_sklearn_classifier_iris(
|
|
40
|
+
n_estimators=99, class_weight=None, sample_weight=None, description=""
|
|
41
|
+
):
|
|
42
|
+
x_train, x_test, y_train, y_test = train_test_split(
|
|
43
|
+
IRIS.data, IRIS.target, test_size=0.33, random_state=31
|
|
44
|
+
)
|
|
45
|
+
# models
|
|
46
|
+
scikit_model = ScikitRandomForestClassifier(
|
|
47
|
+
n_estimators=n_estimators,
|
|
48
|
+
class_weight=class_weight,
|
|
49
|
+
max_depth=None,
|
|
50
|
+
random_state=777,
|
|
51
|
+
)
|
|
52
|
+
daal4py_model = DaalRandomForestClassifier(
|
|
53
|
+
n_estimators=n_estimators,
|
|
54
|
+
class_weight=class_weight,
|
|
55
|
+
max_depth=None,
|
|
56
|
+
random_state=777,
|
|
57
|
+
)
|
|
58
|
+
# training
|
|
59
|
+
scikit_model.fit(x_train, y_train, sample_weight=sample_weight)
|
|
60
|
+
daal4py_model.fit(x_train, y_train, sample_weight=sample_weight)
|
|
61
|
+
# predict
|
|
62
|
+
scikit_predict = scikit_model.predict(x_test)
|
|
63
|
+
daal4py_predict = daal4py_model.predict(x_test)
|
|
64
|
+
# accuracy
|
|
65
|
+
scikit_accuracy = accuracy_score(scikit_predict, y_test)
|
|
66
|
+
daal4py_accuracy = accuracy_score(daal4py_predict, y_test)
|
|
67
|
+
ratio = daal4py_accuracy / scikit_accuracy
|
|
68
|
+
reason = (
|
|
69
|
+
description
|
|
70
|
+
+ f"scikit_accuracy={scikit_accuracy}, daal4py_accuracy={daal4py_accuracy}"
|
|
71
|
+
)
|
|
72
|
+
assert ratio >= ACCURACY_RATIO, reason
|
|
73
|
+
|
|
74
|
+
# predict_proba
|
|
75
|
+
scikit_predict_proba = scikit_model.predict_proba(x_test)
|
|
76
|
+
daal4py_predict_proba = daal4py_model.predict_proba(x_test)
|
|
77
|
+
# log_loss
|
|
78
|
+
scikit_log_loss = log_loss(y_test, scikit_predict_proba)
|
|
79
|
+
daal4py_log_loss = log_loss(y_test, daal4py_predict_proba)
|
|
80
|
+
ratio = daal4py_log_loss / scikit_log_loss
|
|
81
|
+
|
|
82
|
+
reason = (
|
|
83
|
+
description
|
|
84
|
+
+ f"scikit_log_loss={scikit_log_loss}, daal4py_log_loss={daal4py_log_loss}"
|
|
85
|
+
)
|
|
86
|
+
assert ratio <= LOG_LOSS_RATIO, reason
|
|
87
|
+
|
|
88
|
+
# ROC AUC
|
|
89
|
+
scikit_roc_auc = roc_auc_score(y_test, scikit_predict_proba, multi_class="ovr")
|
|
90
|
+
daal4py_roc_auc = roc_auc_score(y_test, daal4py_predict_proba, multi_class="ovr")
|
|
91
|
+
ratio = daal4py_roc_auc / scikit_roc_auc
|
|
92
|
+
|
|
93
|
+
reason = (
|
|
94
|
+
description
|
|
95
|
+
+ f"scikit_roc_auc={scikit_roc_auc}, daal4py_roc_auc={daal4py_roc_auc}"
|
|
96
|
+
)
|
|
97
|
+
assert ratio >= ROC_AUC_RATIO, reason
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
CLASS_WEIGHTS_IRIS = [
|
|
101
|
+
{0: 0, 1: 1, 2: 1},
|
|
102
|
+
{0: 1, 1: 2, 2: 3},
|
|
103
|
+
{0: 10, 1: 5, 2: 4},
|
|
104
|
+
{
|
|
105
|
+
0: RNG.uniform(1, 50),
|
|
106
|
+
1: RNG.uniform(1, 50),
|
|
107
|
+
2: RNG.uniform(1, 50),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
0: RNG.uniform(1, 1000),
|
|
111
|
+
1: RNG.uniform(1, 1000),
|
|
112
|
+
2: RNG.uniform(1, 1000),
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
0: RNG.uniform(1, 10),
|
|
116
|
+
1: RNG.uniform(50, 100),
|
|
117
|
+
2: RNG.uniform(1, 100),
|
|
118
|
+
},
|
|
119
|
+
{0: 50, 1: 50, 2: 50},
|
|
120
|
+
"balanced",
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@pytest.mark.parametrize("class_weight", CLASS_WEIGHTS_IRIS)
|
|
125
|
+
def test_classifier_class_weight_iris(class_weight):
|
|
126
|
+
_compare_with_sklearn_classifier_iris(
|
|
127
|
+
class_weight=class_weight, description="Classifier class weight: "
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
SAMPLE_WEIGHTS_IRIS = [
|
|
132
|
+
(np.full_like(range(100), 1), "Only 1"),
|
|
133
|
+
(np.full_like(range(100), 50), "Only 50"),
|
|
134
|
+
(RNG.rand(100), "Uniform distribution"),
|
|
135
|
+
(RNG.normal(1000, 10, 100), "Gaussian distribution"),
|
|
136
|
+
(RNG.poisson(lam=10, size=100), "Poisson distribution"),
|
|
137
|
+
(RNG.rayleigh(scale=1, size=100), "Rayleigh distribution"),
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@pytest.mark.parametrize("sample_weight", SAMPLE_WEIGHTS_IRIS)
|
|
142
|
+
def test_classifier_sample_weight_iris(sample_weight):
|
|
143
|
+
sample_weight, description = sample_weight
|
|
144
|
+
_compare_with_sklearn_classifier_iris(
|
|
145
|
+
sample_weight=sample_weight,
|
|
146
|
+
description=f"Classifier sample_weight_type={description}: ",
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
N_ESTIMATORS_IRIS = [
|
|
151
|
+
1000,
|
|
152
|
+
8000,
|
|
153
|
+
]
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@pytest.mark.parametrize("n_estimators", N_ESTIMATORS_IRIS)
|
|
157
|
+
def test_classifier_big_estimators_iris(n_estimators):
|
|
158
|
+
_compare_with_sklearn_classifier_iris(
|
|
159
|
+
n_estimators=n_estimators, description=f"Classifier n_estimators={n_estimators}: "
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _compare_with_sklearn_mse_regressor_iris(
|
|
164
|
+
n_estimators=99, sample_weight=None, description=""
|
|
165
|
+
):
|
|
166
|
+
x_train, x_test, y_train, y_test = train_test_split(
|
|
167
|
+
IRIS.data, IRIS.target, test_size=0.33, random_state=31
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
scikit_model = ScikitRandomForestRegressor(
|
|
171
|
+
n_estimators=n_estimators, max_depth=None, random_state=777
|
|
172
|
+
)
|
|
173
|
+
daal4py_model = DaalRandomForestRegressor(
|
|
174
|
+
n_estimators=n_estimators, max_depth=None, random_state=777
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
scikit_predict = scikit_model.fit(
|
|
178
|
+
x_train, y_train, sample_weight=sample_weight
|
|
179
|
+
).predict(x_test)
|
|
180
|
+
daal4py_predict = daal4py_model.fit(
|
|
181
|
+
x_train, y_train, sample_weight=sample_weight
|
|
182
|
+
).predict(x_test)
|
|
183
|
+
|
|
184
|
+
scikit_mse = mean_squared_error(scikit_predict, y_test)
|
|
185
|
+
daal4py_mse = mean_squared_error(daal4py_predict, y_test)
|
|
186
|
+
|
|
187
|
+
ratio = daal4py_mse / scikit_mse
|
|
188
|
+
reason = description + f"scikit_mse={scikit_mse}, daal4py_mse={daal4py_mse}"
|
|
189
|
+
assert ratio <= MSE_RATIO, reason
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@pytest.mark.parametrize("weight", SAMPLE_WEIGHTS_IRIS)
|
|
193
|
+
def test_mse_regressor_sample_weight_iris(weight):
|
|
194
|
+
sample_weight, description = weight
|
|
195
|
+
_compare_with_sklearn_mse_regressor_iris(
|
|
196
|
+
sample_weight=sample_weight,
|
|
197
|
+
description=f"Regression sample weights: sample_weight_type={description}: ",
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
@pytest.mark.parametrize("n_estimators", N_ESTIMATORS_IRIS)
|
|
202
|
+
def test_mse_regressor_big_estimators_iris(n_estimators):
|
|
203
|
+
_compare_with_sklearn_mse_regressor_iris(
|
|
204
|
+
n_estimators=n_estimators,
|
|
205
|
+
description=f"Regression: n_estimators={n_estimators}: ",
|
|
206
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
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 .coordinate_descent import ElasticNet, Lasso
|
|
18
|
+
from .linear import LinearRegression
|
|
19
|
+
from .logistic_path import LogisticRegression, logistic_regression_path
|
|
20
|
+
from .ridge import Ridge
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"Ridge",
|
|
24
|
+
"LinearRegression",
|
|
25
|
+
"LogisticRegression",
|
|
26
|
+
"logistic_regression_path",
|
|
27
|
+
"ElasticNet",
|
|
28
|
+
"Lasso",
|
|
29
|
+
]
|