scikit-learn-intelex 2025.1.0__py311-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-311-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-311-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-311-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_host.cpython-311-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_spmd_dpc.cpython-311-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,425 @@
|
|
|
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 numbers
|
|
18
|
+
import warnings
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
from sklearn.base import BaseEstimator, MultiOutputMixin, RegressorMixin
|
|
22
|
+
from sklearn.metrics import r2_score
|
|
23
|
+
from sklearn.utils import gen_batches
|
|
24
|
+
from sklearn.utils.validation import check_is_fitted, check_X_y
|
|
25
|
+
|
|
26
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
27
|
+
from daal4py.sklearn.utils.validation import sklearn_check_version
|
|
28
|
+
|
|
29
|
+
if sklearn_check_version("1.2"):
|
|
30
|
+
from sklearn.utils._param_validation import Interval
|
|
31
|
+
|
|
32
|
+
from onedal.linear_model import IncrementalRidge as onedal_IncrementalRidge
|
|
33
|
+
|
|
34
|
+
from .._device_offload import dispatch, wrap_output_data
|
|
35
|
+
from .._utils import PatchingConditionsChain
|
|
36
|
+
|
|
37
|
+
if sklearn_check_version("1.6"):
|
|
38
|
+
from sklearn.utils.validation import validate_data
|
|
39
|
+
else:
|
|
40
|
+
validate_data = BaseEstimator._validate_data
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@control_n_jobs(
|
|
44
|
+
decorated_methods=["fit", "partial_fit", "predict", "score", "_onedal_finalize_fit"]
|
|
45
|
+
)
|
|
46
|
+
class IncrementalRidge(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
47
|
+
"""
|
|
48
|
+
Incremental estimator for Ridge Regression.
|
|
49
|
+
Allows to train Ridge Regression if data is splitted into batches.
|
|
50
|
+
|
|
51
|
+
Parameters
|
|
52
|
+
----------
|
|
53
|
+
fit_intercept : bool, default=True
|
|
54
|
+
Whether to calculate the intercept for this model. If set
|
|
55
|
+
to False, no intercept will be used in calculations
|
|
56
|
+
(i.e. data is expected to be centered).
|
|
57
|
+
|
|
58
|
+
alpha : float, default=1.0
|
|
59
|
+
Regularization strength; must be a positive float. Regularization
|
|
60
|
+
improves the conditioning of the problem and reduces the variance of
|
|
61
|
+
the estimates. Larger values specify stronger regularization.
|
|
62
|
+
|
|
63
|
+
copy_X : bool, default=True
|
|
64
|
+
If True, X will be copied; else, it may be overwritten.
|
|
65
|
+
|
|
66
|
+
n_jobs : int, default=None
|
|
67
|
+
The number of jobs to use for the computation.
|
|
68
|
+
|
|
69
|
+
batch_size : int, default=None
|
|
70
|
+
The number of samples to use for each batch. Only used when calling
|
|
71
|
+
``fit``. If ``batch_size`` is ``None``, then ``batch_size``
|
|
72
|
+
is inferred from the data and set to ``5 * n_features``, to provide a
|
|
73
|
+
balance between approximation accuracy and memory consumption.
|
|
74
|
+
|
|
75
|
+
Attributes
|
|
76
|
+
----------
|
|
77
|
+
coef_ : array of shape (n_features, ) or (n_targets, n_features)
|
|
78
|
+
Estimated coefficients for the ridge regression problem.
|
|
79
|
+
If multiple targets are passed during the fit (y 2D), this
|
|
80
|
+
is a 2D array of shape (n_targets, n_features), while if only
|
|
81
|
+
one target is passed, this is a 1D array of length n_features.
|
|
82
|
+
|
|
83
|
+
intercept_ : float or array of shape (n_targets,)
|
|
84
|
+
Independent term in the linear model. Set to 0.0 if
|
|
85
|
+
`fit_intercept = False`.
|
|
86
|
+
|
|
87
|
+
n_features_in_ : int
|
|
88
|
+
Number of features seen during :term:`fit`.
|
|
89
|
+
|
|
90
|
+
n_samples_seen_ : int
|
|
91
|
+
The number of samples processed by the estimator. Will be reset on
|
|
92
|
+
new calls to fit, but increments across ``partial_fit`` calls.
|
|
93
|
+
It should be not less than `n_features_in_` if `fit_intercept`
|
|
94
|
+
is False and not less than `n_features_in_` + 1 if `fit_intercept`
|
|
95
|
+
is True to obtain regression coefficients.
|
|
96
|
+
|
|
97
|
+
batch_size_ : int
|
|
98
|
+
Inferred batch size from ``batch_size``.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
_onedal_incremental_ridge = staticmethod(onedal_IncrementalRidge)
|
|
102
|
+
|
|
103
|
+
if sklearn_check_version("1.2"):
|
|
104
|
+
_parameter_constraints: dict = {
|
|
105
|
+
"fit_intercept": ["boolean"],
|
|
106
|
+
"alpha": [Interval(numbers.Real, 0, None, closed="left")],
|
|
107
|
+
"copy_X": ["boolean"],
|
|
108
|
+
"n_jobs": [Interval(numbers.Integral, -1, None, closed="left"), None],
|
|
109
|
+
"batch_size": [Interval(numbers.Integral, 1, None, closed="left"), None],
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
def __init__(
|
|
113
|
+
self, fit_intercept=True, alpha=1.0, copy_X=True, n_jobs=None, batch_size=None
|
|
114
|
+
):
|
|
115
|
+
self.fit_intercept = fit_intercept
|
|
116
|
+
self.alpha = alpha
|
|
117
|
+
self.copy_X = copy_X
|
|
118
|
+
self.n_jobs = n_jobs
|
|
119
|
+
self.batch_size = batch_size
|
|
120
|
+
|
|
121
|
+
def _onedal_supported(self, method_name, *data):
|
|
122
|
+
patching_status = PatchingConditionsChain(
|
|
123
|
+
f"sklearn.linear_model.{self.__class__.__name__}.{method_name}"
|
|
124
|
+
)
|
|
125
|
+
return patching_status
|
|
126
|
+
|
|
127
|
+
_onedal_cpu_supported = _onedal_supported
|
|
128
|
+
_onedal_gpu_supported = _onedal_supported
|
|
129
|
+
|
|
130
|
+
def _onedal_predict(self, X, queue=None):
|
|
131
|
+
if sklearn_check_version("1.2"):
|
|
132
|
+
self._validate_params()
|
|
133
|
+
|
|
134
|
+
if sklearn_check_version("1.0"):
|
|
135
|
+
X = validate_data(self, X, accept_sparse=False, reset=False)
|
|
136
|
+
|
|
137
|
+
assert hasattr(self, "_onedal_estimator")
|
|
138
|
+
if self._need_to_finalize:
|
|
139
|
+
self._onedal_finalize_fit()
|
|
140
|
+
return self._onedal_estimator.predict(X, queue)
|
|
141
|
+
|
|
142
|
+
def _onedal_score(self, X, y, sample_weight=None, queue=None):
|
|
143
|
+
return r2_score(
|
|
144
|
+
y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
def _onedal_partial_fit(self, X, y, check_input=True, queue=None):
|
|
148
|
+
first_pass = not hasattr(self, "n_samples_seen_") or self.n_samples_seen_ == 0
|
|
149
|
+
|
|
150
|
+
if sklearn_check_version("1.2"):
|
|
151
|
+
self._validate_params()
|
|
152
|
+
|
|
153
|
+
if check_input:
|
|
154
|
+
if sklearn_check_version("1.0"):
|
|
155
|
+
X, y = validate_data(
|
|
156
|
+
self,
|
|
157
|
+
X,
|
|
158
|
+
y,
|
|
159
|
+
dtype=[np.float64, np.float32],
|
|
160
|
+
reset=first_pass,
|
|
161
|
+
copy=self.copy_X,
|
|
162
|
+
multi_output=True,
|
|
163
|
+
force_all_finite=False,
|
|
164
|
+
)
|
|
165
|
+
else:
|
|
166
|
+
check_X_y(X, y, multi_output=True, y_numeric=True)
|
|
167
|
+
|
|
168
|
+
if first_pass:
|
|
169
|
+
self.n_samples_seen_ = X.shape[0]
|
|
170
|
+
self.n_features_in_ = X.shape[1]
|
|
171
|
+
else:
|
|
172
|
+
self.n_samples_seen_ += X.shape[0]
|
|
173
|
+
onedal_params = {
|
|
174
|
+
"fit_intercept": self.fit_intercept,
|
|
175
|
+
"alpha": self.alpha,
|
|
176
|
+
"copy_X": self.copy_X,
|
|
177
|
+
}
|
|
178
|
+
if not hasattr(self, "_onedal_estimator"):
|
|
179
|
+
self._onedal_estimator = self._onedal_incremental_ridge(**onedal_params)
|
|
180
|
+
self._onedal_estimator.partial_fit(X, y, queue)
|
|
181
|
+
self._need_to_finalize = True
|
|
182
|
+
|
|
183
|
+
def _onedal_finalize_fit(self):
|
|
184
|
+
assert hasattr(self, "_onedal_estimator")
|
|
185
|
+
is_underdetermined = self.n_samples_seen_ < self.n_features_in_ + int(
|
|
186
|
+
self.fit_intercept
|
|
187
|
+
)
|
|
188
|
+
if is_underdetermined:
|
|
189
|
+
raise ValueError("Not enough samples to finalize")
|
|
190
|
+
self._onedal_estimator.finalize_fit()
|
|
191
|
+
self._save_attributes()
|
|
192
|
+
self._need_to_finalize = False
|
|
193
|
+
|
|
194
|
+
def _onedal_fit(self, X, y, queue=None):
|
|
195
|
+
if sklearn_check_version("1.2"):
|
|
196
|
+
self._validate_params()
|
|
197
|
+
|
|
198
|
+
if sklearn_check_version("1.0"):
|
|
199
|
+
X, y = validate_data(
|
|
200
|
+
self,
|
|
201
|
+
X,
|
|
202
|
+
y,
|
|
203
|
+
dtype=[np.float64, np.float32],
|
|
204
|
+
copy=self.copy_X,
|
|
205
|
+
multi_output=True,
|
|
206
|
+
ensure_2d=True,
|
|
207
|
+
)
|
|
208
|
+
else:
|
|
209
|
+
check_X_y(X, y, multi_output=True, y_numeric=True)
|
|
210
|
+
|
|
211
|
+
n_samples, n_features = X.shape
|
|
212
|
+
|
|
213
|
+
is_underdetermined = n_samples < n_features + int(self.fit_intercept)
|
|
214
|
+
if is_underdetermined:
|
|
215
|
+
raise ValueError("Not enough samples to run oneDAL backend")
|
|
216
|
+
|
|
217
|
+
if self.batch_size is None:
|
|
218
|
+
self.batch_size_ = 5 * n_features
|
|
219
|
+
else:
|
|
220
|
+
self.batch_size_ = self.batch_size
|
|
221
|
+
|
|
222
|
+
self.n_samples_seen_ = 0
|
|
223
|
+
if hasattr(self, "_onedal_estimator"):
|
|
224
|
+
self._onedal_estimator._reset()
|
|
225
|
+
|
|
226
|
+
for batch in gen_batches(n_samples, self.batch_size_):
|
|
227
|
+
X_batch, y_batch = X[batch], y[batch]
|
|
228
|
+
self._onedal_partial_fit(X_batch, y_batch, check_input=False, queue=queue)
|
|
229
|
+
|
|
230
|
+
if sklearn_check_version("1.2"):
|
|
231
|
+
self._validate_params()
|
|
232
|
+
|
|
233
|
+
# finite check occurs on onedal side
|
|
234
|
+
self.n_features_in_ = n_features
|
|
235
|
+
|
|
236
|
+
if n_samples == 1:
|
|
237
|
+
warnings.warn(
|
|
238
|
+
"Only one sample available. You may want to reshape your data array"
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
self._onedal_finalize_fit()
|
|
242
|
+
|
|
243
|
+
return self
|
|
244
|
+
|
|
245
|
+
def partial_fit(self, X, y, check_input=True):
|
|
246
|
+
"""
|
|
247
|
+
Incrementally fits the linear model with X and y. All of X and y is
|
|
248
|
+
processed as a single batch.
|
|
249
|
+
|
|
250
|
+
Parameters
|
|
251
|
+
----------
|
|
252
|
+
X : array-like of shape (n_samples, n_features)
|
|
253
|
+
Training data, where `n_samples` is the number of samples and
|
|
254
|
+
`n_features` is the number of features.
|
|
255
|
+
|
|
256
|
+
y : array-like of shape (n_samples,) or (n_samples, n_targets)
|
|
257
|
+
Target values, where `n_samples` is the number of samples and
|
|
258
|
+
`n_targets` is the number of targets.
|
|
259
|
+
|
|
260
|
+
Returns
|
|
261
|
+
-------
|
|
262
|
+
self : object
|
|
263
|
+
Returns the instance itself.
|
|
264
|
+
"""
|
|
265
|
+
|
|
266
|
+
dispatch(
|
|
267
|
+
self,
|
|
268
|
+
"partial_fit",
|
|
269
|
+
{
|
|
270
|
+
"onedal": self.__class__._onedal_partial_fit,
|
|
271
|
+
"sklearn": None,
|
|
272
|
+
},
|
|
273
|
+
X,
|
|
274
|
+
y,
|
|
275
|
+
check_input=check_input,
|
|
276
|
+
)
|
|
277
|
+
return self
|
|
278
|
+
|
|
279
|
+
def fit(self, X, y):
|
|
280
|
+
"""
|
|
281
|
+
Fit the model with X and y, using minibatches of size batch_size.
|
|
282
|
+
|
|
283
|
+
Parameters
|
|
284
|
+
----------
|
|
285
|
+
X : array-like of shape (n_samples, n_features)
|
|
286
|
+
Training data, where `n_samples` is the number of samples and
|
|
287
|
+
`n_features` is the number of features. It is necessary for
|
|
288
|
+
`n_samples` to be not less than `n_features` if `fit_intercept`
|
|
289
|
+
is False and not less than `n_features` + 1 if `fit_intercept`
|
|
290
|
+
is True
|
|
291
|
+
|
|
292
|
+
y : array-like of shape (n_samples,) or (n_samples, n_targets)
|
|
293
|
+
Target values, where `n_samples` is the number of samples and
|
|
294
|
+
`n_targets` is the number of targets.
|
|
295
|
+
|
|
296
|
+
Returns
|
|
297
|
+
-------
|
|
298
|
+
self : object
|
|
299
|
+
Returns the instance itself.
|
|
300
|
+
"""
|
|
301
|
+
|
|
302
|
+
dispatch(
|
|
303
|
+
self,
|
|
304
|
+
"fit",
|
|
305
|
+
{
|
|
306
|
+
"onedal": self.__class__._onedal_fit,
|
|
307
|
+
"sklearn": None,
|
|
308
|
+
},
|
|
309
|
+
X,
|
|
310
|
+
y,
|
|
311
|
+
)
|
|
312
|
+
return self
|
|
313
|
+
|
|
314
|
+
@wrap_output_data
|
|
315
|
+
def predict(self, X, y=None):
|
|
316
|
+
"""
|
|
317
|
+
Predict using the linear model.
|
|
318
|
+
|
|
319
|
+
Parameters
|
|
320
|
+
----------
|
|
321
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
322
|
+
Samples.
|
|
323
|
+
|
|
324
|
+
Returns
|
|
325
|
+
-------
|
|
326
|
+
array, shape (n_samples,) or (n_samples, n_targets)
|
|
327
|
+
Returns predicted values.
|
|
328
|
+
"""
|
|
329
|
+
check_is_fitted(
|
|
330
|
+
self,
|
|
331
|
+
msg=f"This {self.__class__.__name__} instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.",
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
return dispatch(
|
|
335
|
+
self,
|
|
336
|
+
"predict",
|
|
337
|
+
{
|
|
338
|
+
"onedal": self.__class__._onedal_predict,
|
|
339
|
+
"sklearn": None,
|
|
340
|
+
},
|
|
341
|
+
X,
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
@wrap_output_data
|
|
345
|
+
def score(self, X, y, sample_weight=None):
|
|
346
|
+
"""
|
|
347
|
+
Return the coefficient of determination R^2 of the prediction.
|
|
348
|
+
|
|
349
|
+
The coefficient R^2 is defined as (1 - u/v), where u is the residual
|
|
350
|
+
sum of squares ((y_true - y_pred) ** 2).sum() and v is the total sum
|
|
351
|
+
of squares ((y_true - y_true.mean()) ** 2).sum().
|
|
352
|
+
The best possible score is 1.0 and it can be negative (because the
|
|
353
|
+
model can be arbitrarily worse). A constant model that always
|
|
354
|
+
predicts the expected value of y, disregarding the input features,
|
|
355
|
+
would get a R^2 score of 0.0.
|
|
356
|
+
|
|
357
|
+
Parameters
|
|
358
|
+
----------
|
|
359
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
360
|
+
Test samples.
|
|
361
|
+
|
|
362
|
+
y : array-like of shape (n_samples,) or (n_samples, n_targets)
|
|
363
|
+
True values for X.
|
|
364
|
+
|
|
365
|
+
sample_weight : array-like of shape (n_samples,), default=None
|
|
366
|
+
Sample weights.
|
|
367
|
+
|
|
368
|
+
Returns
|
|
369
|
+
-------
|
|
370
|
+
score : float
|
|
371
|
+
R^2 of self.predict(X) wrt. y.
|
|
372
|
+
"""
|
|
373
|
+
check_is_fitted(
|
|
374
|
+
self,
|
|
375
|
+
msg=f"This {self.__class__.__name__} instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.",
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
return dispatch(
|
|
379
|
+
self,
|
|
380
|
+
"score",
|
|
381
|
+
{
|
|
382
|
+
"onedal": self.__class__._onedal_score,
|
|
383
|
+
"sklearn": None,
|
|
384
|
+
},
|
|
385
|
+
X,
|
|
386
|
+
y,
|
|
387
|
+
sample_weight=sample_weight,
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
@property
|
|
391
|
+
def coef_(self):
|
|
392
|
+
if hasattr(self, "_onedal_estimator") and self._need_to_finalize:
|
|
393
|
+
self._onedal_finalize_fit()
|
|
394
|
+
|
|
395
|
+
return self._coef
|
|
396
|
+
|
|
397
|
+
@coef_.setter
|
|
398
|
+
def coef_(self, value):
|
|
399
|
+
if hasattr(self, "_onedal_estimator"):
|
|
400
|
+
self._onedal_estimator.coef_ = value
|
|
401
|
+
# checking if the model is already fitted and if so, deleting the model
|
|
402
|
+
if hasattr(self._onedal_estimator, "_onedal_model"):
|
|
403
|
+
del self._onedal_estimator._onedal_model
|
|
404
|
+
self._coef = value
|
|
405
|
+
|
|
406
|
+
@property
|
|
407
|
+
def intercept_(self):
|
|
408
|
+
if hasattr(self, "_onedal_estimator") and self._need_to_finalize:
|
|
409
|
+
self._onedal_finalize_fit()
|
|
410
|
+
|
|
411
|
+
return self._intercept
|
|
412
|
+
|
|
413
|
+
@intercept_.setter
|
|
414
|
+
def intercept_(self, value):
|
|
415
|
+
if hasattr(self, "_onedal_estimator"):
|
|
416
|
+
self._onedal_estimator.intercept_ = value
|
|
417
|
+
# checking if the model is already fitted and if so, deleting the model
|
|
418
|
+
if hasattr(self._onedal_estimator, "_onedal_model"):
|
|
419
|
+
del self._onedal_estimator._onedal_model
|
|
420
|
+
self._intercept = value
|
|
421
|
+
|
|
422
|
+
def _save_attributes(self):
|
|
423
|
+
self.n_features_in_ = self._onedal_estimator.n_features_in_
|
|
424
|
+
self._coef = self._onedal_estimator.coef_
|
|
425
|
+
self._intercept = self._onedal_estimator.intercept_
|