scikit-learn-intelex 2024.1.0__py311-none-manylinux1_x86_64.whl → 2024.4.0__py311-none-manylinux1_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.
- {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/METADATA +2 -2
- scikit_learn_intelex-2024.4.0.dist-info/RECORD +101 -0
- sklearnex/__init__.py +9 -7
- sklearnex/_device_offload.py +31 -4
- sklearnex/basic_statistics/__init__.py +2 -1
- sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
- sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +386 -0
- sklearnex/cluster/dbscan.py +6 -4
- sklearnex/conftest.py +63 -0
- sklearnex/{preview/decomposition → covariance}/__init__.py +19 -19
- sklearnex/covariance/incremental_covariance.py +130 -0
- sklearnex/covariance/tests/test_incremental_covariance.py +143 -0
- sklearnex/decomposition/pca.py +319 -1
- sklearnex/decomposition/tests/test_pca.py +34 -5
- sklearnex/dispatcher.py +93 -61
- sklearnex/ensemble/_forest.py +81 -97
- sklearnex/ensemble/tests/test_forest.py +15 -19
- sklearnex/linear_model/__init__.py +1 -2
- sklearnex/linear_model/linear.py +275 -347
- sklearnex/{preview/linear_model → linear_model}/logistic_regression.py +83 -50
- sklearnex/linear_model/tests/test_linear.py +40 -5
- sklearnex/linear_model/tests/test_logreg.py +70 -7
- sklearnex/neighbors/__init__.py +1 -1
- sklearnex/neighbors/_lof.py +221 -0
- sklearnex/neighbors/common.py +4 -1
- sklearnex/neighbors/knn_classification.py +47 -137
- sklearnex/neighbors/knn_regression.py +20 -132
- sklearnex/neighbors/knn_unsupervised.py +16 -93
- sklearnex/neighbors/tests/test_neighbors.py +12 -16
- sklearnex/preview/__init__.py +1 -1
- sklearnex/preview/cluster/k_means.py +8 -81
- sklearnex/preview/covariance/covariance.py +51 -16
- sklearnex/preview/covariance/tests/test_covariance.py +18 -5
- sklearnex/spmd/__init__.py +1 -0
- sklearnex/{preview/linear_model → spmd/covariance}/__init__.py +5 -5
- sklearnex/spmd/covariance/covariance.py +21 -0
- sklearnex/spmd/ensemble/forest.py +4 -12
- sklearnex/spmd/linear_model/__init__.py +2 -1
- sklearnex/spmd/linear_model/logistic_regression.py +21 -0
- sklearnex/svm/_common.py +4 -7
- sklearnex/svm/nusvc.py +74 -55
- sklearnex/svm/nusvr.py +9 -56
- sklearnex/svm/svc.py +74 -56
- sklearnex/svm/svr.py +6 -53
- sklearnex/tests/_utils.py +164 -0
- sklearnex/tests/test_memory_usage.py +9 -7
- sklearnex/tests/test_monkeypatch.py +179 -138
- sklearnex/tests/test_n_jobs_support.py +77 -9
- sklearnex/tests/test_parallel.py +6 -8
- sklearnex/tests/test_patching.py +338 -89
- sklearnex/utils/__init__.py +2 -1
- sklearnex/utils/_namespace.py +97 -0
- scikit_learn_intelex-2024.1.0.dist-info/RECORD +0 -97
- sklearnex/neighbors/lof.py +0 -436
- sklearnex/preview/decomposition/pca.py +0 -376
- sklearnex/preview/decomposition/tests/test_preview_pca.py +0 -42
- sklearnex/preview/linear_model/tests/test_preview_logistic_regression.py +0 -59
- sklearnex/tests/_models_info.py +0 -170
- sklearnex/tests/utils/_launch_algorithms.py +0 -118
- {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/WHEEL +0 -0
- {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/top_level.txt +0 -0
sklearnex/svm/nusvc.py
CHANGED
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
# ==============================================================================
|
|
16
16
|
|
|
17
|
+
import numpy as np
|
|
17
18
|
from sklearn.exceptions import NotFittedError
|
|
19
|
+
from sklearn.metrics import accuracy_score
|
|
18
20
|
from sklearn.svm import NuSVC as sklearn_NuSVC
|
|
19
21
|
from sklearn.utils.validation import _deprecate_positional_args
|
|
20
22
|
|
|
21
|
-
from daal4py.sklearn.
|
|
23
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
24
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
25
|
+
from sklearnex.utils import get_namespace
|
|
22
26
|
|
|
23
27
|
from .._device_offload import dispatch, wrap_output_data
|
|
24
28
|
from ._common import BaseSVC
|
|
@@ -29,7 +33,9 @@ if sklearn_check_version("1.0"):
|
|
|
29
33
|
from onedal.svm import NuSVC as onedal_NuSVC
|
|
30
34
|
|
|
31
35
|
|
|
32
|
-
@control_n_jobs
|
|
36
|
+
@control_n_jobs(
|
|
37
|
+
decorated_methods=["fit", "predict", "_predict_proba", "decision_function", "score"]
|
|
38
|
+
)
|
|
33
39
|
class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
34
40
|
__doc__ = sklearn_NuSVC.__doc__
|
|
35
41
|
|
|
@@ -75,39 +81,6 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
75
81
|
)
|
|
76
82
|
|
|
77
83
|
def fit(self, X, y, sample_weight=None):
|
|
78
|
-
"""
|
|
79
|
-
Fit the SVM model according to the given training data.
|
|
80
|
-
|
|
81
|
-
Parameters
|
|
82
|
-
----------
|
|
83
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features) \
|
|
84
|
-
or (n_samples, n_samples)
|
|
85
|
-
Training vectors, where `n_samples` is the number of samples
|
|
86
|
-
and `n_features` is the number of features.
|
|
87
|
-
For kernel="precomputed", the expected shape of X is
|
|
88
|
-
(n_samples, n_samples).
|
|
89
|
-
|
|
90
|
-
y : array-like of shape (n_samples,)
|
|
91
|
-
Target values (class labels in classification, real numbers in
|
|
92
|
-
regression).
|
|
93
|
-
|
|
94
|
-
sample_weight : array-like of shape (n_samples,), default=None
|
|
95
|
-
Per-sample weights. Rescale C per sample. Higher weights
|
|
96
|
-
force the classifier to put more emphasis on these points.
|
|
97
|
-
|
|
98
|
-
Returns
|
|
99
|
-
-------
|
|
100
|
-
self : object
|
|
101
|
-
Fitted estimator.
|
|
102
|
-
|
|
103
|
-
Notes
|
|
104
|
-
-----
|
|
105
|
-
If X and y are not C-ordered and contiguous arrays of np.float64 and
|
|
106
|
-
X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
|
|
107
|
-
|
|
108
|
-
If X is a dense array, then the other methods will not support sparse
|
|
109
|
-
matrices as input.
|
|
110
|
-
"""
|
|
111
84
|
if sklearn_check_version("1.2"):
|
|
112
85
|
self._validate_params()
|
|
113
86
|
if sklearn_check_version("1.0"):
|
|
@@ -128,22 +101,6 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
128
101
|
|
|
129
102
|
@wrap_output_data
|
|
130
103
|
def predict(self, X):
|
|
131
|
-
"""
|
|
132
|
-
Perform regression on samples in X.
|
|
133
|
-
|
|
134
|
-
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
|
|
135
|
-
|
|
136
|
-
Parameters
|
|
137
|
-
----------
|
|
138
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
139
|
-
For kernel="precomputed", the expected shape of X is
|
|
140
|
-
(n_samples_test, n_samples_train).
|
|
141
|
-
|
|
142
|
-
Returns
|
|
143
|
-
-------
|
|
144
|
-
y_pred : ndarray of shape (n_samples,)
|
|
145
|
-
The predicted values.
|
|
146
|
-
"""
|
|
147
104
|
if sklearn_check_version("1.0"):
|
|
148
105
|
self._check_feature_names(X, reset=False)
|
|
149
106
|
return dispatch(
|
|
@@ -156,6 +113,22 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
156
113
|
X,
|
|
157
114
|
)
|
|
158
115
|
|
|
116
|
+
@wrap_output_data
|
|
117
|
+
def score(self, X, y, sample_weight=None):
|
|
118
|
+
if sklearn_check_version("1.0"):
|
|
119
|
+
self._check_feature_names(X, reset=False)
|
|
120
|
+
return dispatch(
|
|
121
|
+
self,
|
|
122
|
+
"score",
|
|
123
|
+
{
|
|
124
|
+
"onedal": self.__class__._onedal_score,
|
|
125
|
+
"sklearn": sklearn_NuSVC.score,
|
|
126
|
+
},
|
|
127
|
+
X,
|
|
128
|
+
y,
|
|
129
|
+
sample_weight=sample_weight,
|
|
130
|
+
)
|
|
131
|
+
|
|
159
132
|
if sklearn_check_version("1.0"):
|
|
160
133
|
|
|
161
134
|
@available_if(sklearn_NuSVC._check_proba)
|
|
@@ -188,6 +161,38 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
188
161
|
"""
|
|
189
162
|
return self._predict_proba(X)
|
|
190
163
|
|
|
164
|
+
@available_if(sklearn_NuSVC._check_proba)
|
|
165
|
+
def predict_log_proba(self, X):
|
|
166
|
+
"""Compute log probabilities of possible outcomes for samples in X.
|
|
167
|
+
|
|
168
|
+
The model need to have probability information computed at training
|
|
169
|
+
time: fit with attribute `probability` set to True.
|
|
170
|
+
|
|
171
|
+
Parameters
|
|
172
|
+
----------
|
|
173
|
+
X : array-like of shape (n_samples, n_features) or \
|
|
174
|
+
(n_samples_test, n_samples_train)
|
|
175
|
+
For kernel="precomputed", the expected shape of X is
|
|
176
|
+
(n_samples_test, n_samples_train).
|
|
177
|
+
|
|
178
|
+
Returns
|
|
179
|
+
-------
|
|
180
|
+
T : ndarray of shape (n_samples, n_classes)
|
|
181
|
+
Returns the log-probabilities of the sample for each class in
|
|
182
|
+
the model. The columns correspond to the classes in sorted
|
|
183
|
+
order, as they appear in the attribute :term:`classes_`.
|
|
184
|
+
|
|
185
|
+
Notes
|
|
186
|
+
-----
|
|
187
|
+
The probability model is created using cross validation, so
|
|
188
|
+
the results can be slightly different than those obtained by
|
|
189
|
+
predict. Also, it will produce meaningless results on very small
|
|
190
|
+
datasets.
|
|
191
|
+
"""
|
|
192
|
+
xp, _ = get_namespace(X)
|
|
193
|
+
|
|
194
|
+
return xp.log(self.predict_proba(X))
|
|
195
|
+
|
|
191
196
|
else:
|
|
192
197
|
|
|
193
198
|
@property
|
|
@@ -195,6 +200,12 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
195
200
|
self._check_proba()
|
|
196
201
|
return self._predict_proba
|
|
197
202
|
|
|
203
|
+
def _predict_log_proba(self, X):
|
|
204
|
+
xp, _ = get_namespace(X)
|
|
205
|
+
return xp.log(self.predict_proba(X))
|
|
206
|
+
|
|
207
|
+
predict_proba.__doc__ = sklearn_NuSVC.predict_proba.__doc__
|
|
208
|
+
|
|
198
209
|
@wrap_output_data
|
|
199
210
|
def _predict_proba(self, X):
|
|
200
211
|
if sklearn_check_version("1.0"):
|
|
@@ -229,7 +240,8 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
229
240
|
X,
|
|
230
241
|
)
|
|
231
242
|
|
|
232
|
-
|
|
243
|
+
decision_function.__doc__ = sklearn_NuSVC.decision_function.__doc__
|
|
244
|
+
|
|
233
245
|
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
|
|
234
246
|
onedal_params = {
|
|
235
247
|
"nu": self.nu,
|
|
@@ -253,11 +265,9 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
253
265
|
self._fit_proba(X, y, sample_weight, queue=queue)
|
|
254
266
|
self._save_attributes()
|
|
255
267
|
|
|
256
|
-
@run_with_n_jobs
|
|
257
268
|
def _onedal_predict(self, X, queue=None):
|
|
258
269
|
return self._onedal_estimator.predict(X, queue=queue)
|
|
259
270
|
|
|
260
|
-
@run_with_n_jobs
|
|
261
271
|
def _onedal_predict_proba(self, X, queue=None):
|
|
262
272
|
if getattr(self, "clf_prob", None) is None:
|
|
263
273
|
raise NotFittedError(
|
|
@@ -272,6 +282,15 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
272
282
|
with config_context(**cfg):
|
|
273
283
|
return self.clf_prob.predict_proba(X)
|
|
274
284
|
|
|
275
|
-
@run_with_n_jobs
|
|
276
285
|
def _onedal_decision_function(self, X, queue=None):
|
|
277
286
|
return self._onedal_estimator.decision_function(X, queue=queue)
|
|
287
|
+
|
|
288
|
+
def _onedal_score(self, X, y, sample_weight=None, queue=None):
|
|
289
|
+
return accuracy_score(
|
|
290
|
+
y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
fit.__doc__ = sklearn_NuSVC.fit.__doc__
|
|
294
|
+
predict.__doc__ = sklearn_NuSVC.predict.__doc__
|
|
295
|
+
decision_function.__doc__ = sklearn_NuSVC.decision_function.__doc__
|
|
296
|
+
score.__doc__ = sklearn_NuSVC.score.__doc__
|
sklearnex/svm/nusvr.py
CHANGED
|
@@ -17,14 +17,15 @@
|
|
|
17
17
|
from sklearn.svm import NuSVR as sklearn_NuSVR
|
|
18
18
|
from sklearn.utils.validation import _deprecate_positional_args
|
|
19
19
|
|
|
20
|
-
from daal4py.sklearn.
|
|
20
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
21
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
21
22
|
from onedal.svm import NuSVR as onedal_NuSVR
|
|
22
23
|
|
|
23
24
|
from .._device_offload import dispatch, wrap_output_data
|
|
24
25
|
from ._common import BaseSVR
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
@control_n_jobs
|
|
28
|
+
@control_n_jobs(decorated_methods=["fit", "predict"])
|
|
28
29
|
class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
29
30
|
__doc__ = sklearn_NuSVR.__doc__
|
|
30
31
|
|
|
@@ -35,14 +36,14 @@ class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
|
35
36
|
def __init__(
|
|
36
37
|
self,
|
|
37
38
|
*,
|
|
39
|
+
nu=0.5,
|
|
40
|
+
C=1.0,
|
|
38
41
|
kernel="rbf",
|
|
39
42
|
degree=3,
|
|
40
43
|
gamma="scale",
|
|
41
44
|
coef0=0.0,
|
|
42
|
-
tol=1e-3,
|
|
43
|
-
C=1.0,
|
|
44
|
-
nu=0.5,
|
|
45
45
|
shrinking=True,
|
|
46
|
+
tol=1e-3,
|
|
46
47
|
cache_size=200,
|
|
47
48
|
verbose=False,
|
|
48
49
|
max_iter=-1,
|
|
@@ -62,39 +63,6 @@ class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
|
62
63
|
)
|
|
63
64
|
|
|
64
65
|
def fit(self, X, y, sample_weight=None):
|
|
65
|
-
"""
|
|
66
|
-
Fit the SVM model according to the given training data.
|
|
67
|
-
|
|
68
|
-
Parameters
|
|
69
|
-
----------
|
|
70
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features) \
|
|
71
|
-
or (n_samples, n_samples)
|
|
72
|
-
Training vectors, where `n_samples` is the number of samples
|
|
73
|
-
and `n_features` is the number of features.
|
|
74
|
-
For kernel="precomputed", the expected shape of X is
|
|
75
|
-
(n_samples, n_samples).
|
|
76
|
-
|
|
77
|
-
y : array-like of shape (n_samples,)
|
|
78
|
-
Target values (class labels in classification, real numbers in
|
|
79
|
-
regression).
|
|
80
|
-
|
|
81
|
-
sample_weight : array-like of shape (n_samples,), default=None
|
|
82
|
-
Per-sample weights. Rescale C per sample. Higher weights
|
|
83
|
-
force the classifier to put more emphasis on these points.
|
|
84
|
-
|
|
85
|
-
Returns
|
|
86
|
-
-------
|
|
87
|
-
self : object
|
|
88
|
-
Fitted estimator.
|
|
89
|
-
|
|
90
|
-
Notes
|
|
91
|
-
-----
|
|
92
|
-
If X and y are not C-ordered and contiguous arrays of np.float64 and
|
|
93
|
-
X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
|
|
94
|
-
|
|
95
|
-
If X is a dense array, then the other methods will not support sparse
|
|
96
|
-
matrices as input.
|
|
97
|
-
"""
|
|
98
66
|
if sklearn_check_version("1.2"):
|
|
99
67
|
self._validate_params()
|
|
100
68
|
if sklearn_check_version("1.0"):
|
|
@@ -114,22 +82,6 @@ class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
|
114
82
|
|
|
115
83
|
@wrap_output_data
|
|
116
84
|
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
85
|
if sklearn_check_version("1.0"):
|
|
134
86
|
self._check_feature_names(X, reset=False)
|
|
135
87
|
return dispatch(
|
|
@@ -142,7 +94,6 @@ class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
|
142
94
|
X,
|
|
143
95
|
)
|
|
144
96
|
|
|
145
|
-
@run_with_n_jobs
|
|
146
97
|
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
|
|
147
98
|
onedal_params = {
|
|
148
99
|
"C": self.C,
|
|
@@ -161,6 +112,8 @@ class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
|
161
112
|
self._onedal_estimator.fit(X, y, sample_weight, queue=queue)
|
|
162
113
|
self._save_attributes()
|
|
163
114
|
|
|
164
|
-
@run_with_n_jobs
|
|
165
115
|
def _onedal_predict(self, X, queue=None):
|
|
166
116
|
return self._onedal_estimator.predict(X, queue=queue)
|
|
117
|
+
|
|
118
|
+
fit.__doc__ = sklearn_NuSVR.fit.__doc__
|
|
119
|
+
predict.__doc__ = sklearn_NuSVR.predict.__doc__
|
sklearnex/svm/svc.py
CHANGED
|
@@ -17,10 +17,13 @@
|
|
|
17
17
|
import numpy as np
|
|
18
18
|
from scipy import sparse as sp
|
|
19
19
|
from sklearn.exceptions import NotFittedError
|
|
20
|
+
from sklearn.metrics import accuracy_score
|
|
20
21
|
from sklearn.svm import SVC as sklearn_SVC
|
|
21
22
|
from sklearn.utils.validation import _deprecate_positional_args
|
|
22
23
|
|
|
23
|
-
from daal4py.sklearn.
|
|
24
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
25
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
26
|
+
from sklearnex.utils import get_namespace
|
|
24
27
|
|
|
25
28
|
from .._device_offload import dispatch, wrap_output_data
|
|
26
29
|
from .._utils import PatchingConditionsChain
|
|
@@ -32,7 +35,9 @@ if sklearn_check_version("1.0"):
|
|
|
32
35
|
from onedal.svm import SVC as onedal_SVC
|
|
33
36
|
|
|
34
37
|
|
|
35
|
-
@control_n_jobs
|
|
38
|
+
@control_n_jobs(
|
|
39
|
+
decorated_methods=["fit", "predict", "_predict_proba", "decision_function", "score"]
|
|
40
|
+
)
|
|
36
41
|
class SVC(sklearn_SVC, BaseSVC):
|
|
37
42
|
__doc__ = sklearn_SVC.__doc__
|
|
38
43
|
|
|
@@ -78,39 +83,6 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
78
83
|
)
|
|
79
84
|
|
|
80
85
|
def fit(self, X, y, sample_weight=None):
|
|
81
|
-
"""
|
|
82
|
-
Fit the SVM model according to the given training data.
|
|
83
|
-
|
|
84
|
-
Parameters
|
|
85
|
-
----------
|
|
86
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features) \
|
|
87
|
-
or (n_samples, n_samples)
|
|
88
|
-
Training vectors, where `n_samples` is the number of samples
|
|
89
|
-
and `n_features` is the number of features.
|
|
90
|
-
For kernel="precomputed", the expected shape of X is
|
|
91
|
-
(n_samples, n_samples).
|
|
92
|
-
|
|
93
|
-
y : array-like of shape (n_samples,)
|
|
94
|
-
Target values (class labels in classification, real numbers in
|
|
95
|
-
regression).
|
|
96
|
-
|
|
97
|
-
sample_weight : array-like of shape (n_samples,), default=None
|
|
98
|
-
Per-sample weights. Rescale C per sample. Higher weights
|
|
99
|
-
force the classifier to put more emphasis on these points.
|
|
100
|
-
|
|
101
|
-
Returns
|
|
102
|
-
-------
|
|
103
|
-
self : object
|
|
104
|
-
Fitted estimator.
|
|
105
|
-
|
|
106
|
-
Notes
|
|
107
|
-
-----
|
|
108
|
-
If X and y are not C-ordered and contiguous arrays of np.float64 and
|
|
109
|
-
X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
|
|
110
|
-
|
|
111
|
-
If X is a dense array, then the other methods will not support sparse
|
|
112
|
-
matrices as input.
|
|
113
|
-
"""
|
|
114
86
|
if sklearn_check_version("1.2"):
|
|
115
87
|
self._validate_params()
|
|
116
88
|
if sklearn_check_version("1.0"):
|
|
@@ -130,22 +102,6 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
130
102
|
|
|
131
103
|
@wrap_output_data
|
|
132
104
|
def predict(self, X):
|
|
133
|
-
"""
|
|
134
|
-
Perform regression on samples in X.
|
|
135
|
-
|
|
136
|
-
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
|
|
137
|
-
|
|
138
|
-
Parameters
|
|
139
|
-
----------
|
|
140
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
141
|
-
For kernel="precomputed", the expected shape of X is
|
|
142
|
-
(n_samples_test, n_samples_train).
|
|
143
|
-
|
|
144
|
-
Returns
|
|
145
|
-
-------
|
|
146
|
-
y_pred : ndarray of shape (n_samples,)
|
|
147
|
-
The predicted values.
|
|
148
|
-
"""
|
|
149
105
|
if sklearn_check_version("1.0"):
|
|
150
106
|
self._check_feature_names(X, reset=False)
|
|
151
107
|
return dispatch(
|
|
@@ -158,6 +114,22 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
158
114
|
X,
|
|
159
115
|
)
|
|
160
116
|
|
|
117
|
+
@wrap_output_data
|
|
118
|
+
def score(self, X, y, sample_weight=None):
|
|
119
|
+
if sklearn_check_version("1.0"):
|
|
120
|
+
self._check_feature_names(X, reset=False)
|
|
121
|
+
return dispatch(
|
|
122
|
+
self,
|
|
123
|
+
"score",
|
|
124
|
+
{
|
|
125
|
+
"onedal": self.__class__._onedal_score,
|
|
126
|
+
"sklearn": sklearn_SVC.score,
|
|
127
|
+
},
|
|
128
|
+
X,
|
|
129
|
+
y,
|
|
130
|
+
sample_weight=sample_weight,
|
|
131
|
+
)
|
|
132
|
+
|
|
161
133
|
if sklearn_check_version("1.0"):
|
|
162
134
|
|
|
163
135
|
@available_if(sklearn_SVC._check_proba)
|
|
@@ -190,6 +162,38 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
190
162
|
"""
|
|
191
163
|
return self._predict_proba(X)
|
|
192
164
|
|
|
165
|
+
@available_if(sklearn_SVC._check_proba)
|
|
166
|
+
def predict_log_proba(self, X):
|
|
167
|
+
"""Compute log probabilities of possible outcomes for samples in X.
|
|
168
|
+
|
|
169
|
+
The model need to have probability information computed at training
|
|
170
|
+
time: fit with attribute `probability` set to True.
|
|
171
|
+
|
|
172
|
+
Parameters
|
|
173
|
+
----------
|
|
174
|
+
X : array-like of shape (n_samples, n_features) or \
|
|
175
|
+
(n_samples_test, n_samples_train)
|
|
176
|
+
For kernel="precomputed", the expected shape of X is
|
|
177
|
+
(n_samples_test, n_samples_train).
|
|
178
|
+
|
|
179
|
+
Returns
|
|
180
|
+
-------
|
|
181
|
+
T : ndarray of shape (n_samples, n_classes)
|
|
182
|
+
Returns the log-probabilities of the sample for each class in
|
|
183
|
+
the model. The columns correspond to the classes in sorted
|
|
184
|
+
order, as they appear in the attribute :term:`classes_`.
|
|
185
|
+
|
|
186
|
+
Notes
|
|
187
|
+
-----
|
|
188
|
+
The probability model is created using cross validation, so
|
|
189
|
+
the results can be slightly different than those obtained by
|
|
190
|
+
predict. Also, it will produce meaningless results on very small
|
|
191
|
+
datasets.
|
|
192
|
+
"""
|
|
193
|
+
xp, _ = get_namespace(X)
|
|
194
|
+
|
|
195
|
+
return xp.log(self.predict_proba(X))
|
|
196
|
+
|
|
193
197
|
else:
|
|
194
198
|
|
|
195
199
|
@property
|
|
@@ -197,6 +201,12 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
197
201
|
self._check_proba()
|
|
198
202
|
return self._predict_proba
|
|
199
203
|
|
|
204
|
+
def _predict_log_proba(self, X):
|
|
205
|
+
xp, _ = get_namespace(X)
|
|
206
|
+
return xp.log(self.predict_proba(X))
|
|
207
|
+
|
|
208
|
+
predict_proba.__doc__ = sklearn_SVC.predict_proba.__doc__
|
|
209
|
+
|
|
200
210
|
@wrap_output_data
|
|
201
211
|
def _predict_proba(self, X):
|
|
202
212
|
sklearn_pred_proba = (
|
|
@@ -229,6 +239,8 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
229
239
|
X,
|
|
230
240
|
)
|
|
231
241
|
|
|
242
|
+
decision_function.__doc__ = sklearn_SVC.decision_function.__doc__
|
|
243
|
+
|
|
232
244
|
def _onedal_gpu_supported(self, method_name, *data):
|
|
233
245
|
class_name = self.__class__.__name__
|
|
234
246
|
patching_status = PatchingConditionsChain(
|
|
@@ -250,7 +262,7 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
250
262
|
if method_name == "fit":
|
|
251
263
|
patching_status.and_conditions(conditions)
|
|
252
264
|
return patching_status
|
|
253
|
-
if method_name in ["predict", "predict_proba", "decision_function"]:
|
|
265
|
+
if method_name in ["predict", "predict_proba", "decision_function", "score"]:
|
|
254
266
|
conditions.append(
|
|
255
267
|
(hasattr(self, "_onedal_estimator"), "oneDAL model was not trained")
|
|
256
268
|
)
|
|
@@ -258,7 +270,6 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
258
270
|
return patching_status
|
|
259
271
|
raise RuntimeError(f"Unknown method {method_name} in {class_name}")
|
|
260
272
|
|
|
261
|
-
@run_with_n_jobs
|
|
262
273
|
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
|
|
263
274
|
onedal_params = {
|
|
264
275
|
"C": self.C,
|
|
@@ -282,11 +293,9 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
282
293
|
self._fit_proba(X, y, sample_weight, queue=queue)
|
|
283
294
|
self._save_attributes()
|
|
284
295
|
|
|
285
|
-
@run_with_n_jobs
|
|
286
296
|
def _onedal_predict(self, X, queue=None):
|
|
287
297
|
return self._onedal_estimator.predict(X, queue=queue)
|
|
288
298
|
|
|
289
|
-
@run_with_n_jobs
|
|
290
299
|
def _onedal_predict_proba(self, X, queue=None):
|
|
291
300
|
if getattr(self, "clf_prob", None) is None:
|
|
292
301
|
raise NotFittedError(
|
|
@@ -301,6 +310,15 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
301
310
|
with config_context(**cfg):
|
|
302
311
|
return self.clf_prob.predict_proba(X)
|
|
303
312
|
|
|
304
|
-
@run_with_n_jobs
|
|
305
313
|
def _onedal_decision_function(self, X, queue=None):
|
|
306
314
|
return self._onedal_estimator.decision_function(X, queue=queue)
|
|
315
|
+
|
|
316
|
+
def _onedal_score(self, X, y, sample_weight=None, queue=None):
|
|
317
|
+
return accuracy_score(
|
|
318
|
+
y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
fit.__doc__ = sklearn_SVC.fit.__doc__
|
|
322
|
+
predict.__doc__ = sklearn_SVC.predict.__doc__
|
|
323
|
+
decision_function.__doc__ = sklearn_SVC.decision_function.__doc__
|
|
324
|
+
score.__doc__ = sklearn_SVC.score.__doc__
|
sklearnex/svm/svr.py
CHANGED
|
@@ -17,14 +17,15 @@
|
|
|
17
17
|
from sklearn.svm import SVR as sklearn_SVR
|
|
18
18
|
from sklearn.utils.validation import _deprecate_positional_args
|
|
19
19
|
|
|
20
|
-
from daal4py.sklearn.
|
|
20
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
21
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
21
22
|
from onedal.svm import SVR as onedal_SVR
|
|
22
23
|
|
|
23
24
|
from .._device_offload import dispatch, wrap_output_data
|
|
24
25
|
from ._common import BaseSVR
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
@control_n_jobs
|
|
28
|
+
@control_n_jobs(decorated_methods=["fit", "predict"])
|
|
28
29
|
class SVR(sklearn_SVR, BaseSVR):
|
|
29
30
|
__doc__ = sklearn_SVR.__doc__
|
|
30
31
|
|
|
@@ -62,39 +63,6 @@ class SVR(sklearn_SVR, BaseSVR):
|
|
|
62
63
|
)
|
|
63
64
|
|
|
64
65
|
def fit(self, X, y, sample_weight=None):
|
|
65
|
-
"""
|
|
66
|
-
Fit the SVM model according to the given training data.
|
|
67
|
-
|
|
68
|
-
Parameters
|
|
69
|
-
----------
|
|
70
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features) \
|
|
71
|
-
or (n_samples, n_samples)
|
|
72
|
-
Training vectors, where `n_samples` is the number of samples
|
|
73
|
-
and `n_features` is the number of features.
|
|
74
|
-
For kernel="precomputed", the expected shape of X is
|
|
75
|
-
(n_samples, n_samples).
|
|
76
|
-
|
|
77
|
-
y : array-like of shape (n_samples,)
|
|
78
|
-
Target values (class labels in classification, real numbers in
|
|
79
|
-
regression).
|
|
80
|
-
|
|
81
|
-
sample_weight : array-like of shape (n_samples,), default=None
|
|
82
|
-
Per-sample weights. Rescale C per sample. Higher weights
|
|
83
|
-
force the classifier to put more emphasis on these points.
|
|
84
|
-
|
|
85
|
-
Returns
|
|
86
|
-
-------
|
|
87
|
-
self : object
|
|
88
|
-
Fitted estimator.
|
|
89
|
-
|
|
90
|
-
Notes
|
|
91
|
-
-----
|
|
92
|
-
If X and y are not C-ordered and contiguous arrays of np.float64 and
|
|
93
|
-
X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
|
|
94
|
-
|
|
95
|
-
If X is a dense array, then the other methods will not support sparse
|
|
96
|
-
matrices as input.
|
|
97
|
-
"""
|
|
98
66
|
if sklearn_check_version("1.2"):
|
|
99
67
|
self._validate_params()
|
|
100
68
|
if sklearn_check_version("1.0"):
|
|
@@ -115,22 +83,6 @@ class SVR(sklearn_SVR, BaseSVR):
|
|
|
115
83
|
|
|
116
84
|
@wrap_output_data
|
|
117
85
|
def predict(self, X):
|
|
118
|
-
"""
|
|
119
|
-
Perform regression on samples in X.
|
|
120
|
-
|
|
121
|
-
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
|
|
122
|
-
|
|
123
|
-
Parameters
|
|
124
|
-
----------
|
|
125
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
126
|
-
For kernel="precomputed", the expected shape of X is
|
|
127
|
-
(n_samples_test, n_samples_train).
|
|
128
|
-
|
|
129
|
-
Returns
|
|
130
|
-
-------
|
|
131
|
-
y_pred : ndarray of shape (n_samples,)
|
|
132
|
-
The predicted values.
|
|
133
|
-
"""
|
|
134
86
|
if sklearn_check_version("1.0"):
|
|
135
87
|
self._check_feature_names(X, reset=False)
|
|
136
88
|
return dispatch(
|
|
@@ -143,7 +95,6 @@ class SVR(sklearn_SVR, BaseSVR):
|
|
|
143
95
|
X,
|
|
144
96
|
)
|
|
145
97
|
|
|
146
|
-
@run_with_n_jobs
|
|
147
98
|
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
|
|
148
99
|
onedal_params = {
|
|
149
100
|
"C": self.C,
|
|
@@ -162,6 +113,8 @@ class SVR(sklearn_SVR, BaseSVR):
|
|
|
162
113
|
self._onedal_estimator.fit(X, y, sample_weight, queue=queue)
|
|
163
114
|
self._save_attributes()
|
|
164
115
|
|
|
165
|
-
@run_with_n_jobs
|
|
166
116
|
def _onedal_predict(self, X, queue=None):
|
|
167
117
|
return self._onedal_estimator.predict(X, queue=queue)
|
|
118
|
+
|
|
119
|
+
fit.__doc__ = sklearn_SVR.fit.__doc__
|
|
120
|
+
predict.__doc__ = sklearn_SVR.predict.__doc__
|