scikit-learn-intelex 2024.3.0__py310-none-manylinux1_x86_64.whl → 2024.5.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.
- {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.5.0.dist-info}/METADATA +2 -2
- {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.5.0.dist-info}/RECORD +43 -37
- sklearnex/_device_offload.py +39 -5
- 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 +384 -0
- sklearnex/covariance/incremental_covariance.py +217 -30
- sklearnex/covariance/tests/test_incremental_covariance.py +54 -17
- sklearnex/decomposition/pca.py +71 -19
- sklearnex/decomposition/tests/test_pca.py +2 -2
- sklearnex/dispatcher.py +33 -2
- sklearnex/ensemble/_forest.py +73 -79
- sklearnex/linear_model/__init__.py +5 -3
- sklearnex/linear_model/incremental_linear.py +387 -0
- sklearnex/linear_model/linear.py +275 -340
- sklearnex/linear_model/logistic_regression.py +50 -9
- sklearnex/linear_model/tests/test_incremental_linear.py +200 -0
- sklearnex/linear_model/tests/test_linear.py +40 -5
- sklearnex/neighbors/_lof.py +53 -36
- sklearnex/neighbors/common.py +4 -1
- sklearnex/neighbors/knn_classification.py +37 -122
- sklearnex/neighbors/knn_regression.py +10 -117
- sklearnex/neighbors/knn_unsupervised.py +6 -78
- sklearnex/neighbors/tests/test_neighbors.py +2 -2
- 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/svm/_common.py +4 -7
- sklearnex/svm/nusvc.py +66 -50
- sklearnex/svm/nusvr.py +3 -49
- sklearnex/svm/svc.py +66 -51
- sklearnex/svm/svr.py +3 -49
- sklearnex/tests/_utils.py +34 -16
- sklearnex/tests/test_memory_usage.py +5 -1
- sklearnex/tests/test_n_jobs_support.py +12 -2
- sklearnex/tests/test_patching.py +87 -58
- sklearnex/tests/test_run_to_run_stability_tests.py +1 -1
- sklearnex/utils/__init__.py +2 -1
- sklearnex/utils/_namespace.py +97 -0
- sklearnex/utils/tests/test_finite.py +89 -0
- {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.5.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.5.0.dist-info}/WHEEL +0 -0
- {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.5.0.dist-info}/top_level.txt +0 -0
sklearnex/dispatcher.py
CHANGED
|
@@ -93,6 +93,7 @@ def get_patch_map_core(preview=False):
|
|
|
93
93
|
# Scikit-learn* modules
|
|
94
94
|
import sklearn as base_module
|
|
95
95
|
import sklearn.cluster as cluster_module
|
|
96
|
+
import sklearn.covariance as covariance_module
|
|
96
97
|
import sklearn.decomposition as decomposition_module
|
|
97
98
|
import sklearn.ensemble as ensemble_module
|
|
98
99
|
import sklearn.linear_model as linear_model_module
|
|
@@ -115,11 +116,17 @@ def get_patch_map_core(preview=False):
|
|
|
115
116
|
from .utils.parallel import _FuncWrapperOld as _FuncWrapper_sklearnex
|
|
116
117
|
|
|
117
118
|
from .cluster import DBSCAN as DBSCAN_sklearnex
|
|
119
|
+
from .covariance import (
|
|
120
|
+
IncrementalEmpiricalCovariance as IncrementalEmpiricalCovariance_sklearnex,
|
|
121
|
+
)
|
|
118
122
|
from .decomposition import PCA as PCA_sklearnex
|
|
119
123
|
from .ensemble import ExtraTreesClassifier as ExtraTreesClassifier_sklearnex
|
|
120
124
|
from .ensemble import ExtraTreesRegressor as ExtraTreesRegressor_sklearnex
|
|
121
125
|
from .ensemble import RandomForestClassifier as RandomForestClassifier_sklearnex
|
|
122
126
|
from .ensemble import RandomForestRegressor as RandomForestRegressor_sklearnex
|
|
127
|
+
from .linear_model import (
|
|
128
|
+
IncrementalLinearRegression as IncrementalLinearRegression_sklearnex,
|
|
129
|
+
)
|
|
123
130
|
from .linear_model import LinearRegression as LinearRegression_sklearnex
|
|
124
131
|
from .linear_model import LogisticRegression as LogisticRegression_sklearnex
|
|
125
132
|
from .neighbors import KNeighborsClassifier as KNeighborsClassifier_sklearnex
|
|
@@ -273,6 +280,30 @@ def get_patch_map_core(preview=False):
|
|
|
273
280
|
]
|
|
274
281
|
mapping["localoutlierfactor"] = mapping["lof"]
|
|
275
282
|
|
|
283
|
+
# IncrementalEmpiricalCovariance
|
|
284
|
+
mapping["incrementalempiricalcovariance"] = [
|
|
285
|
+
[
|
|
286
|
+
(
|
|
287
|
+
covariance_module,
|
|
288
|
+
"IncrementalEmpiricalCovariance",
|
|
289
|
+
IncrementalEmpiricalCovariance_sklearnex,
|
|
290
|
+
),
|
|
291
|
+
None,
|
|
292
|
+
]
|
|
293
|
+
]
|
|
294
|
+
|
|
295
|
+
# IncrementalLinearRegression
|
|
296
|
+
mapping["incrementallinearregression"] = [
|
|
297
|
+
[
|
|
298
|
+
(
|
|
299
|
+
linear_model_module,
|
|
300
|
+
"IncrementalLinearRegression",
|
|
301
|
+
IncrementalLinearRegression_sklearnex,
|
|
302
|
+
),
|
|
303
|
+
None,
|
|
304
|
+
]
|
|
305
|
+
]
|
|
306
|
+
|
|
276
307
|
# Configs
|
|
277
308
|
mapping["set_config"] = [
|
|
278
309
|
[(base_module, "set_config", set_config_sklearnex), None]
|
|
@@ -314,10 +345,10 @@ def get_patch_names():
|
|
|
314
345
|
def patch_sklearn(name=None, verbose=True, global_patch=False, preview=False):
|
|
315
346
|
if preview:
|
|
316
347
|
os.environ["SKLEARNEX_PREVIEW"] = "enabled_via_patch_sklearn"
|
|
317
|
-
if not sklearn_check_version("0.
|
|
348
|
+
if not sklearn_check_version("0.24"):
|
|
318
349
|
raise NotImplementedError(
|
|
319
350
|
"Intel(R) Extension for Scikit-learn* patches apply "
|
|
320
|
-
"for scikit-learn >= 0.
|
|
351
|
+
"for scikit-learn >= 0.24 only ..."
|
|
321
352
|
)
|
|
322
353
|
|
|
323
354
|
if global_patch:
|
sklearnex/ensemble/_forest.py
CHANGED
|
@@ -25,8 +25,11 @@ from sklearn.ensemble import ExtraTreesClassifier as sklearn_ExtraTreesClassifie
|
|
|
25
25
|
from sklearn.ensemble import ExtraTreesRegressor as sklearn_ExtraTreesRegressor
|
|
26
26
|
from sklearn.ensemble import RandomForestClassifier as sklearn_RandomForestClassifier
|
|
27
27
|
from sklearn.ensemble import RandomForestRegressor as sklearn_RandomForestRegressor
|
|
28
|
+
from sklearn.ensemble._forest import ForestClassifier as sklearn_ForestClassifier
|
|
29
|
+
from sklearn.ensemble._forest import ForestRegressor as sklearn_ForestRegressor
|
|
28
30
|
from sklearn.ensemble._forest import _get_n_samples_bootstrap
|
|
29
31
|
from sklearn.exceptions import DataConversionWarning
|
|
32
|
+
from sklearn.metrics import accuracy_score
|
|
30
33
|
from sklearn.tree import (
|
|
31
34
|
DecisionTreeClassifier,
|
|
32
35
|
DecisionTreeRegressor,
|
|
@@ -35,12 +38,7 @@ from sklearn.tree import (
|
|
|
35
38
|
)
|
|
36
39
|
from sklearn.tree._tree import Tree
|
|
37
40
|
from sklearn.utils import check_random_state, deprecated
|
|
38
|
-
from sklearn.utils.validation import
|
|
39
|
-
check_array,
|
|
40
|
-
check_consistent_length,
|
|
41
|
-
check_is_fitted,
|
|
42
|
-
check_X_y,
|
|
43
|
-
)
|
|
41
|
+
from sklearn.utils.validation import check_array, check_is_fitted
|
|
44
42
|
|
|
45
43
|
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
46
44
|
from daal4py.sklearn._utils import (
|
|
@@ -52,19 +50,10 @@ from onedal.ensemble import ExtraTreesClassifier as onedal_ExtraTreesClassifier
|
|
|
52
50
|
from onedal.ensemble import ExtraTreesRegressor as onedal_ExtraTreesRegressor
|
|
53
51
|
from onedal.ensemble import RandomForestClassifier as onedal_RandomForestClassifier
|
|
54
52
|
from onedal.ensemble import RandomForestRegressor as onedal_RandomForestRegressor
|
|
55
|
-
|
|
56
|
-
# try catch needed for changes in structures observed in Scikit-learn around v0.22
|
|
57
|
-
try:
|
|
58
|
-
from sklearn.ensemble._forest import ForestClassifier as sklearn_ForestClassifier
|
|
59
|
-
from sklearn.ensemble._forest import ForestRegressor as sklearn_ForestRegressor
|
|
60
|
-
except ModuleNotFoundError:
|
|
61
|
-
from sklearn.ensemble.forest import ForestClassifier as sklearn_ForestClassifier
|
|
62
|
-
from sklearn.ensemble.forest import ForestRegressor as sklearn_ForestRegressor
|
|
63
|
-
|
|
64
53
|
from onedal.primitives import get_tree_state_cls, get_tree_state_reg
|
|
65
54
|
from onedal.utils import _num_features, _num_samples
|
|
55
|
+
from sklearnex.utils import get_namespace
|
|
66
56
|
|
|
67
|
-
from .._config import get_config
|
|
68
57
|
from .._device_offload import dispatch, wrap_output_data
|
|
69
58
|
from .._utils import PatchingConditionsChain
|
|
70
59
|
|
|
@@ -78,24 +67,14 @@ class BaseForest(ABC):
|
|
|
78
67
|
_onedal_factory = None
|
|
79
68
|
|
|
80
69
|
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
|
|
81
|
-
|
|
82
|
-
X,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
)
|
|
90
|
-
else:
|
|
91
|
-
X, y = check_X_y(
|
|
92
|
-
X,
|
|
93
|
-
y,
|
|
94
|
-
accept_sparse=False,
|
|
95
|
-
dtype=[np.float64, np.float32],
|
|
96
|
-
multi_output=False,
|
|
97
|
-
force_all_finite=False,
|
|
98
|
-
)
|
|
70
|
+
X, y = self._validate_data(
|
|
71
|
+
X,
|
|
72
|
+
y,
|
|
73
|
+
multi_output=False,
|
|
74
|
+
accept_sparse=False,
|
|
75
|
+
dtype=[np.float64, np.float32],
|
|
76
|
+
force_all_finite=False,
|
|
77
|
+
)
|
|
99
78
|
|
|
100
79
|
if sample_weight is not None:
|
|
101
80
|
sample_weight = self.check_sample_weight(sample_weight, X)
|
|
@@ -173,15 +152,6 @@ class BaseForest(ABC):
|
|
|
173
152
|
|
|
174
153
|
return self
|
|
175
154
|
|
|
176
|
-
def _fit_proba(self, X, y, sample_weight=None, queue=None):
|
|
177
|
-
params = self.get_params()
|
|
178
|
-
self.__class__(**params)
|
|
179
|
-
|
|
180
|
-
# We use stock metaestimators below, so the only way
|
|
181
|
-
# to pass a queue is using config_context.
|
|
182
|
-
cfg = get_config()
|
|
183
|
-
cfg["target_offload"] = queue
|
|
184
|
-
|
|
185
155
|
def _save_attributes(self):
|
|
186
156
|
if self.oob_score:
|
|
187
157
|
self.oob_score_ = self._onedal_estimator.oob_score_
|
|
@@ -204,8 +174,6 @@ class BaseForest(ABC):
|
|
|
204
174
|
self._validate_estimator()
|
|
205
175
|
return self
|
|
206
176
|
|
|
207
|
-
# TODO:
|
|
208
|
-
# move to onedal modul.
|
|
209
177
|
def _check_parameters(self):
|
|
210
178
|
if isinstance(self.min_samples_leaf, numbers.Integral):
|
|
211
179
|
if not 1 <= self.min_samples_leaf:
|
|
@@ -550,18 +518,14 @@ class ForestClassifier(sklearn_ForestClassifier, BaseForest):
|
|
|
550
518
|
)
|
|
551
519
|
|
|
552
520
|
if patching_status.get_status():
|
|
553
|
-
|
|
554
|
-
X,
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
)
|
|
562
|
-
else:
|
|
563
|
-
X = check_array(X, dtype=[np.float64, np.float32], force_all_finite=False)
|
|
564
|
-
y = check_array(y, ensure_2d=False, dtype=X.dtype, force_all_finite=False)
|
|
521
|
+
X, y = self._validate_data(
|
|
522
|
+
X,
|
|
523
|
+
y,
|
|
524
|
+
multi_output=True,
|
|
525
|
+
accept_sparse=True,
|
|
526
|
+
dtype=[np.float64, np.float32],
|
|
527
|
+
force_all_finite=False,
|
|
528
|
+
)
|
|
565
529
|
|
|
566
530
|
if y.ndim == 2 and y.shape[1] == 1:
|
|
567
531
|
warnings.warn(
|
|
@@ -655,9 +619,38 @@ class ForestClassifier(sklearn_ForestClassifier, BaseForest):
|
|
|
655
619
|
X,
|
|
656
620
|
)
|
|
657
621
|
|
|
622
|
+
def predict_log_proba(self, X):
|
|
623
|
+
xp, _ = get_namespace(X)
|
|
624
|
+
proba = self.predict_proba(X)
|
|
625
|
+
|
|
626
|
+
if self.n_outputs_ == 1:
|
|
627
|
+
return xp.log(proba)
|
|
628
|
+
|
|
629
|
+
else:
|
|
630
|
+
for k in range(self.n_outputs_):
|
|
631
|
+
proba[k] = xp.log(proba[k])
|
|
632
|
+
|
|
633
|
+
return proba
|
|
634
|
+
|
|
635
|
+
@wrap_output_data
|
|
636
|
+
def score(self, X, y, sample_weight=None):
|
|
637
|
+
return dispatch(
|
|
638
|
+
self,
|
|
639
|
+
"score",
|
|
640
|
+
{
|
|
641
|
+
"onedal": self.__class__._onedal_score,
|
|
642
|
+
"sklearn": sklearn_ForestClassifier.score,
|
|
643
|
+
},
|
|
644
|
+
X,
|
|
645
|
+
y,
|
|
646
|
+
sample_weight=sample_weight,
|
|
647
|
+
)
|
|
648
|
+
|
|
658
649
|
fit.__doc__ = sklearn_ForestClassifier.fit.__doc__
|
|
659
650
|
predict.__doc__ = sklearn_ForestClassifier.predict.__doc__
|
|
660
651
|
predict_proba.__doc__ = sklearn_ForestClassifier.predict_proba.__doc__
|
|
652
|
+
predict_log_proba.__doc__ = sklearn_ForestClassifier.predict_log_proba.__doc__
|
|
653
|
+
score.__doc__ = sklearn_ForestClassifier.score.__doc__
|
|
661
654
|
|
|
662
655
|
def _onedal_cpu_supported(self, method_name, *data):
|
|
663
656
|
class_name = self.__class__.__name__
|
|
@@ -684,7 +677,7 @@ class ForestClassifier(sklearn_ForestClassifier, BaseForest):
|
|
|
684
677
|
]
|
|
685
678
|
)
|
|
686
679
|
|
|
687
|
-
elif method_name in ["predict", "predict_proba"]:
|
|
680
|
+
elif method_name in ["predict", "predict_proba", "score"]:
|
|
688
681
|
X = data[0]
|
|
689
682
|
|
|
690
683
|
patching_status.and_conditions(
|
|
@@ -749,7 +742,7 @@ class ForestClassifier(sklearn_ForestClassifier, BaseForest):
|
|
|
749
742
|
]
|
|
750
743
|
)
|
|
751
744
|
|
|
752
|
-
elif method_name in ["predict", "predict_proba"]:
|
|
745
|
+
elif method_name in ["predict", "predict_proba", "score"]:
|
|
753
746
|
X = data[0]
|
|
754
747
|
|
|
755
748
|
patching_status.and_conditions(
|
|
@@ -784,15 +777,16 @@ class ForestClassifier(sklearn_ForestClassifier, BaseForest):
|
|
|
784
777
|
return patching_status
|
|
785
778
|
|
|
786
779
|
def _onedal_predict(self, X, queue=None):
|
|
780
|
+
check_is_fitted(self, "_onedal_estimator")
|
|
781
|
+
|
|
782
|
+
if sklearn_check_version("1.0"):
|
|
783
|
+
self._check_feature_names(X, reset=False)
|
|
784
|
+
|
|
787
785
|
X = check_array(
|
|
788
786
|
X,
|
|
789
787
|
dtype=[np.float64, np.float32],
|
|
790
788
|
force_all_finite=False,
|
|
791
789
|
) # Warning, order of dtype matters
|
|
792
|
-
check_is_fitted(self, "_onedal_estimator")
|
|
793
|
-
|
|
794
|
-
if sklearn_check_version("1.0"):
|
|
795
|
-
self._check_feature_names(X, reset=False)
|
|
796
790
|
|
|
797
791
|
res = self._onedal_estimator.predict(X, queue=queue)
|
|
798
792
|
return np.take(self.classes_, res.ravel().astype(np.int64, casting="unsafe"))
|
|
@@ -801,12 +795,16 @@ class ForestClassifier(sklearn_ForestClassifier, BaseForest):
|
|
|
801
795
|
X = check_array(X, dtype=[np.float64, np.float32], force_all_finite=False)
|
|
802
796
|
check_is_fitted(self, "_onedal_estimator")
|
|
803
797
|
|
|
804
|
-
|
|
805
|
-
self._check_n_features(X, reset=False)
|
|
798
|
+
self._check_n_features(X, reset=False)
|
|
806
799
|
if sklearn_check_version("1.0"):
|
|
807
800
|
self._check_feature_names(X, reset=False)
|
|
808
801
|
return self._onedal_estimator.predict_proba(X, queue=queue)
|
|
809
802
|
|
|
803
|
+
def _onedal_score(self, X, y, sample_weight=None, queue=None):
|
|
804
|
+
return accuracy_score(
|
|
805
|
+
y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
|
|
806
|
+
)
|
|
807
|
+
|
|
810
808
|
|
|
811
809
|
class ForestRegressor(sklearn_ForestRegressor, BaseForest):
|
|
812
810
|
_err = "out_of_bag_error_r2|out_of_bag_error_prediction"
|
|
@@ -916,18 +914,14 @@ class ForestRegressor(sklearn_ForestRegressor, BaseForest):
|
|
|
916
914
|
)
|
|
917
915
|
|
|
918
916
|
if patching_status.get_status():
|
|
919
|
-
|
|
920
|
-
X,
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
)
|
|
928
|
-
else:
|
|
929
|
-
X = check_array(X, dtype=[np.float64, np.float32], force_all_finite=False)
|
|
930
|
-
y = check_array(y, ensure_2d=False, dtype=X.dtype, force_all_finite=False)
|
|
917
|
+
X, y = self._validate_data(
|
|
918
|
+
X,
|
|
919
|
+
y,
|
|
920
|
+
multi_output=True,
|
|
921
|
+
accept_sparse=True,
|
|
922
|
+
dtype=[np.float64, np.float32],
|
|
923
|
+
force_all_finite=False,
|
|
924
|
+
)
|
|
931
925
|
|
|
932
926
|
if y.ndim == 2 and y.shape[1] == 1:
|
|
933
927
|
warnings.warn(
|
|
@@ -1129,7 +1123,7 @@ class ForestRegressor(sklearn_ForestRegressor, BaseForest):
|
|
|
1129
1123
|
predict.__doc__ = sklearn_ForestRegressor.predict.__doc__
|
|
1130
1124
|
|
|
1131
1125
|
|
|
1132
|
-
@control_n_jobs(decorated_methods=["fit", "predict", "predict_proba"])
|
|
1126
|
+
@control_n_jobs(decorated_methods=["fit", "predict", "predict_proba", "score"])
|
|
1133
1127
|
class RandomForestClassifier(ForestClassifier):
|
|
1134
1128
|
__doc__ = sklearn_RandomForestClassifier.__doc__
|
|
1135
1129
|
_onedal_factory = onedal_RandomForestClassifier
|
|
@@ -1540,7 +1534,7 @@ class RandomForestRegressor(ForestRegressor):
|
|
|
1540
1534
|
self.min_bin_size = min_bin_size
|
|
1541
1535
|
|
|
1542
1536
|
|
|
1543
|
-
@control_n_jobs(decorated_methods=["fit", "predict", "predict_proba"])
|
|
1537
|
+
@control_n_jobs(decorated_methods=["fit", "predict", "predict_proba", "score"])
|
|
1544
1538
|
class ExtraTreesClassifier(ForestClassifier):
|
|
1545
1539
|
__doc__ = sklearn_ExtraTreesClassifier.__doc__
|
|
1546
1540
|
_onedal_factory = onedal_ExtraTreesClassifier
|
|
@@ -15,14 +15,16 @@
|
|
|
15
15
|
# ===============================================================================
|
|
16
16
|
|
|
17
17
|
from .coordinate_descent import ElasticNet, Lasso
|
|
18
|
+
from .incremental_linear import IncrementalLinearRegression
|
|
18
19
|
from .linear import LinearRegression
|
|
19
20
|
from .logistic_regression import LogisticRegression
|
|
20
21
|
from .ridge import Ridge
|
|
21
22
|
|
|
22
23
|
__all__ = [
|
|
23
|
-
"Ridge",
|
|
24
|
-
"LinearRegression",
|
|
25
|
-
"LogisticRegression",
|
|
26
24
|
"ElasticNet",
|
|
25
|
+
"IncrementalLinearRegression",
|
|
27
26
|
"Lasso",
|
|
27
|
+
"LinearRegression",
|
|
28
|
+
"LogisticRegression",
|
|
29
|
+
"Ridge",
|
|
28
30
|
]
|