scikit-learn-intelex 2024.0.1__py312-none-win_amd64.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.
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/__init__.py +61 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/__main__.py +59 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/_config.py +110 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/_device_offload.py +223 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/_utils.py +95 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/basic_statistics/__init__.py +20 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/basic_statistics/basic_statistics.py +17 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/cluster/__init__.py +21 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/cluster/dbscan.py +187 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/cluster/k_means.py +18 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/cluster/tests/test_dbscan.py +37 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/cluster/tests/test_kmeans.py +31 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/decomposition/__init__.py +20 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/decomposition/pca.py +18 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/decomposition/tests/test_pca.py +28 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/dispatcher.py +329 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/doc/third-party-programs.txt +424 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/ensemble/__init__.py +30 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/ensemble/_forest.py +1947 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/ensemble/tests/test_forest.py +118 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/glob/__main__.py +73 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/glob/dispatcher.py +88 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/__init__.py +30 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/coordinate_descent.py +18 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/linear.py +373 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/logistic_path.py +18 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/ridge.py +18 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/tests/test_linear.py +77 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/tests/test_logreg.py +29 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/manifold/__init__.py +20 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/manifold/t_sne.py +18 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/manifold/tests/test_tsne.py +27 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/metrics/__init__.py +24 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/metrics/pairwise.py +18 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/metrics/ranking.py +18 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/metrics/tests/test_metrics.py +40 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/model_selection/__init__.py +22 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/model_selection/split.py +18 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/model_selection/tests/test_model_selection.py +35 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/__init__.py +28 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/common.py +264 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/knn_classification.py +331 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/knn_regression.py +307 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/knn_unsupervised.py +220 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/lof.py +437 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/tests/test_neighbors.py +85 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/__init__.py +18 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/cluster/__init__.py +20 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/cluster/_common.py +84 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/cluster/k_means.py +370 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/decomposition/__init__.py +20 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/decomposition/pca.py +376 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/preview/decomposition/tests/test_preview_pca.py +38 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/__init__.py +24 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/basic_statistics/__init__.py +19 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/basic_statistics/basic_statistics.py +21 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/cluster/__init__.py +30 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/cluster/dbscan.py +50 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/cluster/kmeans.py +21 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/decomposition/__init__.py +19 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/decomposition/pca.py +21 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/ensemble/__init__.py +19 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/ensemble/forest.py +79 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/linear_model/__init__.py +19 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/linear_model/linear_model.py +21 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/neighbors/__init__.py +19 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd/neighbors/neighbors.py +25 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/__init__.py +30 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/_common.py +188 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/nusvc.py +272 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/nusvr.py +163 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/svc.py +301 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/svr.py +164 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/svm/tests/test_svm.py +102 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/_models_info.py +170 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_config.py +39 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_memory_usage.py +225 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_monkeypatch.py +210 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_parallel.py +50 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_patching.py +122 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/test_run_to_run_stability_tests.py +428 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/tests/utils/_launch_algorithms.py +118 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/utils/__init__.py +19 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/utils/parallel.py +59 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/utils/validation.py +18 -0
- scikit_learn_intelex-2024.0.1.dist-info/LICENSE.txt +202 -0
- scikit_learn_intelex-2024.0.1.dist-info/METADATA +230 -0
- scikit_learn_intelex-2024.0.1.dist-info/RECORD +90 -0
- scikit_learn_intelex-2024.0.1.dist-info/WHEEL +5 -0
- scikit_learn_intelex-2024.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
from sklearn.svm import NuSVR as sklearn_NuSVR
|
|
18
|
+
from sklearn.utils.validation import _deprecate_positional_args
|
|
19
|
+
|
|
20
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
21
|
+
from onedal.svm import NuSVR as onedal_NuSVR
|
|
22
|
+
|
|
23
|
+
from .._device_offload import dispatch, wrap_output_data
|
|
24
|
+
from ._common import BaseSVR
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
28
|
+
__doc__ = sklearn_NuSVR.__doc__
|
|
29
|
+
|
|
30
|
+
if sklearn_check_version("1.2"):
|
|
31
|
+
_parameter_constraints: dict = {**sklearn_NuSVR._parameter_constraints}
|
|
32
|
+
|
|
33
|
+
@_deprecate_positional_args
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
*,
|
|
37
|
+
kernel="rbf",
|
|
38
|
+
degree=3,
|
|
39
|
+
gamma="scale",
|
|
40
|
+
coef0=0.0,
|
|
41
|
+
tol=1e-3,
|
|
42
|
+
C=1.0,
|
|
43
|
+
nu=0.5,
|
|
44
|
+
shrinking=True,
|
|
45
|
+
cache_size=200,
|
|
46
|
+
verbose=False,
|
|
47
|
+
max_iter=-1,
|
|
48
|
+
):
|
|
49
|
+
super().__init__(
|
|
50
|
+
kernel=kernel,
|
|
51
|
+
degree=degree,
|
|
52
|
+
gamma=gamma,
|
|
53
|
+
coef0=coef0,
|
|
54
|
+
tol=tol,
|
|
55
|
+
C=C,
|
|
56
|
+
nu=nu,
|
|
57
|
+
shrinking=shrinking,
|
|
58
|
+
cache_size=cache_size,
|
|
59
|
+
verbose=verbose,
|
|
60
|
+
max_iter=max_iter,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def fit(self, X, y, sample_weight=None):
|
|
64
|
+
"""
|
|
65
|
+
Fit the SVM model according to the given training data.
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features) \
|
|
70
|
+
or (n_samples, n_samples)
|
|
71
|
+
Training vectors, where `n_samples` is the number of samples
|
|
72
|
+
and `n_features` is the number of features.
|
|
73
|
+
For kernel="precomputed", the expected shape of X is
|
|
74
|
+
(n_samples, n_samples).
|
|
75
|
+
|
|
76
|
+
y : array-like of shape (n_samples,)
|
|
77
|
+
Target values (class labels in classification, real numbers in
|
|
78
|
+
regression).
|
|
79
|
+
|
|
80
|
+
sample_weight : array-like of shape (n_samples,), default=None
|
|
81
|
+
Per-sample weights. Rescale C per sample. Higher weights
|
|
82
|
+
force the classifier to put more emphasis on these points.
|
|
83
|
+
|
|
84
|
+
Returns
|
|
85
|
+
-------
|
|
86
|
+
self : object
|
|
87
|
+
Fitted estimator.
|
|
88
|
+
|
|
89
|
+
Notes
|
|
90
|
+
-----
|
|
91
|
+
If X and y are not C-ordered and contiguous arrays of np.float64 and
|
|
92
|
+
X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
|
|
93
|
+
|
|
94
|
+
If X is a dense array, then the other methods will not support sparse
|
|
95
|
+
matrices as input.
|
|
96
|
+
"""
|
|
97
|
+
if sklearn_check_version("1.2"):
|
|
98
|
+
self._validate_params()
|
|
99
|
+
if sklearn_check_version("1.0"):
|
|
100
|
+
self._check_feature_names(X, reset=True)
|
|
101
|
+
dispatch(
|
|
102
|
+
self,
|
|
103
|
+
"fit",
|
|
104
|
+
{
|
|
105
|
+
"onedal": self.__class__._onedal_fit,
|
|
106
|
+
"sklearn": sklearn_NuSVR.fit,
|
|
107
|
+
},
|
|
108
|
+
X,
|
|
109
|
+
y,
|
|
110
|
+
sample_weight,
|
|
111
|
+
)
|
|
112
|
+
return self
|
|
113
|
+
|
|
114
|
+
@wrap_output_data
|
|
115
|
+
def predict(self, X):
|
|
116
|
+
"""
|
|
117
|
+
Perform regression on samples in X.
|
|
118
|
+
|
|
119
|
+
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
|
|
120
|
+
|
|
121
|
+
Parameters
|
|
122
|
+
----------
|
|
123
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
124
|
+
For kernel="precomputed", the expected shape of X is
|
|
125
|
+
(n_samples_test, n_samples_train).
|
|
126
|
+
|
|
127
|
+
Returns
|
|
128
|
+
-------
|
|
129
|
+
y_pred : ndarray of shape (n_samples,)
|
|
130
|
+
The predicted values.
|
|
131
|
+
"""
|
|
132
|
+
if sklearn_check_version("1.0"):
|
|
133
|
+
self._check_feature_names(X, reset=False)
|
|
134
|
+
return dispatch(
|
|
135
|
+
self,
|
|
136
|
+
"predict",
|
|
137
|
+
{
|
|
138
|
+
"onedal": self.__class__._onedal_predict,
|
|
139
|
+
"sklearn": sklearn_NuSVR.predict,
|
|
140
|
+
},
|
|
141
|
+
X,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
|
|
145
|
+
onedal_params = {
|
|
146
|
+
"C": self.C,
|
|
147
|
+
"nu": self.nu,
|
|
148
|
+
"kernel": self.kernel,
|
|
149
|
+
"degree": self.degree,
|
|
150
|
+
"gamma": self.gamma,
|
|
151
|
+
"coef0": self.coef0,
|
|
152
|
+
"tol": self.tol,
|
|
153
|
+
"shrinking": self.shrinking,
|
|
154
|
+
"cache_size": self.cache_size,
|
|
155
|
+
"max_iter": self.max_iter,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
self._onedal_estimator = onedal_NuSVR(**onedal_params)
|
|
159
|
+
self._onedal_estimator.fit(X, y, sample_weight, queue=queue)
|
|
160
|
+
self._save_attributes()
|
|
161
|
+
|
|
162
|
+
def _onedal_predict(self, X, queue=None):
|
|
163
|
+
return self._onedal_estimator.predict(X, queue=queue)
|
|
@@ -0,0 +1,301 @@
|
|
|
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 scipy import sparse as sp
|
|
19
|
+
from sklearn.exceptions import NotFittedError
|
|
20
|
+
from sklearn.svm import SVC as sklearn_SVC
|
|
21
|
+
from sklearn.utils.validation import _deprecate_positional_args
|
|
22
|
+
|
|
23
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
24
|
+
|
|
25
|
+
from .._device_offload import dispatch, wrap_output_data
|
|
26
|
+
from .._utils import PatchingConditionsChain
|
|
27
|
+
from ._common import BaseSVC
|
|
28
|
+
|
|
29
|
+
if sklearn_check_version("1.0"):
|
|
30
|
+
from sklearn.utils.metaestimators import available_if
|
|
31
|
+
|
|
32
|
+
from onedal.svm import SVC as onedal_SVC
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SVC(sklearn_SVC, BaseSVC):
|
|
36
|
+
__doc__ = sklearn_SVC.__doc__
|
|
37
|
+
|
|
38
|
+
if sklearn_check_version("1.2"):
|
|
39
|
+
_parameter_constraints: dict = {**sklearn_SVC._parameter_constraints}
|
|
40
|
+
|
|
41
|
+
@_deprecate_positional_args
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
*,
|
|
45
|
+
C=1.0,
|
|
46
|
+
kernel="rbf",
|
|
47
|
+
degree=3,
|
|
48
|
+
gamma="scale",
|
|
49
|
+
coef0=0.0,
|
|
50
|
+
shrinking=True,
|
|
51
|
+
probability=False,
|
|
52
|
+
tol=1e-3,
|
|
53
|
+
cache_size=200,
|
|
54
|
+
class_weight=None,
|
|
55
|
+
verbose=False,
|
|
56
|
+
max_iter=-1,
|
|
57
|
+
decision_function_shape="ovr",
|
|
58
|
+
break_ties=False,
|
|
59
|
+
random_state=None,
|
|
60
|
+
):
|
|
61
|
+
super().__init__(
|
|
62
|
+
C=C,
|
|
63
|
+
kernel=kernel,
|
|
64
|
+
degree=degree,
|
|
65
|
+
gamma=gamma,
|
|
66
|
+
coef0=coef0,
|
|
67
|
+
shrinking=shrinking,
|
|
68
|
+
probability=probability,
|
|
69
|
+
tol=tol,
|
|
70
|
+
cache_size=cache_size,
|
|
71
|
+
class_weight=class_weight,
|
|
72
|
+
verbose=verbose,
|
|
73
|
+
max_iter=max_iter,
|
|
74
|
+
decision_function_shape=decision_function_shape,
|
|
75
|
+
break_ties=break_ties,
|
|
76
|
+
random_state=random_state,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def fit(self, X, y, sample_weight=None):
|
|
80
|
+
"""
|
|
81
|
+
Fit the SVM model according to the given training data.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features) \
|
|
86
|
+
or (n_samples, n_samples)
|
|
87
|
+
Training vectors, where `n_samples` is the number of samples
|
|
88
|
+
and `n_features` is the number of features.
|
|
89
|
+
For kernel="precomputed", the expected shape of X is
|
|
90
|
+
(n_samples, n_samples).
|
|
91
|
+
|
|
92
|
+
y : array-like of shape (n_samples,)
|
|
93
|
+
Target values (class labels in classification, real numbers in
|
|
94
|
+
regression).
|
|
95
|
+
|
|
96
|
+
sample_weight : array-like of shape (n_samples,), default=None
|
|
97
|
+
Per-sample weights. Rescale C per sample. Higher weights
|
|
98
|
+
force the classifier to put more emphasis on these points.
|
|
99
|
+
|
|
100
|
+
Returns
|
|
101
|
+
-------
|
|
102
|
+
self : object
|
|
103
|
+
Fitted estimator.
|
|
104
|
+
|
|
105
|
+
Notes
|
|
106
|
+
-----
|
|
107
|
+
If X and y are not C-ordered and contiguous arrays of np.float64 and
|
|
108
|
+
X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
|
|
109
|
+
|
|
110
|
+
If X is a dense array, then the other methods will not support sparse
|
|
111
|
+
matrices as input.
|
|
112
|
+
"""
|
|
113
|
+
if sklearn_check_version("1.2"):
|
|
114
|
+
self._validate_params()
|
|
115
|
+
if sklearn_check_version("1.0"):
|
|
116
|
+
self._check_feature_names(X, reset=True)
|
|
117
|
+
dispatch(
|
|
118
|
+
self,
|
|
119
|
+
"fit",
|
|
120
|
+
{
|
|
121
|
+
"onedal": self.__class__._onedal_fit,
|
|
122
|
+
"sklearn": sklearn_SVC.fit,
|
|
123
|
+
},
|
|
124
|
+
X,
|
|
125
|
+
y,
|
|
126
|
+
sample_weight,
|
|
127
|
+
)
|
|
128
|
+
return self
|
|
129
|
+
|
|
130
|
+
@wrap_output_data
|
|
131
|
+
def predict(self, X):
|
|
132
|
+
"""
|
|
133
|
+
Perform regression on samples in X.
|
|
134
|
+
|
|
135
|
+
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
|
|
136
|
+
|
|
137
|
+
Parameters
|
|
138
|
+
----------
|
|
139
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
140
|
+
For kernel="precomputed", the expected shape of X is
|
|
141
|
+
(n_samples_test, n_samples_train).
|
|
142
|
+
|
|
143
|
+
Returns
|
|
144
|
+
-------
|
|
145
|
+
y_pred : ndarray of shape (n_samples,)
|
|
146
|
+
The predicted values.
|
|
147
|
+
"""
|
|
148
|
+
if sklearn_check_version("1.0"):
|
|
149
|
+
self._check_feature_names(X, reset=False)
|
|
150
|
+
return dispatch(
|
|
151
|
+
self,
|
|
152
|
+
"predict",
|
|
153
|
+
{
|
|
154
|
+
"onedal": self.__class__._onedal_predict,
|
|
155
|
+
"sklearn": sklearn_SVC.predict,
|
|
156
|
+
},
|
|
157
|
+
X,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
if sklearn_check_version("1.0"):
|
|
161
|
+
|
|
162
|
+
@available_if(sklearn_SVC._check_proba)
|
|
163
|
+
def predict_proba(self, X):
|
|
164
|
+
"""
|
|
165
|
+
Compute probabilities of possible outcomes for samples in X.
|
|
166
|
+
|
|
167
|
+
The model need to have probability information computed at training
|
|
168
|
+
time: fit with attribute `probability` set to True.
|
|
169
|
+
|
|
170
|
+
Parameters
|
|
171
|
+
----------
|
|
172
|
+
X : array-like of shape (n_samples, n_features)
|
|
173
|
+
For kernel="precomputed", the expected shape of X is
|
|
174
|
+
(n_samples_test, n_samples_train).
|
|
175
|
+
|
|
176
|
+
Returns
|
|
177
|
+
-------
|
|
178
|
+
T : ndarray of shape (n_samples, n_classes)
|
|
179
|
+
Returns the probability of the sample for each class in
|
|
180
|
+
the model. The columns correspond to the classes in sorted
|
|
181
|
+
order, as they appear in the attribute :term:`classes_`.
|
|
182
|
+
|
|
183
|
+
Notes
|
|
184
|
+
-----
|
|
185
|
+
The probability model is created using cross validation, so
|
|
186
|
+
the results can be slightly different than those obtained by
|
|
187
|
+
predict. Also, it will produce meaningless results on very small
|
|
188
|
+
datasets.
|
|
189
|
+
"""
|
|
190
|
+
return self._predict_proba(X)
|
|
191
|
+
|
|
192
|
+
else:
|
|
193
|
+
|
|
194
|
+
@property
|
|
195
|
+
def predict_proba(self):
|
|
196
|
+
self._check_proba()
|
|
197
|
+
return self._predict_proba
|
|
198
|
+
|
|
199
|
+
@wrap_output_data
|
|
200
|
+
def _predict_proba(self, X):
|
|
201
|
+
sklearn_pred_proba = (
|
|
202
|
+
sklearn_SVC.predict_proba
|
|
203
|
+
if sklearn_check_version("1.0")
|
|
204
|
+
else sklearn_SVC._predict_proba
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
return dispatch(
|
|
208
|
+
self,
|
|
209
|
+
"predict_proba",
|
|
210
|
+
{
|
|
211
|
+
"onedal": self.__class__._onedal_predict_proba,
|
|
212
|
+
"sklearn": sklearn_pred_proba,
|
|
213
|
+
},
|
|
214
|
+
X,
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
@wrap_output_data
|
|
218
|
+
def decision_function(self, X):
|
|
219
|
+
if sklearn_check_version("1.0"):
|
|
220
|
+
self._check_feature_names(X, reset=False)
|
|
221
|
+
return dispatch(
|
|
222
|
+
self,
|
|
223
|
+
"decision_function",
|
|
224
|
+
{
|
|
225
|
+
"onedal": self.__class__._onedal_decision_function,
|
|
226
|
+
"sklearn": sklearn_SVC.decision_function,
|
|
227
|
+
},
|
|
228
|
+
X,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
def _onedal_gpu_supported(self, method_name, *data):
|
|
232
|
+
class_name = self.__class__.__name__
|
|
233
|
+
patching_status = PatchingConditionsChain(
|
|
234
|
+
f"sklearn.svm.{class_name}.{method_name}"
|
|
235
|
+
)
|
|
236
|
+
if len(data) > 1:
|
|
237
|
+
self._class_count = len(np.unique(data[1]))
|
|
238
|
+
self._is_sparse = sp.isspmatrix(data[0])
|
|
239
|
+
conditions = [
|
|
240
|
+
(
|
|
241
|
+
self.kernel in ["linear", "rbf"],
|
|
242
|
+
f'Kernel is "{self.kernel}" while '
|
|
243
|
+
'"linear" and "rbf" are only supported on GPU.',
|
|
244
|
+
),
|
|
245
|
+
(self.class_weight is None, "Class weight is not supported on GPU."),
|
|
246
|
+
(not self._is_sparse, "Sparse input is not supported on GPU."),
|
|
247
|
+
(self._class_count == 2, "Multiclassification is not supported on GPU."),
|
|
248
|
+
]
|
|
249
|
+
if method_name == "fit":
|
|
250
|
+
patching_status.and_conditions(conditions)
|
|
251
|
+
return patching_status
|
|
252
|
+
if method_name in ["predict", "predict_proba", "decision_function"]:
|
|
253
|
+
conditions.append(
|
|
254
|
+
(hasattr(self, "_onedal_estimator"), "oneDAL model was not trained")
|
|
255
|
+
)
|
|
256
|
+
patching_status.and_conditions(conditions)
|
|
257
|
+
return patching_status
|
|
258
|
+
raise RuntimeError(f"Unknown method {method_name} in {class_name}")
|
|
259
|
+
|
|
260
|
+
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
|
|
261
|
+
onedal_params = {
|
|
262
|
+
"C": self.C,
|
|
263
|
+
"kernel": self.kernel,
|
|
264
|
+
"degree": self.degree,
|
|
265
|
+
"gamma": self.gamma,
|
|
266
|
+
"coef0": self.coef0,
|
|
267
|
+
"tol": self.tol,
|
|
268
|
+
"shrinking": self.shrinking,
|
|
269
|
+
"cache_size": self.cache_size,
|
|
270
|
+
"max_iter": self.max_iter,
|
|
271
|
+
"class_weight": self.class_weight,
|
|
272
|
+
"break_ties": self.break_ties,
|
|
273
|
+
"decision_function_shape": self.decision_function_shape,
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
self._onedal_estimator = onedal_SVC(**onedal_params)
|
|
277
|
+
self._onedal_estimator.fit(X, y, sample_weight, queue=queue)
|
|
278
|
+
|
|
279
|
+
if self.probability:
|
|
280
|
+
self._fit_proba(X, y, sample_weight, queue=queue)
|
|
281
|
+
self._save_attributes()
|
|
282
|
+
|
|
283
|
+
def _onedal_predict(self, X, queue=None):
|
|
284
|
+
return self._onedal_estimator.predict(X, queue=queue)
|
|
285
|
+
|
|
286
|
+
def _onedal_predict_proba(self, X, queue=None):
|
|
287
|
+
if getattr(self, "clf_prob", None) is None:
|
|
288
|
+
raise NotFittedError(
|
|
289
|
+
"predict_proba is not available when fitted with probability=False"
|
|
290
|
+
)
|
|
291
|
+
from .._config import config_context, get_config
|
|
292
|
+
|
|
293
|
+
# We use stock metaestimators below, so the only way
|
|
294
|
+
# to pass a queue is using config_context.
|
|
295
|
+
cfg = get_config()
|
|
296
|
+
cfg["target_offload"] = queue
|
|
297
|
+
with config_context(**cfg):
|
|
298
|
+
return self.clf_prob.predict_proba(X)
|
|
299
|
+
|
|
300
|
+
def _onedal_decision_function(self, X, queue=None):
|
|
301
|
+
return self._onedal_estimator.decision_function(X, queue=queue)
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
from sklearn.svm import SVR as sklearn_SVR
|
|
18
|
+
from sklearn.utils.validation import _deprecate_positional_args
|
|
19
|
+
|
|
20
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
21
|
+
from onedal.svm import SVR as onedal_SVR
|
|
22
|
+
|
|
23
|
+
from .._device_offload import dispatch, wrap_output_data
|
|
24
|
+
from ._common import BaseSVR
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SVR(sklearn_SVR, BaseSVR):
|
|
28
|
+
__doc__ = sklearn_SVR.__doc__
|
|
29
|
+
|
|
30
|
+
if sklearn_check_version("1.2"):
|
|
31
|
+
_parameter_constraints: dict = {**sklearn_SVR._parameter_constraints}
|
|
32
|
+
|
|
33
|
+
@_deprecate_positional_args
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
*,
|
|
37
|
+
kernel="rbf",
|
|
38
|
+
degree=3,
|
|
39
|
+
gamma="scale",
|
|
40
|
+
coef0=0.0,
|
|
41
|
+
tol=1e-3,
|
|
42
|
+
C=1.0,
|
|
43
|
+
epsilon=0.1,
|
|
44
|
+
shrinking=True,
|
|
45
|
+
cache_size=200,
|
|
46
|
+
verbose=False,
|
|
47
|
+
max_iter=-1,
|
|
48
|
+
):
|
|
49
|
+
super().__init__(
|
|
50
|
+
kernel=kernel,
|
|
51
|
+
degree=degree,
|
|
52
|
+
gamma=gamma,
|
|
53
|
+
coef0=coef0,
|
|
54
|
+
tol=tol,
|
|
55
|
+
C=C,
|
|
56
|
+
epsilon=epsilon,
|
|
57
|
+
shrinking=shrinking,
|
|
58
|
+
cache_size=cache_size,
|
|
59
|
+
verbose=verbose,
|
|
60
|
+
max_iter=max_iter,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def fit(self, X, y, sample_weight=None):
|
|
64
|
+
"""
|
|
65
|
+
Fit the SVM model according to the given training data.
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features) \
|
|
70
|
+
or (n_samples, n_samples)
|
|
71
|
+
Training vectors, where `n_samples` is the number of samples
|
|
72
|
+
and `n_features` is the number of features.
|
|
73
|
+
For kernel="precomputed", the expected shape of X is
|
|
74
|
+
(n_samples, n_samples).
|
|
75
|
+
|
|
76
|
+
y : array-like of shape (n_samples,)
|
|
77
|
+
Target values (class labels in classification, real numbers in
|
|
78
|
+
regression).
|
|
79
|
+
|
|
80
|
+
sample_weight : array-like of shape (n_samples,), default=None
|
|
81
|
+
Per-sample weights. Rescale C per sample. Higher weights
|
|
82
|
+
force the classifier to put more emphasis on these points.
|
|
83
|
+
|
|
84
|
+
Returns
|
|
85
|
+
-------
|
|
86
|
+
self : object
|
|
87
|
+
Fitted estimator.
|
|
88
|
+
|
|
89
|
+
Notes
|
|
90
|
+
-----
|
|
91
|
+
If X and y are not C-ordered and contiguous arrays of np.float64 and
|
|
92
|
+
X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
|
|
93
|
+
|
|
94
|
+
If X is a dense array, then the other methods will not support sparse
|
|
95
|
+
matrices as input.
|
|
96
|
+
"""
|
|
97
|
+
if sklearn_check_version("1.2"):
|
|
98
|
+
self._validate_params()
|
|
99
|
+
if sklearn_check_version("1.0"):
|
|
100
|
+
self._check_feature_names(X, reset=True)
|
|
101
|
+
dispatch(
|
|
102
|
+
self,
|
|
103
|
+
"fit",
|
|
104
|
+
{
|
|
105
|
+
"onedal": self.__class__._onedal_fit,
|
|
106
|
+
"sklearn": sklearn_SVR.fit,
|
|
107
|
+
},
|
|
108
|
+
X,
|
|
109
|
+
y,
|
|
110
|
+
sample_weight,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
return self
|
|
114
|
+
|
|
115
|
+
@wrap_output_data
|
|
116
|
+
def predict(self, X):
|
|
117
|
+
"""
|
|
118
|
+
Perform regression on samples in X.
|
|
119
|
+
|
|
120
|
+
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
|
|
121
|
+
|
|
122
|
+
Parameters
|
|
123
|
+
----------
|
|
124
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
125
|
+
For kernel="precomputed", the expected shape of X is
|
|
126
|
+
(n_samples_test, n_samples_train).
|
|
127
|
+
|
|
128
|
+
Returns
|
|
129
|
+
-------
|
|
130
|
+
y_pred : ndarray of shape (n_samples,)
|
|
131
|
+
The predicted values.
|
|
132
|
+
"""
|
|
133
|
+
if sklearn_check_version("1.0"):
|
|
134
|
+
self._check_feature_names(X, reset=False)
|
|
135
|
+
return dispatch(
|
|
136
|
+
self,
|
|
137
|
+
"predict",
|
|
138
|
+
{
|
|
139
|
+
"onedal": self.__class__._onedal_predict,
|
|
140
|
+
"sklearn": sklearn_SVR.predict,
|
|
141
|
+
},
|
|
142
|
+
X,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
|
|
146
|
+
onedal_params = {
|
|
147
|
+
"C": self.C,
|
|
148
|
+
"epsilon": self.epsilon,
|
|
149
|
+
"kernel": self.kernel,
|
|
150
|
+
"degree": self.degree,
|
|
151
|
+
"gamma": self.gamma,
|
|
152
|
+
"coef0": self.coef0,
|
|
153
|
+
"tol": self.tol,
|
|
154
|
+
"shrinking": self.shrinking,
|
|
155
|
+
"cache_size": self.cache_size,
|
|
156
|
+
"max_iter": self.max_iter,
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
self._onedal_estimator = onedal_SVR(**onedal_params)
|
|
160
|
+
self._onedal_estimator.fit(X, y, sample_weight, queue=queue)
|
|
161
|
+
self._save_attributes()
|
|
162
|
+
|
|
163
|
+
def _onedal_predict(self, X, queue=None):
|
|
164
|
+
return self._onedal_estimator.predict(X, queue=queue)
|