scikit-learn-intelex 2024.0.1__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.0.1.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 +11 -7
- sklearnex/__main__.py +0 -1
- sklearnex/_device_offload.py +31 -4
- sklearnex/_utils.py +15 -1
- sklearnex/basic_statistics/__init__.py +2 -2
- sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
- sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +386 -0
- sklearnex/cluster/__init__.py +0 -1
- sklearnex/cluster/dbscan.py +5 -2
- sklearnex/cluster/k_means.py +0 -1
- sklearnex/cluster/tests/test_dbscan.py +0 -1
- sklearnex/cluster/tests/test_kmeans.py +0 -1
- sklearnex/conftest.py +63 -0
- sklearnex/covariance/__init__.py +19 -0
- sklearnex/covariance/incremental_covariance.py +130 -0
- sklearnex/covariance/tests/test_incremental_covariance.py +143 -0
- sklearnex/decomposition/__init__.py +0 -1
- sklearnex/decomposition/pca.py +319 -2
- sklearnex/decomposition/tests/test_pca.py +34 -6
- sklearnex/dispatcher.py +93 -28
- sklearnex/ensemble/__init__.py +0 -1
- sklearnex/ensemble/_forest.py +93 -89
- sklearnex/ensemble/tests/test_forest.py +15 -20
- sklearnex/glob/__main__.py +0 -1
- sklearnex/glob/dispatcher.py +0 -1
- sklearnex/linear_model/__init__.py +1 -3
- sklearnex/linear_model/coordinate_descent.py +0 -1
- sklearnex/linear_model/linear.py +275 -332
- sklearnex/linear_model/logistic_path.py +0 -1
- sklearnex/linear_model/logistic_regression.py +385 -0
- sklearnex/linear_model/ridge.py +0 -1
- sklearnex/linear_model/tests/test_linear.py +47 -7
- sklearnex/linear_model/tests/test_logreg.py +70 -8
- sklearnex/manifold/__init__.py +0 -1
- sklearnex/manifold/t_sne.py +0 -1
- sklearnex/manifold/tests/test_tsne.py +0 -1
- sklearnex/metrics/__init__.py +0 -1
- sklearnex/metrics/pairwise.py +0 -1
- sklearnex/metrics/ranking.py +0 -1
- sklearnex/metrics/tests/test_metrics.py +0 -1
- sklearnex/model_selection/__init__.py +0 -1
- sklearnex/model_selection/split.py +0 -1
- sklearnex/model_selection/tests/test_model_selection.py +0 -1
- sklearnex/neighbors/__init__.py +1 -2
- sklearnex/neighbors/_lof.py +221 -0
- sklearnex/neighbors/common.py +5 -3
- sklearnex/neighbors/knn_classification.py +47 -133
- sklearnex/neighbors/knn_regression.py +20 -129
- sklearnex/neighbors/knn_unsupervised.py +15 -89
- sklearnex/neighbors/tests/test_neighbors.py +12 -17
- sklearnex/preview/__init__.py +1 -2
- sklearnex/preview/cluster/__init__.py +0 -1
- sklearnex/preview/cluster/k_means.py +7 -74
- sklearnex/preview/{decomposition → covariance}/__init__.py +19 -20
- sklearnex/preview/covariance/covariance.py +133 -0
- sklearnex/preview/covariance/tests/test_covariance.py +66 -0
- sklearnex/spmd/__init__.py +1 -0
- sklearnex/spmd/covariance/__init__.py +19 -0
- 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/__init__.py +0 -1
- sklearnex/svm/_common.py +4 -7
- sklearnex/svm/nusvc.py +73 -49
- sklearnex/svm/nusvr.py +8 -52
- sklearnex/svm/svc.py +74 -51
- sklearnex/svm/svr.py +5 -49
- sklearnex/svm/tests/test_svm.py +0 -1
- sklearnex/tests/_utils.py +164 -0
- sklearnex/tests/test_memory_usage.py +9 -7
- sklearnex/tests/test_monkeypatch.py +192 -134
- sklearnex/tests/test_n_jobs_support.py +99 -0
- 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
- sklearnex/utils/validation.py +0 -1
- scikit_learn_intelex-2024.0.1.dist-info/RECORD +0 -90
- sklearnex/neighbors/lof.py +0 -437
- sklearnex/preview/decomposition/pca.py +0 -376
- sklearnex/preview/decomposition/tests/test_preview_pca.py +0 -38
- sklearnex/tests/_models_info.py +0 -170
- sklearnex/tests/utils/_launch_algorithms.py +0 -118
- {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/WHEEL +0 -0
- {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/top_level.txt +0 -0
sklearnex/linear_model/linear.py
CHANGED
|
@@ -17,357 +17,300 @@
|
|
|
17
17
|
import logging
|
|
18
18
|
from abc import ABC
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if daal_check_version((2023, "P", 100)):
|
|
65
|
-
import numpy as np
|
|
66
|
-
from sklearn.linear_model import LinearRegression as sklearn_LinearRegression
|
|
67
|
-
|
|
68
|
-
from daal4py.sklearn._utils import get_dtype, make2d, sklearn_check_version
|
|
69
|
-
|
|
70
|
-
from .._device_offload import dispatch, wrap_output_data
|
|
71
|
-
from .._utils import PatchingConditionsChain, get_patch_message
|
|
72
|
-
from ..utils.validation import _assert_all_finite
|
|
20
|
+
import numpy as np
|
|
21
|
+
from sklearn.exceptions import NotFittedError
|
|
22
|
+
from sklearn.linear_model import LinearRegression as sklearn_LinearRegression
|
|
23
|
+
|
|
24
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
25
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
26
|
+
|
|
27
|
+
from .._device_offload import dispatch, wrap_output_data
|
|
28
|
+
from .._utils import PatchingConditionsChain, get_patch_message, register_hyperparameters
|
|
29
|
+
from ..utils.validation import _assert_all_finite
|
|
30
|
+
|
|
31
|
+
if sklearn_check_version("1.0") and not sklearn_check_version("1.2"):
|
|
32
|
+
from sklearn.linear_model._base import _deprecate_normalize
|
|
33
|
+
|
|
34
|
+
from scipy.sparse import issparse
|
|
35
|
+
from sklearn.utils.validation import check_X_y
|
|
36
|
+
|
|
37
|
+
from onedal.common.hyperparameters import get_hyperparameters
|
|
38
|
+
from onedal.linear_model import LinearRegression as onedal_LinearRegression
|
|
39
|
+
from onedal.utils import _num_features, _num_samples
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@register_hyperparameters({"fit": get_hyperparameters("linear_regression", "train")})
|
|
43
|
+
@control_n_jobs(decorated_methods=["fit", "predict"])
|
|
44
|
+
class LinearRegression(sklearn_LinearRegression):
|
|
45
|
+
__doc__ = sklearn_LinearRegression.__doc__
|
|
46
|
+
|
|
47
|
+
if sklearn_check_version("1.2"):
|
|
48
|
+
_parameter_constraints: dict = {**sklearn_LinearRegression._parameter_constraints}
|
|
49
|
+
|
|
50
|
+
def __init__(
|
|
51
|
+
self,
|
|
52
|
+
fit_intercept=True,
|
|
53
|
+
copy_X=True,
|
|
54
|
+
n_jobs=None,
|
|
55
|
+
positive=False,
|
|
56
|
+
):
|
|
57
|
+
super().__init__(
|
|
58
|
+
fit_intercept=fit_intercept,
|
|
59
|
+
copy_X=copy_X,
|
|
60
|
+
n_jobs=n_jobs,
|
|
61
|
+
positive=positive,
|
|
62
|
+
)
|
|
73
63
|
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
else:
|
|
65
|
+
|
|
66
|
+
def __init__(
|
|
67
|
+
self,
|
|
68
|
+
fit_intercept=True,
|
|
69
|
+
normalize="deprecated" if sklearn_check_version("1.0") else False,
|
|
70
|
+
copy_X=True,
|
|
71
|
+
n_jobs=None,
|
|
72
|
+
positive=False,
|
|
73
|
+
):
|
|
74
|
+
super().__init__(
|
|
75
|
+
fit_intercept=fit_intercept,
|
|
76
|
+
normalize=normalize,
|
|
77
|
+
copy_X=copy_X,
|
|
78
|
+
n_jobs=n_jobs,
|
|
79
|
+
positive=positive,
|
|
80
|
+
)
|
|
76
81
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
def fit(self, X, y, sample_weight=None):
|
|
83
|
+
if sklearn_check_version("1.0"):
|
|
84
|
+
self._check_feature_names(X, reset=True)
|
|
85
|
+
if sklearn_check_version("1.2"):
|
|
86
|
+
self._validate_params()
|
|
87
|
+
|
|
88
|
+
# It is necessary to properly update coefs for predict if we
|
|
89
|
+
# fallback to sklearn in dispatch
|
|
90
|
+
if hasattr(self, "_onedal_estimator"):
|
|
91
|
+
del self._onedal_estimator
|
|
92
|
+
|
|
93
|
+
dispatch(
|
|
94
|
+
self,
|
|
95
|
+
"fit",
|
|
96
|
+
{
|
|
97
|
+
"onedal": self.__class__._onedal_fit,
|
|
98
|
+
"sklearn": sklearn_LinearRegression.fit,
|
|
99
|
+
},
|
|
100
|
+
X,
|
|
101
|
+
y,
|
|
102
|
+
sample_weight,
|
|
103
|
+
)
|
|
104
|
+
return self
|
|
105
|
+
|
|
106
|
+
@wrap_output_data
|
|
107
|
+
def predict(self, X):
|
|
108
|
+
|
|
109
|
+
if not hasattr(self, "coef_"):
|
|
110
|
+
msg = (
|
|
111
|
+
"This %(name)s instance is not fitted yet. Call 'fit' with "
|
|
112
|
+
"appropriate arguments before using this estimator."
|
|
113
|
+
)
|
|
114
|
+
raise NotFittedError(msg % {"name": self.__class__.__name__})
|
|
115
|
+
|
|
116
|
+
return dispatch(
|
|
117
|
+
self,
|
|
118
|
+
"predict",
|
|
119
|
+
{
|
|
120
|
+
"onedal": self.__class__._onedal_predict,
|
|
121
|
+
"sklearn": sklearn_LinearRegression.predict,
|
|
122
|
+
},
|
|
123
|
+
X,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
def _test_type_and_finiteness(self, X_in):
|
|
127
|
+
X = X_in if isinstance(X_in, np.ndarray) else np.asarray(X_in)
|
|
128
|
+
|
|
129
|
+
dtype = X.dtype
|
|
130
|
+
if "complex" in str(type(dtype)):
|
|
131
|
+
return False
|
|
132
|
+
|
|
133
|
+
try:
|
|
134
|
+
_assert_all_finite(X)
|
|
135
|
+
except BaseException:
|
|
136
|
+
return False
|
|
137
|
+
return True
|
|
138
|
+
|
|
139
|
+
def _onedal_fit_supported(self, method_name, *data):
|
|
140
|
+
assert method_name == "fit"
|
|
141
|
+
assert len(data) == 3
|
|
142
|
+
X, y, sample_weight = data
|
|
143
|
+
|
|
144
|
+
class_name = self.__class__.__name__
|
|
145
|
+
patching_status = PatchingConditionsChain(
|
|
146
|
+
f"sklearn.linear_model.{class_name}.fit"
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
normalize_is_set = (
|
|
150
|
+
hasattr(self, "normalize")
|
|
151
|
+
and self.normalize
|
|
152
|
+
and self.normalize != "deprecated"
|
|
153
|
+
)
|
|
154
|
+
positive_is_set = hasattr(self, "positive") and self.positive
|
|
155
|
+
|
|
156
|
+
n_samples = _num_samples(X)
|
|
157
|
+
n_features = _num_features(X, fallback_1d=True)
|
|
158
|
+
|
|
159
|
+
# Check if equations are well defined
|
|
160
|
+
is_good_for_onedal = n_samples >= (n_features + int(self.fit_intercept))
|
|
161
|
+
|
|
162
|
+
dal_ready = patching_status.and_conditions(
|
|
163
|
+
[
|
|
164
|
+
(sample_weight is None, "Sample weight is not supported."),
|
|
165
|
+
(
|
|
166
|
+
not issparse(X) and not issparse(y),
|
|
167
|
+
"Sparse input is not supported.",
|
|
168
|
+
),
|
|
169
|
+
(not normalize_is_set, "Normalization is not supported."),
|
|
170
|
+
(
|
|
171
|
+
not positive_is_set,
|
|
172
|
+
"Forced positive coefficients are not supported.",
|
|
173
|
+
),
|
|
174
|
+
(
|
|
175
|
+
is_good_for_onedal,
|
|
176
|
+
"The shape of X (fitting) does not satisfy oneDAL requirements:"
|
|
177
|
+
"Number of features + 1 >= number of samples.",
|
|
178
|
+
),
|
|
179
|
+
]
|
|
180
|
+
)
|
|
181
|
+
if not dal_ready:
|
|
182
|
+
return patching_status
|
|
80
183
|
|
|
81
|
-
|
|
82
|
-
|
|
184
|
+
if not patching_status.and_condition(
|
|
185
|
+
self._test_type_and_finiteness(X), "Input X is not supported."
|
|
186
|
+
):
|
|
187
|
+
return patching_status
|
|
83
188
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
189
|
+
patching_status.and_condition(
|
|
190
|
+
self._test_type_and_finiteness(y), "Input y is not supported."
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
return patching_status
|
|
194
|
+
|
|
195
|
+
def _onedal_predict_supported(self, method_name, *data):
|
|
196
|
+
assert method_name == "predict"
|
|
197
|
+
assert len(data) == 1
|
|
198
|
+
|
|
199
|
+
class_name = self.__class__.__name__
|
|
200
|
+
patching_status = PatchingConditionsChain(
|
|
201
|
+
f"sklearn.linear_model.{class_name}.predict"
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
n_samples = _num_samples(*data)
|
|
205
|
+
model_is_sparse = issparse(self.coef_) or (
|
|
206
|
+
self.fit_intercept and issparse(self.intercept_)
|
|
207
|
+
)
|
|
208
|
+
dal_ready = patching_status.and_conditions(
|
|
209
|
+
[
|
|
210
|
+
(n_samples > 0, "Number of samples is less than 1."),
|
|
211
|
+
(not issparse(*data), "Sparse input is not supported."),
|
|
212
|
+
(not model_is_sparse, "Sparse coefficients are not supported."),
|
|
213
|
+
]
|
|
214
|
+
)
|
|
215
|
+
if not dal_ready:
|
|
216
|
+
return patching_status
|
|
87
217
|
|
|
218
|
+
patching_status.and_condition(
|
|
219
|
+
self._test_type_and_finiteness(*data), "Input X is not supported."
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
return patching_status
|
|
223
|
+
|
|
224
|
+
def _onedal_supported(self, method_name, *data):
|
|
225
|
+
if method_name == "fit":
|
|
226
|
+
return self._onedal_fit_supported(method_name, *data)
|
|
227
|
+
if method_name == "predict":
|
|
228
|
+
return self._onedal_predict_supported(method_name, *data)
|
|
229
|
+
raise RuntimeError(f"Unknown method {method_name} in {self.__class__.__name__}")
|
|
230
|
+
|
|
231
|
+
_onedal_gpu_supported = _onedal_supported
|
|
232
|
+
_onedal_cpu_supported = _onedal_supported
|
|
233
|
+
|
|
234
|
+
def _initialize_onedal_estimator(self):
|
|
235
|
+
onedal_params = {"fit_intercept": self.fit_intercept, "copy_X": self.copy_X}
|
|
236
|
+
self._onedal_estimator = onedal_LinearRegression(**onedal_params)
|
|
237
|
+
|
|
238
|
+
def _onedal_fit(self, X, y, sample_weight, queue=None):
|
|
239
|
+
assert sample_weight is None
|
|
240
|
+
|
|
241
|
+
check_params = {
|
|
242
|
+
"X": X,
|
|
243
|
+
"y": y,
|
|
244
|
+
"dtype": [np.float64, np.float32],
|
|
245
|
+
"accept_sparse": ["csr", "csc", "coo"],
|
|
246
|
+
"y_numeric": True,
|
|
247
|
+
"multi_output": True,
|
|
248
|
+
"force_all_finite": False,
|
|
249
|
+
}
|
|
88
250
|
if sklearn_check_version("1.2"):
|
|
89
|
-
|
|
90
|
-
**sklearn_LinearRegression._parameter_constraints
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
def __init__(
|
|
94
|
-
self,
|
|
95
|
-
fit_intercept=True,
|
|
96
|
-
copy_X=True,
|
|
97
|
-
n_jobs=None,
|
|
98
|
-
positive=False,
|
|
99
|
-
):
|
|
100
|
-
super().__init__(
|
|
101
|
-
fit_intercept=fit_intercept,
|
|
102
|
-
copy_X=copy_X,
|
|
103
|
-
n_jobs=n_jobs,
|
|
104
|
-
positive=positive,
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
elif sklearn_check_version("0.24"):
|
|
108
|
-
|
|
109
|
-
def __init__(
|
|
110
|
-
self,
|
|
111
|
-
fit_intercept=True,
|
|
112
|
-
normalize="deprecated" if sklearn_check_version("1.0") else False,
|
|
113
|
-
copy_X=True,
|
|
114
|
-
n_jobs=None,
|
|
115
|
-
positive=False,
|
|
116
|
-
):
|
|
117
|
-
super().__init__(
|
|
118
|
-
fit_intercept=fit_intercept,
|
|
119
|
-
normalize=normalize,
|
|
120
|
-
copy_X=copy_X,
|
|
121
|
-
n_jobs=n_jobs,
|
|
122
|
-
positive=positive,
|
|
123
|
-
)
|
|
124
|
-
|
|
251
|
+
X, y = self._validate_data(**check_params)
|
|
125
252
|
else:
|
|
253
|
+
X, y = check_X_y(**check_params)
|
|
126
254
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
n_jobs=None,
|
|
133
|
-
):
|
|
134
|
-
super().__init__(
|
|
135
|
-
fit_intercept=fit_intercept,
|
|
136
|
-
normalize=normalize,
|
|
137
|
-
copy_X=copy_X,
|
|
138
|
-
n_jobs=n_jobs,
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
def fit(self, X, y, sample_weight=None):
|
|
142
|
-
"""
|
|
143
|
-
Fit linear model.
|
|
144
|
-
Parameters
|
|
145
|
-
----------
|
|
146
|
-
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
147
|
-
Training data.
|
|
148
|
-
y : array-like of shape (n_samples,) or (n_samples, n_targets)
|
|
149
|
-
Target values. Will be cast to X's dtype if necessary.
|
|
150
|
-
sample_weight : array-like of shape (n_samples,), default=None
|
|
151
|
-
Individual weights for each sample.
|
|
152
|
-
.. versionadded:: 0.17
|
|
153
|
-
parameter *sample_weight* support to LinearRegression.
|
|
154
|
-
Returns
|
|
155
|
-
-------
|
|
156
|
-
self : object
|
|
157
|
-
Fitted Estimator.
|
|
158
|
-
"""
|
|
159
|
-
if sklearn_check_version("1.0"):
|
|
160
|
-
self._check_feature_names(X, reset=True)
|
|
161
|
-
if sklearn_check_version("1.2"):
|
|
162
|
-
self._validate_params()
|
|
163
|
-
|
|
164
|
-
dispatch(
|
|
165
|
-
self,
|
|
166
|
-
"fit",
|
|
167
|
-
{
|
|
168
|
-
"onedal": self.__class__._onedal_fit,
|
|
169
|
-
"sklearn": sklearn_LinearRegression.fit,
|
|
170
|
-
},
|
|
171
|
-
X,
|
|
172
|
-
y,
|
|
173
|
-
sample_weight,
|
|
174
|
-
)
|
|
175
|
-
return self
|
|
176
|
-
|
|
177
|
-
@wrap_output_data
|
|
178
|
-
def predict(self, X):
|
|
179
|
-
"""
|
|
180
|
-
Predict using the linear model.
|
|
181
|
-
Parameters
|
|
182
|
-
----------
|
|
183
|
-
X : array-like or sparse matrix, shape (n_samples, n_features)
|
|
184
|
-
Samples.
|
|
185
|
-
Returns
|
|
186
|
-
-------
|
|
187
|
-
C : array, shape (n_samples, n_targets)
|
|
188
|
-
Returns predicted values.
|
|
189
|
-
"""
|
|
190
|
-
if sklearn_check_version("1.0"):
|
|
191
|
-
self._check_feature_names(X, reset=False)
|
|
192
|
-
return dispatch(
|
|
193
|
-
self,
|
|
194
|
-
"predict",
|
|
195
|
-
{
|
|
196
|
-
"onedal": self.__class__._onedal_predict,
|
|
197
|
-
"sklearn": sklearn_LinearRegression.predict,
|
|
198
|
-
},
|
|
199
|
-
X,
|
|
255
|
+
if sklearn_check_version("1.0") and not sklearn_check_version("1.2"):
|
|
256
|
+
self._normalize = _deprecate_normalize(
|
|
257
|
+
self.normalize,
|
|
258
|
+
default=False,
|
|
259
|
+
estimator_name=self.__class__.__name__,
|
|
200
260
|
)
|
|
201
261
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if "complex" in str(type(dtype)):
|
|
207
|
-
return False
|
|
208
|
-
|
|
209
|
-
try:
|
|
210
|
-
_assert_all_finite(X)
|
|
211
|
-
except BaseException:
|
|
212
|
-
return False
|
|
213
|
-
return True
|
|
214
|
-
|
|
215
|
-
def _onedal_fit_supported(self, method_name, *data):
|
|
216
|
-
assert method_name == "fit"
|
|
217
|
-
assert len(data) == 3
|
|
218
|
-
X, y, sample_weight = data
|
|
262
|
+
self._initialize_onedal_estimator()
|
|
263
|
+
try:
|
|
264
|
+
self._onedal_estimator.fit(X, y, queue=queue)
|
|
265
|
+
self._save_attributes()
|
|
219
266
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
f"
|
|
267
|
+
except RuntimeError:
|
|
268
|
+
logging.getLogger("sklearnex").info(
|
|
269
|
+
f"{self.__class__.__name__}.fit "
|
|
270
|
+
+ get_patch_message("sklearn_after_onedal")
|
|
223
271
|
)
|
|
224
272
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
and self.normalize
|
|
228
|
-
and self.normalize != "deprecated"
|
|
229
|
-
)
|
|
230
|
-
positive_is_set = hasattr(self, "positive") and self.positive
|
|
231
|
-
|
|
232
|
-
n_samples = _num_samples(X)
|
|
233
|
-
n_features = _num_features(X, fallback_1d=True)
|
|
234
|
-
|
|
235
|
-
# Check if equations are well defined
|
|
236
|
-
is_good_for_onedal = n_samples > (n_features + int(self.fit_intercept))
|
|
237
|
-
|
|
238
|
-
dal_ready = patching_status.and_conditions(
|
|
239
|
-
[
|
|
240
|
-
(sample_weight is None, "Sample weight is not supported."),
|
|
241
|
-
(
|
|
242
|
-
not issparse(X) and not issparse(y),
|
|
243
|
-
"Sparse input is not supported.",
|
|
244
|
-
),
|
|
245
|
-
(not normalize_is_set, "Normalization is not supported."),
|
|
246
|
-
(
|
|
247
|
-
not positive_is_set,
|
|
248
|
-
"Forced positive coefficients are not supported.",
|
|
249
|
-
),
|
|
250
|
-
(
|
|
251
|
-
is_good_for_onedal,
|
|
252
|
-
"The shape of X (fitting) does not satisfy oneDAL requirements:."
|
|
253
|
-
"Number of features + 1 >= number of samples.",
|
|
254
|
-
),
|
|
255
|
-
]
|
|
256
|
-
)
|
|
257
|
-
if not dal_ready:
|
|
258
|
-
return patching_status
|
|
259
|
-
|
|
260
|
-
if not patching_status.and_condition(
|
|
261
|
-
self._test_type_and_finiteness(X), "Input X is not supported."
|
|
262
|
-
):
|
|
263
|
-
return patching_status
|
|
273
|
+
del self._onedal_estimator
|
|
274
|
+
super().fit(X, y)
|
|
264
275
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
return patching_status
|
|
276
|
+
def _onedal_predict(self, X, queue=None):
|
|
277
|
+
if sklearn_check_version("1.0"):
|
|
278
|
+
self._check_feature_names(X, reset=False)
|
|
270
279
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
280
|
+
X = self._validate_data(X, accept_sparse=False, reset=False)
|
|
281
|
+
if not hasattr(self, "_onedal_estimator"):
|
|
282
|
+
self._initialize_onedal_estimator()
|
|
283
|
+
self._onedal_estimator.coef_ = self.coef_
|
|
284
|
+
self._onedal_estimator.intercept_ = self.intercept_
|
|
274
285
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
f"sklearn.linear_model.{class_name}.predict"
|
|
278
|
-
)
|
|
286
|
+
res = self._onedal_estimator.predict(X, queue=queue)
|
|
287
|
+
return res
|
|
279
288
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
self.fit_intercept and issparse(self.intercept_)
|
|
283
|
-
)
|
|
284
|
-
dal_ready = patching_status.and_conditions(
|
|
285
|
-
[
|
|
286
|
-
(n_samples > 0, "Number of samples is less than 1."),
|
|
287
|
-
(not issparse(*data), "Sparse input is not supported."),
|
|
288
|
-
(not model_is_sparse, "Sparse coefficients are not supported."),
|
|
289
|
-
(hasattr(self, "_onedal_estimator"), "oneDAL model was not trained."),
|
|
290
|
-
]
|
|
291
|
-
)
|
|
292
|
-
if not dal_ready:
|
|
293
|
-
return patching_status
|
|
289
|
+
def get_coef_(self):
|
|
290
|
+
return self.coef_
|
|
294
291
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
292
|
+
def set_coef_(self, value):
|
|
293
|
+
self.__dict__["coef_"] = value
|
|
294
|
+
if hasattr(self, "_onedal_estimator"):
|
|
295
|
+
self._onedal_estimator.coef_ = value
|
|
296
|
+
del self._onedal_estimator._onedal_model
|
|
298
297
|
|
|
299
|
-
|
|
298
|
+
def get_intercept_(self):
|
|
299
|
+
return self.intercept_
|
|
300
300
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
raise RuntimeError(
|
|
307
|
-
f"Unknown method {method_name} in {self.__class__.__name__}"
|
|
308
|
-
)
|
|
301
|
+
def set_intercept_(self, value):
|
|
302
|
+
self.__dict__["intercept_"] = value
|
|
303
|
+
if hasattr(self, "_onedal_estimator"):
|
|
304
|
+
self._onedal_estimator.intercept_ = value
|
|
305
|
+
del self._onedal_estimator._onedal_model
|
|
309
306
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
onedal_params = {"fit_intercept": self.fit_intercept, "copy_X": self.copy_X}
|
|
318
|
-
self._onedal_estimator = onedal_LinearRegression(**onedal_params)
|
|
319
|
-
|
|
320
|
-
def _onedal_fit(self, X, y, sample_weight, queue=None):
|
|
321
|
-
assert sample_weight is None
|
|
322
|
-
|
|
323
|
-
check_params = {
|
|
324
|
-
"X": X,
|
|
325
|
-
"y": y,
|
|
326
|
-
"dtype": [np.float64, np.float32],
|
|
327
|
-
"accept_sparse": ["csr", "csc", "coo"],
|
|
328
|
-
"y_numeric": True,
|
|
329
|
-
"multi_output": True,
|
|
330
|
-
"force_all_finite": False,
|
|
331
|
-
}
|
|
332
|
-
if sklearn_check_version("1.2"):
|
|
333
|
-
X, y = self._validate_data(**check_params)
|
|
334
|
-
else:
|
|
335
|
-
X, y = check_X_y(**check_params)
|
|
336
|
-
|
|
337
|
-
if sklearn_check_version("1.0") and not sklearn_check_version("1.2"):
|
|
338
|
-
self._normalize = _deprecate_normalize(
|
|
339
|
-
self.normalize,
|
|
340
|
-
default=False,
|
|
341
|
-
estimator_name=self.__class__.__name__,
|
|
342
|
-
)
|
|
307
|
+
def _save_attributes(self):
|
|
308
|
+
self.coef_ = property(self.get_coef_, self.set_coef_)
|
|
309
|
+
self.intercept_ = property(self.get_intercept_, self.set_intercept_)
|
|
310
|
+
self.n_features_in_ = self._onedal_estimator.n_features_in_
|
|
311
|
+
self._sparse = False
|
|
312
|
+
self.__dict__["coef_"] = self._onedal_estimator.coef_
|
|
313
|
+
self.__dict__["intercept_"] = self._onedal_estimator.intercept_
|
|
343
314
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
self._onedal_estimator.fit(X, y, queue=queue)
|
|
347
|
-
self._save_attributes()
|
|
348
|
-
|
|
349
|
-
except RuntimeError:
|
|
350
|
-
logging.getLogger("sklearnex").info(
|
|
351
|
-
f"{self.__class__.__name__}.fit "
|
|
352
|
-
+ get_patch_message("sklearn_after_onedal")
|
|
353
|
-
)
|
|
354
|
-
|
|
355
|
-
del self._onedal_estimator
|
|
356
|
-
super().fit(X, y)
|
|
357
|
-
|
|
358
|
-
def _onedal_predict(self, X, queue=None):
|
|
359
|
-
X = self._validate_data(X, accept_sparse=False, reset=False)
|
|
360
|
-
if not hasattr(self, "_onedal_estimator"):
|
|
361
|
-
self._initialize_onedal_estimator()
|
|
362
|
-
self._onedal_estimator.coef_ = self.coef_
|
|
363
|
-
self._onedal_estimator.intercept_ = self.intercept_
|
|
364
|
-
|
|
365
|
-
return self._onedal_estimator.predict(X, queue=queue)
|
|
366
|
-
|
|
367
|
-
else:
|
|
368
|
-
from daal4py.sklearn.linear_model import LinearRegression
|
|
369
|
-
|
|
370
|
-
logging.warning(
|
|
371
|
-
"Sklearnex LinearRegression requires oneDAL version >= 2023.1 "
|
|
372
|
-
"but it was not found"
|
|
373
|
-
)
|
|
315
|
+
fit.__doc__ = sklearn_LinearRegression.fit.__doc__
|
|
316
|
+
predict.__doc__ = sklearn_LinearRegression.predict.__doc__
|