scikit-learn-intelex 2024.5.0__py310-none-manylinux1_x86_64.whl → 2024.7.0__py310-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.

Files changed (73) hide show
  1. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/METADATA +2 -2
  2. scikit_learn_intelex-2024.7.0.dist-info/RECORD +122 -0
  3. sklearnex/_config.py +3 -15
  4. sklearnex/_device_offload.py +9 -168
  5. sklearnex/basic_statistics/basic_statistics.py +127 -1
  6. sklearnex/basic_statistics/tests/test_basic_statistics.py +251 -0
  7. sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +1 -1
  8. sklearnex/cluster/dbscan.py +3 -1
  9. sklearnex/cluster/k_means.py +8 -0
  10. sklearnex/cluster/tests/test_dbscan.py +8 -6
  11. sklearnex/cluster/tests/test_kmeans.py +15 -3
  12. sklearnex/conftest.py +11 -1
  13. sklearnex/covariance/incremental_covariance.py +64 -13
  14. sklearnex/covariance/tests/test_incremental_covariance.py +35 -0
  15. sklearnex/decomposition/pca.py +25 -1
  16. sklearnex/decomposition/tests/test_pca.py +4 -2
  17. sklearnex/dispatcher.py +109 -1
  18. sklearnex/ensemble/_forest.py +121 -57
  19. sklearnex/ensemble/tests/test_forest.py +7 -0
  20. sklearnex/glob/dispatcher.py +16 -2
  21. sklearnex/linear_model/coordinate_descent.py +13 -0
  22. sklearnex/linear_model/incremental_linear.py +102 -25
  23. sklearnex/linear_model/linear.py +25 -39
  24. sklearnex/linear_model/logistic_regression.py +92 -74
  25. sklearnex/linear_model/ridge.py +7 -0
  26. sklearnex/linear_model/tests/test_incremental_linear.py +10 -10
  27. sklearnex/linear_model/tests/test_linear.py +30 -5
  28. sklearnex/linear_model/tests/test_logreg.py +45 -3
  29. sklearnex/manifold/t_sne.py +4 -0
  30. sklearnex/metrics/pairwise.py +5 -0
  31. sklearnex/metrics/ranking.py +3 -0
  32. sklearnex/model_selection/split.py +3 -0
  33. sklearnex/neighbors/_lof.py +9 -0
  34. sklearnex/neighbors/common.py +45 -1
  35. sklearnex/neighbors/knn_classification.py +1 -20
  36. sklearnex/neighbors/knn_regression.py +25 -20
  37. sklearnex/neighbors/knn_unsupervised.py +31 -7
  38. sklearnex/preview/__init__.py +1 -1
  39. sklearnex/preview/decomposition/__init__.py +19 -0
  40. sklearnex/preview/decomposition/incremental_pca.py +228 -0
  41. sklearnex/preview/decomposition/tests/test_incremental_pca.py +266 -0
  42. sklearnex/preview/linear_model/__init__.py +19 -0
  43. sklearnex/preview/linear_model/ridge.py +419 -0
  44. sklearnex/preview/linear_model/tests/test_ridge.py +102 -0
  45. sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py +107 -0
  46. sklearnex/spmd/cluster/tests/test_dbscan_spmd.py +97 -0
  47. sklearnex/spmd/cluster/tests/test_kmeans_spmd.py +172 -0
  48. sklearnex/spmd/covariance/tests/test_covariance_spmd.py +107 -0
  49. sklearnex/spmd/decomposition/tests/test_pca_spmd.py +128 -0
  50. sklearnex/spmd/ensemble/tests/test_forest_spmd.py +265 -0
  51. sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py +145 -0
  52. sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py +163 -0
  53. sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py +288 -0
  54. sklearnex/svm/_common.py +163 -20
  55. sklearnex/svm/nusvc.py +40 -4
  56. sklearnex/svm/nusvr.py +31 -2
  57. sklearnex/svm/svc.py +40 -4
  58. sklearnex/svm/svr.py +31 -2
  59. sklearnex/svm/tests/test_svm.py +12 -20
  60. sklearnex/tests/_utils.py +185 -30
  61. sklearnex/tests/_utils_spmd.py +185 -0
  62. sklearnex/tests/test_common.py +54 -0
  63. sklearnex/tests/test_config.py +4 -0
  64. sklearnex/tests/test_memory_usage.py +185 -126
  65. sklearnex/tests/test_monkeypatch.py +12 -4
  66. sklearnex/tests/test_patching.py +21 -25
  67. sklearnex/tests/test_run_to_run_stability.py +295 -0
  68. sklearnex/utils/_namespace.py +1 -1
  69. scikit_learn_intelex-2024.5.0.dist-info/RECORD +0 -104
  70. sklearnex/tests/test_run_to_run_stability_tests.py +0 -428
  71. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/LICENSE.txt +0 -0
  72. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/WHEEL +0 -0
  73. {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/top_level.txt +0 -0
@@ -20,6 +20,7 @@ import warnings
20
20
  import numpy as np
21
21
  from sklearn.base import BaseEstimator, MultiOutputMixin, RegressorMixin
22
22
  from sklearn.exceptions import NotFittedError
23
+ from sklearn.metrics import r2_score
23
24
  from sklearn.utils import check_array, gen_batches
24
25
 
25
26
  from daal4py.sklearn._n_jobs_support import control_n_jobs
@@ -134,6 +135,7 @@ class IncrementalLinearRegression(MultiOutputMixin, RegressorMixin, BaseEstimato
134
135
  X,
135
136
  dtype=[np.float64, np.float32],
136
137
  copy=self.copy_X,
138
+ reset=False,
137
139
  )
138
140
  else:
139
141
  X = check_array(
@@ -147,33 +149,42 @@ class IncrementalLinearRegression(MultiOutputMixin, RegressorMixin, BaseEstimato
147
149
  self._onedal_finalize_fit()
148
150
  return self._onedal_estimator.predict(X, queue)
149
151
 
150
- def _onedal_partial_fit(self, X, y, queue=None):
152
+ def _onedal_score(self, X, y, sample_weight=None, queue=None):
153
+ return r2_score(
154
+ y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
155
+ )
156
+
157
+ def _onedal_partial_fit(self, X, y, check_input=True, queue=None):
151
158
  first_pass = not hasattr(self, "n_samples_seen_") or self.n_samples_seen_ == 0
152
159
 
153
160
  if sklearn_check_version("1.2"):
154
161
  self._validate_params()
155
162
 
156
- if sklearn_check_version("1.0"):
157
- X, y = self._validate_data(
158
- X,
159
- y,
160
- dtype=[np.float64, np.float32],
161
- reset=first_pass,
162
- copy=self.copy_X,
163
- multi_output=True,
164
- )
165
- else:
166
- X = check_array(
167
- X,
168
- dtype=[np.float64, np.float32],
169
- copy=self.copy_X,
170
- )
171
- y = check_array(
172
- y,
173
- dtype=[np.float64, np.float32],
174
- copy=False,
175
- ensure_2d=False,
176
- )
163
+ if check_input:
164
+ if sklearn_check_version("1.0"):
165
+ X, y = self._validate_data(
166
+ X,
167
+ y,
168
+ dtype=[np.float64, np.float32],
169
+ reset=first_pass,
170
+ copy=self.copy_X,
171
+ multi_output=True,
172
+ force_all_finite=False,
173
+ )
174
+ else:
175
+ X = check_array(
176
+ X,
177
+ dtype=[np.float64, np.float32],
178
+ copy=self.copy_X,
179
+ force_all_finite=False,
180
+ )
181
+ y = check_array(
182
+ y,
183
+ dtype=[np.float64, np.float32],
184
+ copy=False,
185
+ ensure_2d=False,
186
+ force_all_finite=False,
187
+ )
177
188
 
178
189
  if first_pass:
179
190
  self.n_samples_seen_ = X.shape[0]
@@ -202,7 +213,12 @@ class IncrementalLinearRegression(MultiOutputMixin, RegressorMixin, BaseEstimato
202
213
 
203
214
  if sklearn_check_version("1.0"):
204
215
  X, y = self._validate_data(
205
- X, y, dtype=[np.float64, np.float32], copy=self.copy_X, multi_output=True
216
+ X,
217
+ y,
218
+ dtype=[np.float64, np.float32],
219
+ copy=self.copy_X,
220
+ multi_output=True,
221
+ ensure_2d=True,
206
222
  )
207
223
  else:
208
224
  X = check_array(
@@ -234,7 +250,7 @@ class IncrementalLinearRegression(MultiOutputMixin, RegressorMixin, BaseEstimato
234
250
 
235
251
  for batch in gen_batches(n_samples, self.batch_size_):
236
252
  X_batch, y_batch = X[batch], y[batch]
237
- self._onedal_partial_fit(X_batch, y_batch, queue=queue)
253
+ self._onedal_partial_fit(X_batch, y_batch, check_input=False, queue=queue)
238
254
 
239
255
  if sklearn_check_version("1.2"):
240
256
  self._validate_params()
@@ -288,7 +304,7 @@ class IncrementalLinearRegression(MultiOutputMixin, RegressorMixin, BaseEstimato
288
304
  coef_ = property(get_coef_, set_coef_)
289
305
  intercept_ = property(get_intercept_, set_intercept_)
290
306
 
291
- def partial_fit(self, X, y):
307
+ def partial_fit(self, X, y, check_input=True):
292
308
  """
293
309
  Incremental fit linear model with X and y. All of X and y is
294
310
  processed as a single batch.
@@ -318,6 +334,7 @@ class IncrementalLinearRegression(MultiOutputMixin, RegressorMixin, BaseEstimato
318
334
  },
319
335
  X,
320
336
  y,
337
+ check_input=check_input,
321
338
  )
322
339
  return self
323
340
 
@@ -385,3 +402,63 @@ class IncrementalLinearRegression(MultiOutputMixin, RegressorMixin, BaseEstimato
385
402
  },
386
403
  X,
387
404
  )
405
+
406
+ @wrap_output_data
407
+ def score(self, X, y, sample_weight=None):
408
+ """Return the coefficient of determination of the prediction.
409
+
410
+ The coefficient of determination :math:`R^2` is defined as
411
+ :math:`(1 - \\frac{u}{v})`, where :math:`u` is the residual
412
+ sum of squares ``((y_true - y_pred)** 2).sum()`` and :math:`v`
413
+ is the total sum of squares ``((y_true - y_true.mean()) ** 2).sum()``.
414
+ The best possible score is 1.0 and it can be negative (because the
415
+ model can be arbitrarily worse). A constant model that always predicts
416
+ the expected value of `y`, disregarding the input features, would get
417
+ a :math:`R^2` score of 0.0.
418
+
419
+ Parameters
420
+ ----------
421
+ X : array-like of shape (n_samples, n_features)
422
+ Test samples. For some estimators this may be a precomputed
423
+ kernel matrix or a list of generic objects instead with shape
424
+ ``(n_samples, n_samples_fitted)``, where ``n_samples_fitted``
425
+ is the number of samples used in the fitting for the estimator.
426
+
427
+ y : array-like of shape (n_samples,) or (n_samples, n_outputs)
428
+ True values for `X`.
429
+
430
+ sample_weight : array-like of shape (n_samples,), default=None
431
+ Sample weights.
432
+
433
+ Returns
434
+ -------
435
+ score : float
436
+ :math:`R^2` of ``self.predict(X)`` w.r.t. `y`.
437
+
438
+ Notes
439
+ -----
440
+ The :math:`R^2` score used when calling ``score`` on a regressor uses
441
+ ``multioutput='uniform_average'`` from version 0.23 to keep consistent
442
+ with default value of :func:`~sklearn.metrics.r2_score`.
443
+ This influences the ``score`` method of all the multioutput
444
+ regressors (except for
445
+ :class:`~sklearn.multioutput.MultiOutputRegressor`).
446
+ """
447
+ if not hasattr(self, "coef_"):
448
+ msg = (
449
+ "This %(name)s instance is not fitted yet. Call 'fit' or 'partial_fit' "
450
+ "with appropriate arguments before using this estimator."
451
+ )
452
+ raise NotFittedError(msg % {"name": self.__class__.__name__})
453
+
454
+ return dispatch(
455
+ self,
456
+ "score",
457
+ {
458
+ "onedal": self.__class__._onedal_score,
459
+ "sklearn": None,
460
+ },
461
+ X,
462
+ y,
463
+ sample_weight=sample_weight,
464
+ )
@@ -20,13 +20,13 @@ from abc import ABC
20
20
  import numpy as np
21
21
  from sklearn.exceptions import NotFittedError
22
22
  from sklearn.linear_model import LinearRegression as sklearn_LinearRegression
23
+ from sklearn.metrics import r2_score
23
24
 
24
25
  from daal4py.sklearn._n_jobs_support import control_n_jobs
25
26
  from daal4py.sklearn._utils import sklearn_check_version
26
27
 
27
28
  from .._device_offload import dispatch, wrap_output_data
28
29
  from .._utils import PatchingConditionsChain, get_patch_message, register_hyperparameters
29
- from ..utils.validation import _assert_all_finite
30
30
 
31
31
  if sklearn_check_version("1.0") and not sklearn_check_version("1.2"):
32
32
  from sklearn.linear_model._base import _deprecate_normalize
@@ -123,18 +123,19 @@ class LinearRegression(sklearn_LinearRegression):
123
123
  X,
124
124
  )
125
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
126
+ @wrap_output_data
127
+ def score(self, X, y, sample_weight=None):
128
+ return dispatch(
129
+ self,
130
+ "score",
131
+ {
132
+ "onedal": self.__class__._onedal_score,
133
+ "sklearn": sklearn_LinearRegression.score,
134
+ },
135
+ X,
136
+ y,
137
+ sample_weight=sample_weight,
138
+ )
138
139
 
139
140
  def _onedal_fit_supported(self, method_name, *data):
140
141
  assert method_name == "fit"
@@ -159,7 +160,7 @@ class LinearRegression(sklearn_LinearRegression):
159
160
  # Check if equations are well defined
160
161
  is_underdetermined = n_samples < (n_features + int(self.fit_intercept))
161
162
 
162
- dal_ready = patching_status.and_conditions(
163
+ patching_status.and_conditions(
163
164
  [
164
165
  (sample_weight is None, "Sample weight is not supported."),
165
166
  (
@@ -178,53 +179,33 @@ class LinearRegression(sklearn_LinearRegression):
178
179
  ),
179
180
  ]
180
181
  )
181
- if not dal_ready:
182
- return patching_status
183
-
184
- if not patching_status.and_condition(
185
- self._test_type_and_finiteness(X), "Input X is not supported."
186
- ):
187
- return patching_status
188
-
189
- patching_status.and_condition(
190
- self._test_type_and_finiteness(y), "Input y is not supported."
191
- )
192
182
 
193
183
  return patching_status
194
184
 
195
185
  def _onedal_predict_supported(self, method_name, *data):
196
- assert method_name == "predict"
197
- assert len(data) == 1
198
-
199
186
  class_name = self.__class__.__name__
200
187
  patching_status = PatchingConditionsChain(
201
188
  f"sklearn.linear_model.{class_name}.predict"
202
189
  )
203
190
 
204
- n_samples = _num_samples(*data)
191
+ n_samples = _num_samples(data[0])
205
192
  model_is_sparse = issparse(self.coef_) or (
206
193
  self.fit_intercept and issparse(self.intercept_)
207
194
  )
208
- dal_ready = patching_status.and_conditions(
195
+ patching_status.and_conditions(
209
196
  [
210
197
  (n_samples > 0, "Number of samples is less than 1."),
211
- (not issparse(*data), "Sparse input is not supported."),
198
+ (not issparse(data[0]), "Sparse input is not supported."),
212
199
  (not model_is_sparse, "Sparse coefficients are not supported."),
213
200
  ]
214
201
  )
215
- if not dal_ready:
216
- return patching_status
217
-
218
- patching_status.and_condition(
219
- self._test_type_and_finiteness(*data), "Input X is not supported."
220
- )
221
202
 
222
203
  return patching_status
223
204
 
224
205
  def _onedal_supported(self, method_name, *data):
225
206
  if method_name == "fit":
226
207
  return self._onedal_fit_supported(method_name, *data)
227
- if method_name == "predict":
208
+ if method_name in ["predict", "score"]:
228
209
  return self._onedal_predict_supported(method_name, *data)
229
210
  raise RuntimeError(f"Unknown method {method_name} in {self.__class__.__name__}")
230
211
 
@@ -245,7 +226,6 @@ class LinearRegression(sklearn_LinearRegression):
245
226
  "accept_sparse": ["csr", "csc", "coo"],
246
227
  "y_numeric": True,
247
228
  "multi_output": True,
248
- "force_all_finite": False,
249
229
  }
250
230
  if sklearn_check_version("1.2"):
251
231
  X, y = self._validate_data(**check_params)
@@ -286,6 +266,11 @@ class LinearRegression(sklearn_LinearRegression):
286
266
  res = self._onedal_estimator.predict(X, queue=queue)
287
267
  return res
288
268
 
269
+ def _onedal_score(self, X, y, sample_weight=None, queue=None):
270
+ return r2_score(
271
+ y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
272
+ )
273
+
289
274
  def get_coef_(self):
290
275
  return self.coef_
291
276
 
@@ -314,3 +299,4 @@ class LinearRegression(sklearn_LinearRegression):
314
299
 
315
300
  fit.__doc__ = sklearn_LinearRegression.fit.__doc__
316
301
  predict.__doc__ = sklearn_LinearRegression.predict.__doc__
302
+ score.__doc__ = sklearn_LinearRegression.score.__doc__
@@ -21,18 +21,6 @@ from daal4py.sklearn._utils import daal_check_version
21
21
  from daal4py.sklearn.linear_model.logistic_path import (
22
22
  LogisticRegression as LogisticRegression_daal4py,
23
23
  )
24
- from daal4py.sklearn.linear_model.logistic_path import daal4py_fit, daal4py_predict
25
-
26
-
27
- class BaseLogisticRegression(ABC):
28
- def _save_attributes(self):
29
- assert hasattr(self, "_onedal_estimator")
30
- self.classes_ = self._onedal_estimator.classes_
31
- self.coef_ = self._onedal_estimator.coef_
32
- self.intercept_ = self._onedal_estimator.intercept_
33
- self.n_features_in_ = self._onedal_estimator.n_features_in_
34
- self.n_iter_ = self._onedal_estimator.n_iter_
35
-
36
24
 
37
25
  if daal_check_version((2024, "P", 1)):
38
26
  import numpy as np
@@ -40,16 +28,27 @@ if daal_check_version((2024, "P", 1)):
40
28
  from sklearn.linear_model import LogisticRegression as sklearn_LogisticRegression
41
29
  from sklearn.metrics import accuracy_score
42
30
  from sklearn.utils.multiclass import type_of_target
43
- from sklearn.utils.validation import check_X_y
31
+ from sklearn.utils.validation import check_array, check_is_fitted, check_X_y
44
32
 
45
33
  from daal4py.sklearn._n_jobs_support import control_n_jobs
46
34
  from daal4py.sklearn._utils import sklearn_check_version
35
+ from daal4py.sklearn.linear_model.logistic_path import daal4py_fit, daal4py_predict
47
36
  from onedal.linear_model import LogisticRegression as onedal_LogisticRegression
48
37
  from onedal.utils import _num_samples
49
38
 
50
39
  from .._device_offload import dispatch, wrap_output_data
51
40
  from .._utils import PatchingConditionsChain, get_patch_message
52
- from ..utils.validation import _assert_all_finite
41
+
42
+ _sparsity_enabled = daal_check_version((2024, "P", 700))
43
+
44
+ class BaseLogisticRegression(ABC):
45
+ def _save_attributes(self):
46
+ assert hasattr(self, "_onedal_estimator")
47
+ self.classes_ = self._onedal_estimator.classes_
48
+ self.coef_ = self._onedal_estimator.coef_
49
+ self.intercept_ = self._onedal_estimator.intercept_
50
+ self.n_features_in_ = self._onedal_estimator.n_features_in_
51
+ self.n_iter_ = self._onedal_estimator.n_iter_
53
52
 
54
53
  @control_n_jobs(
55
54
  decorated_methods=[
@@ -82,7 +81,7 @@ if daal_check_version((2024, "P", 1)):
82
81
  random_state=None,
83
82
  solver="lbfgs",
84
83
  max_iter=100,
85
- multi_class="auto",
84
+ multi_class="deprecated" if sklearn_check_version("1.5") else "auto",
86
85
  verbose=0,
87
86
  warm_start=False,
88
87
  n_jobs=None,
@@ -109,8 +108,6 @@ if daal_check_version((2024, "P", 1)):
109
108
  _onedal_cpu_fit = daal4py_fit
110
109
 
111
110
  def fit(self, X, y, sample_weight=None):
112
- if sklearn_check_version("1.0"):
113
- self._check_feature_names(X, reset=True)
114
111
  if sklearn_check_version("1.2"):
115
112
  self._validate_params()
116
113
  dispatch(
@@ -128,8 +125,6 @@ if daal_check_version((2024, "P", 1)):
128
125
 
129
126
  @wrap_output_data
130
127
  def predict(self, X):
131
- if sklearn_check_version("1.0"):
132
- self._check_feature_names(X, reset=False)
133
128
  return dispatch(
134
129
  self,
135
130
  "predict",
@@ -142,11 +137,9 @@ if daal_check_version((2024, "P", 1)):
142
137
 
143
138
  @wrap_output_data
144
139
  def predict_proba(self, X):
145
- if sklearn_check_version("1.0"):
146
- self._check_feature_names(X, reset=False)
147
140
  return dispatch(
148
141
  self,
149
- "predict",
142
+ "predict_proba",
150
143
  {
151
144
  "onedal": self.__class__._onedal_predict_proba,
152
145
  "sklearn": sklearn_LogisticRegression.predict_proba,
@@ -156,11 +149,9 @@ if daal_check_version((2024, "P", 1)):
156
149
 
157
150
  @wrap_output_data
158
151
  def predict_log_proba(self, X):
159
- if sklearn_check_version("1.0"):
160
- self._check_feature_names(X, reset=False)
161
152
  return dispatch(
162
153
  self,
163
- "predict",
154
+ "predict_log_proba",
164
155
  {
165
156
  "onedal": self.__class__._onedal_predict_log_proba,
166
157
  "sklearn": sklearn_LogisticRegression.predict_log_proba,
@@ -170,8 +161,6 @@ if daal_check_version((2024, "P", 1)):
170
161
 
171
162
  @wrap_output_data
172
163
  def score(self, X, y, sample_weight=None):
173
- if sklearn_check_version("1.0"):
174
- self._check_feature_names(X, reset=False)
175
164
  return dispatch(
176
165
  self,
177
166
  "score",
@@ -189,17 +178,6 @@ if daal_check_version((2024, "P", 1)):
189
178
  y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
190
179
  )
191
180
 
192
- def _test_type_and_finiteness(self, X_in):
193
- X = np.asarray(X_in)
194
-
195
- if np.iscomplexobj(X):
196
- return False
197
- try:
198
- _assert_all_finite(X)
199
- except BaseException:
200
- return False
201
- return True
202
-
203
181
  def _onedal_gpu_fit_supported(self, method_name, *data):
204
182
  assert method_name == "fit"
205
183
  assert len(data) == 3
@@ -210,7 +188,12 @@ if daal_check_version((2024, "P", 1)):
210
188
  f"sklearn.linear_model.{class_name}.fit"
211
189
  )
212
190
 
213
- dal_ready = patching_status.and_conditions(
191
+ target_type = (
192
+ type_of_target(y, input_name="y")
193
+ if sklearn_check_version("1.1")
194
+ else type_of_target(y)
195
+ )
196
+ patching_status.and_conditions(
214
197
  [
215
198
  (self.penalty == "l2", "Only l2 penalty is supported."),
216
199
  (self.dual == False, "dual=True is not supported."),
@@ -228,24 +211,12 @@ if daal_check_version((2024, "P", 1)):
228
211
  (self.l1_ratio is None, "l1 ratio is not supported."),
229
212
  (sample_weight is None, "Sample weight is not supported."),
230
213
  (
231
- type_of_target(y) == "binary",
214
+ target_type == "binary",
232
215
  "Only binary classification is supported",
233
216
  ),
234
217
  ]
235
218
  )
236
219
 
237
- if not dal_ready:
238
- return patching_status
239
-
240
- if not patching_status.and_condition(
241
- self._test_type_and_finiteness(X), "Input X is not supported."
242
- ):
243
- return patching_status
244
-
245
- patching_status.and_condition(
246
- self._test_type_and_finiteness(y), "Input y is not supported."
247
- )
248
-
249
220
  return patching_status
250
221
 
251
222
  def _onedal_gpu_predict_supported(self, method_name, *data):
@@ -269,7 +240,7 @@ if daal_check_version((2024, "P", 1)):
269
240
  [
270
241
  (n_samples > 0, "Number of samples is less than 1."),
271
242
  (
272
- not any([issparse(i) for i in data]),
243
+ (not any([issparse(i) for i in data])) or _sparsity_enabled,
273
244
  "Sparse input is not supported.",
274
245
  ),
275
246
  (not model_is_sparse, "Sparse coefficients are not supported."),
@@ -279,12 +250,6 @@ if daal_check_version((2024, "P", 1)):
279
250
  ),
280
251
  ]
281
252
  )
282
- if not dal_ready:
283
- return patching_status
284
-
285
- patching_status.and_condition(
286
- self._test_type_and_finiteness(*data), "Input X is not supported."
287
- )
288
253
 
289
254
  return patching_status
290
255
 
@@ -315,24 +280,29 @@ if daal_check_version((2024, "P", 1)):
315
280
  }
316
281
  self._onedal_estimator = onedal_LogisticRegression(**onedal_params)
317
282
 
318
- def _onedal_fit(self, X, y, sample_weight, queue=None):
283
+ def _onedal_fit(self, X, y, sample_weight=None, queue=None):
319
284
  if queue is None or queue.sycl_device.is_cpu:
320
285
  return self._onedal_cpu_fit(X, y, sample_weight)
321
286
 
322
287
  assert sample_weight is None
323
288
 
324
- check_params = {
325
- "X": X,
326
- "y": y,
327
- "dtype": [np.float64, np.float32],
328
- "accept_sparse": False,
329
- "multi_output": False,
330
- "force_all_finite": True,
331
- }
332
- if sklearn_check_version("1.2"):
333
- X, y = self._validate_data(**check_params)
289
+ if sklearn_check_version("1.0"):
290
+ X, y = self._validate_data(
291
+ X,
292
+ y,
293
+ accept_sparse=_sparsity_enabled,
294
+ accept_large_sparse=_sparsity_enabled,
295
+ dtype=[np.float64, np.float32],
296
+ )
334
297
  else:
335
- X, y = check_X_y(**check_params)
298
+ X, y = check_X_y(
299
+ X,
300
+ y,
301
+ accept_sparse=_sparsity_enabled,
302
+ accept_large_sparse=_sparsity_enabled,
303
+ dtype=[np.float64, np.float32],
304
+ )
305
+
336
306
  self._initialize_onedal_estimator()
337
307
  try:
338
308
  self._onedal_estimator.fit(X, y, queue=queue)
@@ -350,7 +320,23 @@ if daal_check_version((2024, "P", 1)):
350
320
  if queue is None or queue.sycl_device.is_cpu:
351
321
  return daal4py_predict(self, X, "computeClassLabels")
352
322
 
353
- X = self._validate_data(X, accept_sparse=False, reset=False)
323
+ check_is_fitted(self)
324
+ if sklearn_check_version("1.0"):
325
+ X = self._validate_data(
326
+ X,
327
+ reset=False,
328
+ accept_sparse=_sparsity_enabled,
329
+ accept_large_sparse=_sparsity_enabled,
330
+ dtype=[np.float64, np.float32],
331
+ )
332
+ else:
333
+ X = check_array(
334
+ X,
335
+ accept_sparse=_sparsity_enabled,
336
+ accept_large_sparse=_sparsity_enabled,
337
+ dtype=[np.float64, np.float32],
338
+ )
339
+
354
340
  assert hasattr(self, "_onedal_estimator")
355
341
  return self._onedal_estimator.predict(X, queue=queue)
356
342
 
@@ -358,7 +344,23 @@ if daal_check_version((2024, "P", 1)):
358
344
  if queue is None or queue.sycl_device.is_cpu:
359
345
  return daal4py_predict(self, X, "computeClassProbabilities")
360
346
 
361
- X = self._validate_data(X, accept_sparse=False, reset=False)
347
+ check_is_fitted(self)
348
+ if sklearn_check_version("1.0"):
349
+ X = self._validate_data(
350
+ X,
351
+ reset=False,
352
+ accept_sparse=_sparsity_enabled,
353
+ accept_large_sparse=_sparsity_enabled,
354
+ dtype=[np.float64, np.float32],
355
+ )
356
+ else:
357
+ X = check_array(
358
+ X,
359
+ accept_sparse=_sparsity_enabled,
360
+ accept_large_sparse=_sparsity_enabled,
361
+ dtype=[np.float64, np.float32],
362
+ )
363
+
362
364
  assert hasattr(self, "_onedal_estimator")
363
365
  return self._onedal_estimator.predict_proba(X, queue=queue)
364
366
 
@@ -366,7 +368,23 @@ if daal_check_version((2024, "P", 1)):
366
368
  if queue is None or queue.sycl_device.is_cpu:
367
369
  return daal4py_predict(self, X, "computeClassLogProbabilities")
368
370
 
369
- X = self._validate_data(X, accept_sparse=False, reset=False)
371
+ check_is_fitted(self)
372
+ if sklearn_check_version("1.0"):
373
+ X = self._validate_data(
374
+ X,
375
+ reset=False,
376
+ accept_sparse=_sparsity_enabled,
377
+ accept_large_sparse=_sparsity_enabled,
378
+ dtype=[np.float64, np.float32],
379
+ )
380
+ else:
381
+ X = check_array(
382
+ X,
383
+ accept_sparse=_sparsity_enabled,
384
+ accept_large_sparse=_sparsity_enabled,
385
+ dtype=[np.float64, np.float32],
386
+ )
387
+
370
388
  assert hasattr(self, "_onedal_estimator")
371
389
  return self._onedal_estimator.predict_log_proba(X, queue=queue)
372
390
 
@@ -15,3 +15,10 @@
15
15
  # ===============================================================================
16
16
 
17
17
  from daal4py.sklearn.linear_model import Ridge
18
+ from onedal._device_offload import support_usm_ndarray
19
+
20
+ # Note: `sklearnex.linear_model.Ridge` only has functional
21
+ # sycl GPU support. No GPU device will be offloaded.
22
+ Ridge.fit = support_usm_ndarray(queue_param=False)(Ridge.fit)
23
+ Ridge.predict = support_usm_ndarray(queue_param=False)(Ridge.predict)
24
+ Ridge.score = support_usm_ndarray(queue_param=False)(Ridge.score)