scikit-learn-intelex 2025.0.0__py312-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-312-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-312-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-312-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_host.cpython-312-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_spmd_dpc.cpython-312-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,97 @@
|
|
|
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 pytest
|
|
18
|
+
from numpy.testing import assert_allclose
|
|
19
|
+
from sklearn.datasets import make_classification, make_regression
|
|
20
|
+
|
|
21
|
+
from daal4py.sklearn._utils import daal_check_version
|
|
22
|
+
from onedal.ensemble import RandomForestClassifier, RandomForestRegressor
|
|
23
|
+
from onedal.tests.utils._device_selection import get_queues
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.mark.parametrize("queue", get_queues())
|
|
27
|
+
def test_rf_classifier(queue):
|
|
28
|
+
X, y = make_classification(
|
|
29
|
+
n_samples=100,
|
|
30
|
+
n_features=4,
|
|
31
|
+
n_informative=2,
|
|
32
|
+
n_redundant=0,
|
|
33
|
+
random_state=0,
|
|
34
|
+
shuffle=False,
|
|
35
|
+
)
|
|
36
|
+
rf = RandomForestClassifier(max_depth=2, random_state=0).fit(X, y, queue=queue)
|
|
37
|
+
assert_allclose([1], rf.predict([[0, 0, 0, 0]], queue=queue))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@pytest.mark.parametrize("queue", get_queues())
|
|
41
|
+
def test_rf_regression(queue):
|
|
42
|
+
if queue and queue.sycl_device.is_gpu:
|
|
43
|
+
pytest.skip("RF regressor predict for the GPU sycl_queue is buggy.")
|
|
44
|
+
X, y = make_regression(
|
|
45
|
+
n_samples=100, n_features=4, n_informative=2, random_state=0, shuffle=False
|
|
46
|
+
)
|
|
47
|
+
rf = RandomForestRegressor(max_depth=2, random_state=0).fit(X, y, queue=queue)
|
|
48
|
+
|
|
49
|
+
# GPU and CPU implementations of Random Forest use RNGs differently. They build
|
|
50
|
+
# different ensembles of trees, thereby requiring separate check values.
|
|
51
|
+
if queue and queue.sycl_device.is_gpu:
|
|
52
|
+
if daal_check_version((2024, "P", 0)):
|
|
53
|
+
assert_allclose([1.82], rf.predict([[0, 0, 0, 0]], queue=queue), atol=1e-2)
|
|
54
|
+
else:
|
|
55
|
+
assert_allclose([-6.83], rf.predict([[0, 0, 0, 0]], queue=queue), atol=1e-2)
|
|
56
|
+
else:
|
|
57
|
+
if daal_check_version((2024, "P", 0)):
|
|
58
|
+
assert_allclose([-6.97], rf.predict([[0, 0, 0, 0]], queue=queue), atol=1e-2)
|
|
59
|
+
else:
|
|
60
|
+
assert_allclose([-6.83], rf.predict([[0, 0, 0, 0]], queue=queue), atol=1e-2)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@pytest.mark.skipif(
|
|
64
|
+
not daal_check_version((2023, "P", 101)), reason="requires OneDAL 2023.1.1"
|
|
65
|
+
)
|
|
66
|
+
@pytest.mark.parametrize("queue", get_queues("gpu"))
|
|
67
|
+
def test_rf_classifier_random_splitter(queue):
|
|
68
|
+
X, y = make_classification(
|
|
69
|
+
n_samples=100,
|
|
70
|
+
n_features=4,
|
|
71
|
+
n_informative=2,
|
|
72
|
+
n_redundant=0,
|
|
73
|
+
random_state=0,
|
|
74
|
+
shuffle=False,
|
|
75
|
+
)
|
|
76
|
+
rf = RandomForestClassifier(max_depth=2, random_state=0, splitter_mode="random").fit(
|
|
77
|
+
X, y, queue=queue
|
|
78
|
+
)
|
|
79
|
+
assert_allclose([1], rf.predict([[0, 0, 0, 0]], queue=queue))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@pytest.mark.parametrize("queue", get_queues("gpu"))
|
|
83
|
+
def test_rf_regression_random_splitter(queue):
|
|
84
|
+
# splitter_mode selection only for GPU enabled.
|
|
85
|
+
# For CPU only `best` mode is supported.
|
|
86
|
+
if queue and queue.sycl_device.is_gpu:
|
|
87
|
+
pytest.skip("RF regressor predict for the GPU sycl_queue is buggy.")
|
|
88
|
+
X, y = make_regression(
|
|
89
|
+
n_samples=100, n_features=4, n_informative=2, random_state=0, shuffle=False
|
|
90
|
+
)
|
|
91
|
+
rf = RandomForestRegressor(max_depth=2, random_state=0, splitter_mode="random").fit(
|
|
92
|
+
X, y, queue=queue
|
|
93
|
+
)
|
|
94
|
+
if daal_check_version((2024, "P", 0)):
|
|
95
|
+
assert_allclose([-6.88], rf.predict([[0, 0, 0, 0]], queue=queue), atol=1e-2)
|
|
96
|
+
else:
|
|
97
|
+
assert_allclose([-6.83], rf.predict([[0, 0, 0, 0]], queue=queue), atol=1e-2)
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
from .incremental_linear_model import IncrementalLinearRegression, IncrementalRidge
|
|
18
|
+
from .linear_model import LinearRegression, Ridge
|
|
19
|
+
from .logistic_regression import LogisticRegression
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"IncrementalLinearRegression",
|
|
23
|
+
"IncrementalRidge",
|
|
24
|
+
"LinearRegression",
|
|
25
|
+
"LogisticRegression",
|
|
26
|
+
"Ridge",
|
|
27
|
+
]
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2024 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
|
+
|
|
19
|
+
from daal4py.sklearn._utils import get_dtype
|
|
20
|
+
|
|
21
|
+
from ..common.hyperparameters import get_hyperparameters
|
|
22
|
+
from ..datatypes import _convert_to_supported, from_table, to_table
|
|
23
|
+
from ..utils import _check_X_y, _num_features
|
|
24
|
+
from .linear_model import BaseLinearRegression
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class IncrementalLinearRegression(BaseLinearRegression):
|
|
28
|
+
"""
|
|
29
|
+
Incremental Linear Regression oneDAL implementation.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
fit_intercept : bool, default=True
|
|
34
|
+
Whether to calculate the intercept for this model. If set
|
|
35
|
+
to False, no intercept will be used in calculations
|
|
36
|
+
(i.e. data is expected to be centered).
|
|
37
|
+
|
|
38
|
+
copy_X : bool, default=True
|
|
39
|
+
If True, X will be copied; else, it may be overwritten.
|
|
40
|
+
|
|
41
|
+
algorithm : string, default="norm_eq"
|
|
42
|
+
Algorithm used for computation on oneDAL side
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, fit_intercept=True, copy_X=False, algorithm="norm_eq"):
|
|
46
|
+
super().__init__(fit_intercept=fit_intercept, copy_X=copy_X, algorithm=algorithm)
|
|
47
|
+
self._reset()
|
|
48
|
+
|
|
49
|
+
def _reset(self):
|
|
50
|
+
self._partial_result = self._get_backend(
|
|
51
|
+
"linear_model", "regression", "partial_train_result"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
def partial_fit(self, X, y, queue=None):
|
|
55
|
+
"""
|
|
56
|
+
Computes partial data for linear regression
|
|
57
|
+
from data batch X and saves it to `_partial_result`.
|
|
58
|
+
Parameters
|
|
59
|
+
----------
|
|
60
|
+
X : array-like of shape (n_samples, n_features)
|
|
61
|
+
Training data batch, where `n_samples` is the number of samples
|
|
62
|
+
in the batch, and `n_features` is the number of features.
|
|
63
|
+
|
|
64
|
+
y: array-like of shape (n_samples,) or (n_samples, n_targets) in
|
|
65
|
+
case of multiple targets
|
|
66
|
+
Responses for training data.
|
|
67
|
+
|
|
68
|
+
queue : dpctl.SyclQueue
|
|
69
|
+
If not None, use this queue for computations.
|
|
70
|
+
Returns
|
|
71
|
+
-------
|
|
72
|
+
self : object
|
|
73
|
+
Returns the instance itself.
|
|
74
|
+
"""
|
|
75
|
+
module = self._get_backend("linear_model", "regression")
|
|
76
|
+
|
|
77
|
+
self._queue = queue
|
|
78
|
+
policy = self._get_policy(queue, X)
|
|
79
|
+
|
|
80
|
+
X, y = _convert_to_supported(policy, X, y)
|
|
81
|
+
|
|
82
|
+
if not hasattr(self, "_dtype"):
|
|
83
|
+
self._dtype = get_dtype(X)
|
|
84
|
+
self._params = self._get_onedal_params(self._dtype)
|
|
85
|
+
|
|
86
|
+
y = np.asarray(y, dtype=self._dtype)
|
|
87
|
+
|
|
88
|
+
X, y = _check_X_y(
|
|
89
|
+
X, y, dtype=[np.float64, np.float32], accept_2d_y=True, force_all_finite=False
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
self.n_features_in_ = _num_features(X, fallback_1d=True)
|
|
93
|
+
X_table, y_table = to_table(X, y)
|
|
94
|
+
hparams = get_hyperparameters("linear_regression", "train")
|
|
95
|
+
if hparams is not None and not hparams.is_default:
|
|
96
|
+
self._partial_result = module.partial_train(
|
|
97
|
+
policy,
|
|
98
|
+
self._params,
|
|
99
|
+
hparams.backend,
|
|
100
|
+
self._partial_result,
|
|
101
|
+
X_table,
|
|
102
|
+
y_table,
|
|
103
|
+
)
|
|
104
|
+
else:
|
|
105
|
+
self._partial_result = module.partial_train(
|
|
106
|
+
policy, self._params, self._partial_result, X_table, y_table
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
def finalize_fit(self, queue=None):
|
|
110
|
+
"""
|
|
111
|
+
Finalizes linear regression computation and obtains coefficients
|
|
112
|
+
from the current `_partial_result`.
|
|
113
|
+
|
|
114
|
+
Parameters
|
|
115
|
+
----------
|
|
116
|
+
queue : dpctl.SyclQueue
|
|
117
|
+
If not None, use this queue for computations.
|
|
118
|
+
|
|
119
|
+
Returns
|
|
120
|
+
-------
|
|
121
|
+
self : object
|
|
122
|
+
Returns the instance itself.
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
if queue is not None:
|
|
126
|
+
policy = self._get_policy(queue)
|
|
127
|
+
else:
|
|
128
|
+
policy = self._get_policy(self._queue)
|
|
129
|
+
|
|
130
|
+
module = self._get_backend("linear_model", "regression")
|
|
131
|
+
hparams = get_hyperparameters("linear_regression", "train")
|
|
132
|
+
if hparams is not None and not hparams.is_default:
|
|
133
|
+
result = module.finalize_train(
|
|
134
|
+
policy, self._params, hparams.backend, self._partial_result
|
|
135
|
+
)
|
|
136
|
+
else:
|
|
137
|
+
result = module.finalize_train(policy, self._params, self._partial_result)
|
|
138
|
+
|
|
139
|
+
self._onedal_model = result.model
|
|
140
|
+
|
|
141
|
+
packed_coefficients = from_table(result.model.packed_coefficients)
|
|
142
|
+
self.coef_, self.intercept_ = (
|
|
143
|
+
packed_coefficients[:, 1:].squeeze(),
|
|
144
|
+
packed_coefficients[:, 0].squeeze(),
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
return self
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class IncrementalRidge(BaseLinearRegression):
|
|
151
|
+
"""
|
|
152
|
+
Incremental Ridge Regression oneDAL implementation.
|
|
153
|
+
|
|
154
|
+
Parameters
|
|
155
|
+
----------
|
|
156
|
+
alpha : float, default=1.0
|
|
157
|
+
Regularization strength; must be a positive float. Regularization
|
|
158
|
+
improves the conditioning of the problem and reduces the variance of
|
|
159
|
+
the estimates. Larger values specify stronger regularization.
|
|
160
|
+
|
|
161
|
+
fit_intercept : bool, default=True
|
|
162
|
+
Whether to calculate the intercept for this model. If set
|
|
163
|
+
to False, no intercept will be used in calculations
|
|
164
|
+
(i.e. data is expected to be centered).
|
|
165
|
+
|
|
166
|
+
copy_X : bool, default=True
|
|
167
|
+
If True, X will be copied; else, it may be overwritten.
|
|
168
|
+
|
|
169
|
+
algorithm : string, default="norm_eq"
|
|
170
|
+
Algorithm used for computation on oneDAL side
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
def __init__(self, alpha=1.0, fit_intercept=True, copy_X=False, algorithm="norm_eq"):
|
|
174
|
+
module = self._get_backend("linear_model", "regression")
|
|
175
|
+
super().__init__(
|
|
176
|
+
fit_intercept=fit_intercept, alpha=alpha, copy_X=copy_X, algorithm=algorithm
|
|
177
|
+
)
|
|
178
|
+
self._partial_result = module.partial_train_result()
|
|
179
|
+
|
|
180
|
+
def _reset(self):
|
|
181
|
+
module = self._get_backend("linear_model", "regression")
|
|
182
|
+
self._partial_result = module.partial_train_result()
|
|
183
|
+
|
|
184
|
+
def partial_fit(self, X, y, queue=None):
|
|
185
|
+
"""
|
|
186
|
+
Computes partial data for ridge regression
|
|
187
|
+
from data batch X and saves it to `_partial_result`.
|
|
188
|
+
Parameters
|
|
189
|
+
----------
|
|
190
|
+
X : array-like of shape (n_samples, n_features)
|
|
191
|
+
Training data batch, where `n_samples` is the number of samples
|
|
192
|
+
in the batch, and `n_features` is the number of features.
|
|
193
|
+
|
|
194
|
+
y: array-like of shape (n_samples,) or (n_samples, n_targets) in
|
|
195
|
+
case of multiple targets
|
|
196
|
+
Responses for training data.
|
|
197
|
+
|
|
198
|
+
queue : dpctl.SyclQueue
|
|
199
|
+
If not None, use this queue for computations.
|
|
200
|
+
Returns
|
|
201
|
+
-------
|
|
202
|
+
self : object
|
|
203
|
+
Returns the instance itself.
|
|
204
|
+
"""
|
|
205
|
+
module = self._get_backend("linear_model", "regression")
|
|
206
|
+
|
|
207
|
+
self._queue = queue
|
|
208
|
+
policy = self._get_policy(queue, X)
|
|
209
|
+
|
|
210
|
+
X, y = _convert_to_supported(policy, X, y)
|
|
211
|
+
|
|
212
|
+
if not hasattr(self, "_dtype"):
|
|
213
|
+
self._dtype = get_dtype(X)
|
|
214
|
+
self._params = self._get_onedal_params(self._dtype)
|
|
215
|
+
|
|
216
|
+
y = np.asarray(y, dtype=self._dtype)
|
|
217
|
+
|
|
218
|
+
X, y = _check_X_y(
|
|
219
|
+
X, y, dtype=[np.float64, np.float32], accept_2d_y=True, force_all_finite=False
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
self.n_features_in_ = _num_features(X, fallback_1d=True)
|
|
223
|
+
X_table, y_table = to_table(X, y)
|
|
224
|
+
self._partial_result = module.partial_train(
|
|
225
|
+
policy, self._params, self._partial_result, X_table, y_table
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
def finalize_fit(self, queue=None):
|
|
229
|
+
"""
|
|
230
|
+
Finalizes ridge regression computation and obtains coefficients
|
|
231
|
+
from the current `_partial_result`.
|
|
232
|
+
|
|
233
|
+
Parameters
|
|
234
|
+
----------
|
|
235
|
+
queue : dpctl.SyclQueue
|
|
236
|
+
If available, uses provided queue for computations.
|
|
237
|
+
|
|
238
|
+
Returns
|
|
239
|
+
-------
|
|
240
|
+
self : object
|
|
241
|
+
Returns the instance itself.
|
|
242
|
+
"""
|
|
243
|
+
module = self._get_backend("linear_model", "regression")
|
|
244
|
+
if queue is not None:
|
|
245
|
+
policy = self._get_policy(queue)
|
|
246
|
+
else:
|
|
247
|
+
policy = self._get_policy(self._queue)
|
|
248
|
+
result = module.finalize_train(policy, self._params, self._partial_result)
|
|
249
|
+
|
|
250
|
+
self._onedal_model = result.model
|
|
251
|
+
|
|
252
|
+
packed_coefficients = from_table(result.model.packed_coefficients)
|
|
253
|
+
self.coef_, self.intercept_ = (
|
|
254
|
+
packed_coefficients[:, 1:].squeeze(),
|
|
255
|
+
packed_coefficients[:, 0].squeeze(),
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
return self
|