scikit-learn-intelex 2024.2.0__py312-none-manylinux1_x86_64.whl → 2024.4.0__py312-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.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/METADATA +2 -2
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/RECORD +45 -45
- 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 +3 -1
- sklearnex/conftest.py +63 -0
- sklearnex/decomposition/pca.py +319 -1
- sklearnex/decomposition/tests/test_pca.py +34 -5
- sklearnex/dispatcher.py +74 -43
- sklearnex/ensemble/_forest.py +78 -89
- sklearnex/ensemble/tests/test_forest.py +15 -19
- sklearnex/linear_model/linear.py +275 -340
- sklearnex/linear_model/logistic_regression.py +63 -11
- sklearnex/linear_model/tests/test_linear.py +40 -5
- sklearnex/linear_model/tests/test_logreg.py +0 -2
- sklearnex/neighbors/_lof.py +74 -20
- sklearnex/neighbors/common.py +4 -1
- sklearnex/neighbors/knn_classification.py +44 -131
- sklearnex/neighbors/knn_regression.py +16 -126
- sklearnex/neighbors/knn_unsupervised.py +11 -86
- sklearnex/neighbors/tests/test_neighbors.py +0 -5
- sklearnex/preview/__init__.py +1 -1
- sklearnex/preview/cluster/k_means.py +5 -73
- sklearnex/preview/covariance/covariance.py +6 -5
- sklearnex/preview/covariance/tests/test_covariance.py +18 -5
- sklearnex/spmd/ensemble/forest.py +4 -12
- sklearnex/svm/_common.py +4 -7
- sklearnex/svm/nusvc.py +70 -50
- sklearnex/svm/nusvr.py +6 -52
- sklearnex/svm/svc.py +70 -51
- sklearnex/svm/svr.py +3 -49
- sklearnex/tests/_utils.py +164 -0
- sklearnex/tests/test_memory_usage.py +8 -3
- sklearnex/tests/test_monkeypatch.py +177 -149
- sklearnex/tests/test_n_jobs_support.py +8 -2
- sklearnex/tests/test_parallel.py +6 -8
- sklearnex/tests/test_patching.py +322 -87
- sklearnex/utils/__init__.py +2 -1
- sklearnex/utils/_namespace.py +97 -0
- sklearnex/preview/decomposition/__init__.py +0 -19
- sklearnex/preview/decomposition/pca.py +0 -374
- sklearnex/preview/decomposition/tests/test_preview_pca.py +0 -42
- sklearnex/tests/_models_info.py +0 -170
- sklearnex/tests/utils/_launch_algorithms.py +0 -118
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/WHEEL +0 -0
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/top_level.txt +0 -0
sklearnex/svm/nusvc.py
CHANGED
|
@@ -14,12 +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
23
|
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
22
24
|
from daal4py.sklearn._utils import sklearn_check_version
|
|
25
|
+
from sklearnex.utils import get_namespace
|
|
23
26
|
|
|
24
27
|
from .._device_offload import dispatch, wrap_output_data
|
|
25
28
|
from ._common import BaseSVC
|
|
@@ -31,7 +34,7 @@ from onedal.svm import NuSVC as onedal_NuSVC
|
|
|
31
34
|
|
|
32
35
|
|
|
33
36
|
@control_n_jobs(
|
|
34
|
-
decorated_methods=["fit", "predict", "_predict_proba", "decision_function"]
|
|
37
|
+
decorated_methods=["fit", "predict", "_predict_proba", "decision_function", "score"]
|
|
35
38
|
)
|
|
36
39
|
class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
37
40
|
__doc__ = sklearn_NuSVC.__doc__
|
|
@@ -78,39 +81,6 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
78
81
|
)
|
|
79
82
|
|
|
80
83
|
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
84
|
if sklearn_check_version("1.2"):
|
|
115
85
|
self._validate_params()
|
|
116
86
|
if sklearn_check_version("1.0"):
|
|
@@ -131,22 +101,6 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
131
101
|
|
|
132
102
|
@wrap_output_data
|
|
133
103
|
def predict(self, X):
|
|
134
|
-
"""
|
|
135
|
-
Perform regression on samples in X.
|
|
136
|
-
|
|
137
|
-
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
|
|
138
|
-
|
|
139
|
-
Parameters
|
|
140
|
-
----------
|
|
141
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
142
|
-
For kernel="precomputed", the expected shape of X is
|
|
143
|
-
(n_samples_test, n_samples_train).
|
|
144
|
-
|
|
145
|
-
Returns
|
|
146
|
-
-------
|
|
147
|
-
y_pred : ndarray of shape (n_samples,)
|
|
148
|
-
The predicted values.
|
|
149
|
-
"""
|
|
150
104
|
if sklearn_check_version("1.0"):
|
|
151
105
|
self._check_feature_names(X, reset=False)
|
|
152
106
|
return dispatch(
|
|
@@ -159,6 +113,22 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
159
113
|
X,
|
|
160
114
|
)
|
|
161
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
|
+
|
|
162
132
|
if sklearn_check_version("1.0"):
|
|
163
133
|
|
|
164
134
|
@available_if(sklearn_NuSVC._check_proba)
|
|
@@ -191,6 +161,38 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
191
161
|
"""
|
|
192
162
|
return self._predict_proba(X)
|
|
193
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
|
+
|
|
194
196
|
else:
|
|
195
197
|
|
|
196
198
|
@property
|
|
@@ -198,6 +200,12 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
198
200
|
self._check_proba()
|
|
199
201
|
return self._predict_proba
|
|
200
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
|
+
|
|
201
209
|
@wrap_output_data
|
|
202
210
|
def _predict_proba(self, X):
|
|
203
211
|
if sklearn_check_version("1.0"):
|
|
@@ -232,6 +240,8 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
232
240
|
X,
|
|
233
241
|
)
|
|
234
242
|
|
|
243
|
+
decision_function.__doc__ = sklearn_NuSVC.decision_function.__doc__
|
|
244
|
+
|
|
235
245
|
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
|
|
236
246
|
onedal_params = {
|
|
237
247
|
"nu": self.nu,
|
|
@@ -274,3 +284,13 @@ class NuSVC(sklearn_NuSVC, BaseSVC):
|
|
|
274
284
|
|
|
275
285
|
def _onedal_decision_function(self, X, queue=None):
|
|
276
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
|
@@ -36,14 +36,14 @@ class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
|
36
36
|
def __init__(
|
|
37
37
|
self,
|
|
38
38
|
*,
|
|
39
|
+
nu=0.5,
|
|
40
|
+
C=1.0,
|
|
39
41
|
kernel="rbf",
|
|
40
42
|
degree=3,
|
|
41
43
|
gamma="scale",
|
|
42
44
|
coef0=0.0,
|
|
43
|
-
tol=1e-3,
|
|
44
|
-
C=1.0,
|
|
45
|
-
nu=0.5,
|
|
46
45
|
shrinking=True,
|
|
46
|
+
tol=1e-3,
|
|
47
47
|
cache_size=200,
|
|
48
48
|
verbose=False,
|
|
49
49
|
max_iter=-1,
|
|
@@ -63,39 +63,6 @@ class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
|
63
63
|
)
|
|
64
64
|
|
|
65
65
|
def fit(self, X, y, sample_weight=None):
|
|
66
|
-
"""
|
|
67
|
-
Fit the SVM model according to the given training data.
|
|
68
|
-
|
|
69
|
-
Parameters
|
|
70
|
-
----------
|
|
71
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features) \
|
|
72
|
-
or (n_samples, n_samples)
|
|
73
|
-
Training vectors, where `n_samples` is the number of samples
|
|
74
|
-
and `n_features` is the number of features.
|
|
75
|
-
For kernel="precomputed", the expected shape of X is
|
|
76
|
-
(n_samples, n_samples).
|
|
77
|
-
|
|
78
|
-
y : array-like of shape (n_samples,)
|
|
79
|
-
Target values (class labels in classification, real numbers in
|
|
80
|
-
regression).
|
|
81
|
-
|
|
82
|
-
sample_weight : array-like of shape (n_samples,), default=None
|
|
83
|
-
Per-sample weights. Rescale C per sample. Higher weights
|
|
84
|
-
force the classifier to put more emphasis on these points.
|
|
85
|
-
|
|
86
|
-
Returns
|
|
87
|
-
-------
|
|
88
|
-
self : object
|
|
89
|
-
Fitted estimator.
|
|
90
|
-
|
|
91
|
-
Notes
|
|
92
|
-
-----
|
|
93
|
-
If X and y are not C-ordered and contiguous arrays of np.float64 and
|
|
94
|
-
X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
|
|
95
|
-
|
|
96
|
-
If X is a dense array, then the other methods will not support sparse
|
|
97
|
-
matrices as input.
|
|
98
|
-
"""
|
|
99
66
|
if sklearn_check_version("1.2"):
|
|
100
67
|
self._validate_params()
|
|
101
68
|
if sklearn_check_version("1.0"):
|
|
@@ -115,22 +82,6 @@ class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
|
115
82
|
|
|
116
83
|
@wrap_output_data
|
|
117
84
|
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
85
|
if sklearn_check_version("1.0"):
|
|
135
86
|
self._check_feature_names(X, reset=False)
|
|
136
87
|
return dispatch(
|
|
@@ -163,3 +114,6 @@ class NuSVR(sklearn_NuSVR, BaseSVR):
|
|
|
163
114
|
|
|
164
115
|
def _onedal_predict(self, X, queue=None):
|
|
165
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,11 +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
24
|
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
24
25
|
from daal4py.sklearn._utils import sklearn_check_version
|
|
26
|
+
from sklearnex.utils import get_namespace
|
|
25
27
|
|
|
26
28
|
from .._device_offload import dispatch, wrap_output_data
|
|
27
29
|
from .._utils import PatchingConditionsChain
|
|
@@ -34,7 +36,7 @@ from onedal.svm import SVC as onedal_SVC
|
|
|
34
36
|
|
|
35
37
|
|
|
36
38
|
@control_n_jobs(
|
|
37
|
-
decorated_methods=["fit", "predict", "_predict_proba", "decision_function"]
|
|
39
|
+
decorated_methods=["fit", "predict", "_predict_proba", "decision_function", "score"]
|
|
38
40
|
)
|
|
39
41
|
class SVC(sklearn_SVC, BaseSVC):
|
|
40
42
|
__doc__ = sklearn_SVC.__doc__
|
|
@@ -81,39 +83,6 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
81
83
|
)
|
|
82
84
|
|
|
83
85
|
def fit(self, X, y, sample_weight=None):
|
|
84
|
-
"""
|
|
85
|
-
Fit the SVM model according to the given training data.
|
|
86
|
-
|
|
87
|
-
Parameters
|
|
88
|
-
----------
|
|
89
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features) \
|
|
90
|
-
or (n_samples, n_samples)
|
|
91
|
-
Training vectors, where `n_samples` is the number of samples
|
|
92
|
-
and `n_features` is the number of features.
|
|
93
|
-
For kernel="precomputed", the expected shape of X is
|
|
94
|
-
(n_samples, n_samples).
|
|
95
|
-
|
|
96
|
-
y : array-like of shape (n_samples,)
|
|
97
|
-
Target values (class labels in classification, real numbers in
|
|
98
|
-
regression).
|
|
99
|
-
|
|
100
|
-
sample_weight : array-like of shape (n_samples,), default=None
|
|
101
|
-
Per-sample weights. Rescale C per sample. Higher weights
|
|
102
|
-
force the classifier to put more emphasis on these points.
|
|
103
|
-
|
|
104
|
-
Returns
|
|
105
|
-
-------
|
|
106
|
-
self : object
|
|
107
|
-
Fitted estimator.
|
|
108
|
-
|
|
109
|
-
Notes
|
|
110
|
-
-----
|
|
111
|
-
If X and y are not C-ordered and contiguous arrays of np.float64 and
|
|
112
|
-
X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
|
|
113
|
-
|
|
114
|
-
If X is a dense array, then the other methods will not support sparse
|
|
115
|
-
matrices as input.
|
|
116
|
-
"""
|
|
117
86
|
if sklearn_check_version("1.2"):
|
|
118
87
|
self._validate_params()
|
|
119
88
|
if sklearn_check_version("1.0"):
|
|
@@ -133,22 +102,6 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
133
102
|
|
|
134
103
|
@wrap_output_data
|
|
135
104
|
def predict(self, X):
|
|
136
|
-
"""
|
|
137
|
-
Perform regression on samples in X.
|
|
138
|
-
|
|
139
|
-
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
|
|
140
|
-
|
|
141
|
-
Parameters
|
|
142
|
-
----------
|
|
143
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
144
|
-
For kernel="precomputed", the expected shape of X is
|
|
145
|
-
(n_samples_test, n_samples_train).
|
|
146
|
-
|
|
147
|
-
Returns
|
|
148
|
-
-------
|
|
149
|
-
y_pred : ndarray of shape (n_samples,)
|
|
150
|
-
The predicted values.
|
|
151
|
-
"""
|
|
152
105
|
if sklearn_check_version("1.0"):
|
|
153
106
|
self._check_feature_names(X, reset=False)
|
|
154
107
|
return dispatch(
|
|
@@ -161,6 +114,22 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
161
114
|
X,
|
|
162
115
|
)
|
|
163
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
|
+
|
|
164
133
|
if sklearn_check_version("1.0"):
|
|
165
134
|
|
|
166
135
|
@available_if(sklearn_SVC._check_proba)
|
|
@@ -193,6 +162,38 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
193
162
|
"""
|
|
194
163
|
return self._predict_proba(X)
|
|
195
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
|
+
|
|
196
197
|
else:
|
|
197
198
|
|
|
198
199
|
@property
|
|
@@ -200,6 +201,12 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
200
201
|
self._check_proba()
|
|
201
202
|
return self._predict_proba
|
|
202
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
|
+
|
|
203
210
|
@wrap_output_data
|
|
204
211
|
def _predict_proba(self, X):
|
|
205
212
|
sklearn_pred_proba = (
|
|
@@ -232,6 +239,8 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
232
239
|
X,
|
|
233
240
|
)
|
|
234
241
|
|
|
242
|
+
decision_function.__doc__ = sklearn_SVC.decision_function.__doc__
|
|
243
|
+
|
|
235
244
|
def _onedal_gpu_supported(self, method_name, *data):
|
|
236
245
|
class_name = self.__class__.__name__
|
|
237
246
|
patching_status = PatchingConditionsChain(
|
|
@@ -253,7 +262,7 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
253
262
|
if method_name == "fit":
|
|
254
263
|
patching_status.and_conditions(conditions)
|
|
255
264
|
return patching_status
|
|
256
|
-
if method_name in ["predict", "predict_proba", "decision_function"]:
|
|
265
|
+
if method_name in ["predict", "predict_proba", "decision_function", "score"]:
|
|
257
266
|
conditions.append(
|
|
258
267
|
(hasattr(self, "_onedal_estimator"), "oneDAL model was not trained")
|
|
259
268
|
)
|
|
@@ -303,3 +312,13 @@ class SVC(sklearn_SVC, BaseSVC):
|
|
|
303
312
|
|
|
304
313
|
def _onedal_decision_function(self, X, queue=None):
|
|
305
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
|
@@ -63,39 +63,6 @@ class SVR(sklearn_SVR, BaseSVR):
|
|
|
63
63
|
)
|
|
64
64
|
|
|
65
65
|
def fit(self, X, y, sample_weight=None):
|
|
66
|
-
"""
|
|
67
|
-
Fit the SVM model according to the given training data.
|
|
68
|
-
|
|
69
|
-
Parameters
|
|
70
|
-
----------
|
|
71
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features) \
|
|
72
|
-
or (n_samples, n_samples)
|
|
73
|
-
Training vectors, where `n_samples` is the number of samples
|
|
74
|
-
and `n_features` is the number of features.
|
|
75
|
-
For kernel="precomputed", the expected shape of X is
|
|
76
|
-
(n_samples, n_samples).
|
|
77
|
-
|
|
78
|
-
y : array-like of shape (n_samples,)
|
|
79
|
-
Target values (class labels in classification, real numbers in
|
|
80
|
-
regression).
|
|
81
|
-
|
|
82
|
-
sample_weight : array-like of shape (n_samples,), default=None
|
|
83
|
-
Per-sample weights. Rescale C per sample. Higher weights
|
|
84
|
-
force the classifier to put more emphasis on these points.
|
|
85
|
-
|
|
86
|
-
Returns
|
|
87
|
-
-------
|
|
88
|
-
self : object
|
|
89
|
-
Fitted estimator.
|
|
90
|
-
|
|
91
|
-
Notes
|
|
92
|
-
-----
|
|
93
|
-
If X and y are not C-ordered and contiguous arrays of np.float64 and
|
|
94
|
-
X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
|
|
95
|
-
|
|
96
|
-
If X is a dense array, then the other methods will not support sparse
|
|
97
|
-
matrices as input.
|
|
98
|
-
"""
|
|
99
66
|
if sklearn_check_version("1.2"):
|
|
100
67
|
self._validate_params()
|
|
101
68
|
if sklearn_check_version("1.0"):
|
|
@@ -116,22 +83,6 @@ class SVR(sklearn_SVR, BaseSVR):
|
|
|
116
83
|
|
|
117
84
|
@wrap_output_data
|
|
118
85
|
def predict(self, X):
|
|
119
|
-
"""
|
|
120
|
-
Perform regression on samples in X.
|
|
121
|
-
|
|
122
|
-
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
|
|
123
|
-
|
|
124
|
-
Parameters
|
|
125
|
-
----------
|
|
126
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
127
|
-
For kernel="precomputed", the expected shape of X is
|
|
128
|
-
(n_samples_test, n_samples_train).
|
|
129
|
-
|
|
130
|
-
Returns
|
|
131
|
-
-------
|
|
132
|
-
y_pred : ndarray of shape (n_samples,)
|
|
133
|
-
The predicted values.
|
|
134
|
-
"""
|
|
135
86
|
if sklearn_check_version("1.0"):
|
|
136
87
|
self._check_feature_names(X, reset=False)
|
|
137
88
|
return dispatch(
|
|
@@ -164,3 +115,6 @@ class SVR(sklearn_SVR, BaseSVR):
|
|
|
164
115
|
|
|
165
116
|
def _onedal_predict(self, X, queue=None):
|
|
166
117
|
return self._onedal_estimator.predict(X, queue=queue)
|
|
118
|
+
|
|
119
|
+
fit.__doc__ = sklearn_SVR.fit.__doc__
|
|
120
|
+
predict.__doc__ = sklearn_SVR.predict.__doc__
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
from inspect import isclass
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
from sklearn.base import (
|
|
21
|
+
BaseEstimator,
|
|
22
|
+
ClassifierMixin,
|
|
23
|
+
ClusterMixin,
|
|
24
|
+
OutlierMixin,
|
|
25
|
+
RegressorMixin,
|
|
26
|
+
TransformerMixin,
|
|
27
|
+
)
|
|
28
|
+
from sklearn.datasets import load_diabetes, load_iris
|
|
29
|
+
from sklearn.neighbors._base import KNeighborsMixin
|
|
30
|
+
|
|
31
|
+
from onedal.tests.utils._dataframes_support import _convert_to_dataframe
|
|
32
|
+
from sklearnex import get_patch_map, patch_sklearn, sklearn_is_patched, unpatch_sklearn
|
|
33
|
+
from sklearnex.linear_model import LogisticRegression
|
|
34
|
+
from sklearnex.neighbors import (
|
|
35
|
+
KNeighborsClassifier,
|
|
36
|
+
KNeighborsRegressor,
|
|
37
|
+
LocalOutlierFactor,
|
|
38
|
+
NearestNeighbors,
|
|
39
|
+
)
|
|
40
|
+
from sklearnex.svm import SVC, NuSVC
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _load_all_models(with_sklearnex=True, estimator=True):
|
|
44
|
+
# insure that patch state is correct as dictated by patch_sklearn boolean
|
|
45
|
+
# and return it to the previous state no matter what occurs.
|
|
46
|
+
already_patched_map = sklearn_is_patched(return_map=True)
|
|
47
|
+
already_patched = any(already_patched_map.values())
|
|
48
|
+
try:
|
|
49
|
+
if with_sklearnex:
|
|
50
|
+
patch_sklearn()
|
|
51
|
+
elif already_patched:
|
|
52
|
+
unpatch_sklearn()
|
|
53
|
+
|
|
54
|
+
models = {}
|
|
55
|
+
for patch_infos in get_patch_map().values():
|
|
56
|
+
candidate = getattr(patch_infos[0][0][0], patch_infos[0][0][1], None)
|
|
57
|
+
if candidate is not None and isclass(candidate) == estimator:
|
|
58
|
+
if not estimator or issubclass(candidate, BaseEstimator):
|
|
59
|
+
models[patch_infos[0][0][1]] = candidate
|
|
60
|
+
finally:
|
|
61
|
+
if with_sklearnex:
|
|
62
|
+
unpatch_sklearn()
|
|
63
|
+
# both branches are now in an unpatched state, repatch as necessary
|
|
64
|
+
if already_patched:
|
|
65
|
+
patch_sklearn(name=[i for i in already_patched_map if already_patched_map[i]])
|
|
66
|
+
|
|
67
|
+
return models
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
PATCHED_MODELS = _load_all_models(with_sklearnex=True)
|
|
71
|
+
UNPATCHED_MODELS = _load_all_models(with_sklearnex=False)
|
|
72
|
+
|
|
73
|
+
PATCHED_FUNCTIONS = _load_all_models(with_sklearnex=True, estimator=False)
|
|
74
|
+
UNPATCHED_FUNCTIONS = _load_all_models(with_sklearnex=False, estimator=False)
|
|
75
|
+
|
|
76
|
+
mixin_map = [
|
|
77
|
+
[
|
|
78
|
+
ClassifierMixin,
|
|
79
|
+
["decision_function", "predict", "predict_proba", "predict_log_proba", "score"],
|
|
80
|
+
"classification",
|
|
81
|
+
],
|
|
82
|
+
[RegressorMixin, ["predict", "score"], "regression"],
|
|
83
|
+
[ClusterMixin, ["fit_predict"], "classification"],
|
|
84
|
+
[TransformerMixin, ["fit_transform", "transform", "score"], "classification"],
|
|
85
|
+
[OutlierMixin, ["fit_predict", "predict"], "classification"],
|
|
86
|
+
[KNeighborsMixin, ["kneighbors"], None],
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
SPECIAL_INSTANCES = {
|
|
91
|
+
str(i): i
|
|
92
|
+
for i in [
|
|
93
|
+
LocalOutlierFactor(novelty=True),
|
|
94
|
+
SVC(probability=True),
|
|
95
|
+
NuSVC(probability=True),
|
|
96
|
+
KNeighborsClassifier(algorithm="brute"),
|
|
97
|
+
KNeighborsRegressor(algorithm="brute"),
|
|
98
|
+
NearestNeighbors(algorithm="brute"),
|
|
99
|
+
LogisticRegression(solver="newton-cg"),
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def gen_models_info(algorithms):
|
|
105
|
+
output = []
|
|
106
|
+
for i in algorithms:
|
|
107
|
+
|
|
108
|
+
if i in PATCHED_MODELS:
|
|
109
|
+
est = PATCHED_MODELS[i]
|
|
110
|
+
elif i in SPECIAL_INSTANCES:
|
|
111
|
+
est = SPECIAL_INSTANCES[i].__class__
|
|
112
|
+
else:
|
|
113
|
+
raise KeyError(f"Unrecognized sklearnex estimator: {i}")
|
|
114
|
+
|
|
115
|
+
methods = set()
|
|
116
|
+
candidates = set(
|
|
117
|
+
[i for i in dir(est) if not i.startswith("_") and not i.endswith("_")]
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
for mixin, method, _ in mixin_map:
|
|
121
|
+
if issubclass(est, mixin):
|
|
122
|
+
methods |= candidates & set(method)
|
|
123
|
+
|
|
124
|
+
output += [[i, j] for j in methods] if methods else [[i, None]]
|
|
125
|
+
|
|
126
|
+
# In the case that no methods are available, set method to None.
|
|
127
|
+
# This will allow estimators without mixins to still test the fit
|
|
128
|
+
# method in various tests.
|
|
129
|
+
return output
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def gen_dataset(estimator, queue=None, target_df=None, dtype=np.float64):
|
|
133
|
+
dataset = None
|
|
134
|
+
name = estimator.__class__.__name__
|
|
135
|
+
est = PATCHED_MODELS[name]
|
|
136
|
+
for mixin, _, data in mixin_map:
|
|
137
|
+
if issubclass(est, mixin) and data is not None:
|
|
138
|
+
dataset = data
|
|
139
|
+
# load data
|
|
140
|
+
if dataset == "classification" or dataset is None:
|
|
141
|
+
X, y = load_iris(return_X_y=True)
|
|
142
|
+
elif dataset == "regression":
|
|
143
|
+
X, y = load_diabetes(return_X_y=True)
|
|
144
|
+
else:
|
|
145
|
+
raise ValueError("Unknown dataset type")
|
|
146
|
+
|
|
147
|
+
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=target_df, dtype=dtype)
|
|
148
|
+
y = _convert_to_dataframe(y, sycl_queue=queue, target_df=target_df, dtype=dtype)
|
|
149
|
+
return X, y
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
DTYPES = [
|
|
153
|
+
np.int8,
|
|
154
|
+
np.int16,
|
|
155
|
+
np.int32,
|
|
156
|
+
np.int64,
|
|
157
|
+
np.float16,
|
|
158
|
+
np.float32,
|
|
159
|
+
np.float64,
|
|
160
|
+
np.uint8,
|
|
161
|
+
np.uint16,
|
|
162
|
+
np.uint32,
|
|
163
|
+
np.uint64,
|
|
164
|
+
]
|