scikit-learn-intelex 2024.3.0__py39-none-manylinux1_x86_64.whl → 2024.4.0__py39-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.4.0.dist-info}/METADATA +2 -2
- {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/RECORD +33 -30
- 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/decomposition/pca.py +3 -6
- sklearnex/dispatcher.py +2 -2
- sklearnex/ensemble/_forest.py +68 -75
- sklearnex/linear_model/linear.py +275 -340
- sklearnex/linear_model/logistic_regression.py +50 -9
- 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/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 +14 -5
- sklearnex/tests/test_n_jobs_support.py +8 -2
- sklearnex/tests/test_patching.py +64 -54
- sklearnex/utils/__init__.py +2 -1
- sklearnex/utils/_namespace.py +97 -0
- {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/WHEEL +0 -0
- {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/top_level.txt +0 -0
{scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: scikit-learn-intelex
|
|
3
|
-
Version: 2024.
|
|
3
|
+
Version: 2024.4.0
|
|
4
4
|
Summary: Intel(R) Extension for Scikit-learn is a seamless way to speed up your Scikit-learn application.
|
|
5
5
|
Home-page: https://github.com/intel/scikit-learn-intelex
|
|
6
6
|
Author: Intel Corporation
|
|
@@ -31,7 +31,7 @@ Classifier: Topic :: Software Development
|
|
|
31
31
|
Requires-Python: >=3.7
|
|
32
32
|
Description-Content-Type: text/markdown
|
|
33
33
|
License-File: LICENSE.txt
|
|
34
|
-
Requires-Dist: daal4py (==2024.
|
|
34
|
+
Requires-Dist: daal4py (==2024.4.0)
|
|
35
35
|
Requires-Dist: scikit-learn (>=0.22)
|
|
36
36
|
|
|
37
37
|
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
sklearnex/__init__.py,sha256=DVpGCMMQcUlrOGj_iy1jk3ZhCfa0_TFISYLqaUDRqC0,1780
|
|
2
2
|
sklearnex/__main__.py,sha256=Le9BJq6aLEGSSoZwJLsOADxsV89ynBfA8BcoJHk9F24,1921
|
|
3
3
|
sklearnex/_config.py,sha256=6WS3UuS4-0DxIJyGn7yQMosj-mGkLybLQrg3W7dED5o,3928
|
|
4
|
-
sklearnex/_device_offload.py,sha256=
|
|
4
|
+
sklearnex/_device_offload.py,sha256=EX9bRBV9tFxQBRf8mS9ntBEmB7tcIfql8sYnb9Zjlto,8639
|
|
5
5
|
sklearnex/_utils.py,sha256=EV4jC3plVdndsgrfPBsJZTzggrRdYWLwOpoIRWtTXt4,3812
|
|
6
6
|
sklearnex/conftest.py,sha256=ZvcfQljZNBa3zlE1iITvuacHblugVtK6X80LwNXrnWI,2130
|
|
7
|
-
sklearnex/dispatcher.py,sha256=
|
|
8
|
-
sklearnex/basic_statistics/__init__.py,sha256
|
|
7
|
+
sklearnex/dispatcher.py,sha256=Vpoy6kwOR0Y3ISfjpk0S1vEKhDZGLUKeMy-xwCBsCQs,14389
|
|
8
|
+
sklearnex/basic_statistics/__init__.py,sha256=-lNh54F2FO0BuHDBLjhW7zp3yBcgFZ-DrXHj2H5hLXE,920
|
|
9
9
|
sklearnex/basic_statistics/basic_statistics.py,sha256=j5jBZ3DgXjoyjCBEFfYQHyl3LgLXEWWFnNHwInThdZw,796
|
|
10
|
+
sklearnex/basic_statistics/incremental_basic_statistics.py,sha256=NNWF9zdxBz2jT7dzt5hL6HRvjQIGosvViQE3KJMF1L4,10048
|
|
11
|
+
sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py,sha256=GarYPjojsyhbOat5vOXF85AofyFa_VretX4Vntc01C8,14992
|
|
10
12
|
sklearnex/cluster/__init__.py,sha256=TsDzdbKzEubaP86iY8a7mSW0ZQzgjzGYuPkhc5lZmlQ,853
|
|
11
13
|
sklearnex/cluster/dbscan.py,sha256=JJaNVhV4dVK0xte9xzQpCAka80xVu3M7_SzmvD3k-EY,6736
|
|
12
14
|
sklearnex/cluster/k_means.py,sha256=1QKcFUQcnycu8kSD8uYSaDIuedHbxZsV_gvUfcEwVAM,806
|
|
@@ -16,21 +18,21 @@ sklearnex/covariance/__init__.py,sha256=_c86wiKDGBH50ofN-_tn7lO4M2YVEWO5AHhJIfim
|
|
|
16
18
|
sklearnex/covariance/incremental_covariance.py,sha256=3s9gmLP48DPhlhnFcg2JB7RQ2sliSZdNroJkv8-1sIA,4526
|
|
17
19
|
sklearnex/covariance/tests/test_incremental_covariance.py,sha256=JIa4p-1_RYvU2ZVLx27iz0OKp0Nwrl9sYCsT0Dlyi2I,5402
|
|
18
20
|
sklearnex/decomposition/__init__.py,sha256=RJBYDWyvnn5DA-j5r4IqVdXLp6H4mdPySsSjnXhlv-U,805
|
|
19
|
-
sklearnex/decomposition/pca.py,sha256=
|
|
21
|
+
sklearnex/decomposition/pca.py,sha256=ffR22wH2n5R8SYflEmOPDPc-QpTomiAMOegV0IMbslg,12654
|
|
20
22
|
sklearnex/decomposition/tests/test_pca.py,sha256=FJYMosxpQpdOo71QD0jVx47oWEhvVNdut_5EOxTyT_0,2201
|
|
21
23
|
sklearnex/doc/third-party-programs.txt,sha256=qA1XbOqYkMRnp29p8VxXjfcH0kHE8NSO5s2heea83-8,21773
|
|
22
24
|
sklearnex/ensemble/__init__.py,sha256=2xB2KfG7l7uJv0p3kfVhrs4KLM174SCsigZhYqwSYAA,1035
|
|
23
|
-
sklearnex/ensemble/_forest.py,sha256=
|
|
25
|
+
sklearnex/ensemble/_forest.py,sha256=OHxqhYhkdjzhhEeWLlE0_IXBrWmKCUJoP_B1gQcmTQM,70002
|
|
24
26
|
sklearnex/ensemble/tests/test_forest.py,sha256=r1GSPQuVVuWYoNB3ZLiGKfMSwq3lp5i6k-Rgr7InonQ,4456
|
|
25
27
|
sklearnex/glob/__main__.py,sha256=--FAjkhh5E6a1TFOGu6_BM3MHe78jP8oSpl0xKiRtTI,2531
|
|
26
28
|
sklearnex/glob/dispatcher.py,sha256=IEEPhAOCVzC2JDFvYtijbiPAbaUY5RrCAhFLRjMMe1w,3018
|
|
27
29
|
sklearnex/linear_model/__init__.py,sha256=5XZDZh8R0SmT8D8ZtSjW7-MKRO7l1jOZ8CUnt_OzHe4,1047
|
|
28
30
|
sklearnex/linear_model/coordinate_descent.py,sha256=uZOHIKfFlHoMlNXZCh2MAnZE30fRZlmtcF7UsZQ3Vq4,822
|
|
29
|
-
sklearnex/linear_model/linear.py,sha256=
|
|
31
|
+
sklearnex/linear_model/linear.py,sha256=0A2kCTpsGZK8IVkbIhYoAXqMAxHOyY7dO5JLxbNWmLw,11159
|
|
30
32
|
sklearnex/linear_model/logistic_path.py,sha256=Nq3JPXSzE4bjamnP3gGQtsMKks2v7s6bSiuYRnFqrRw,849
|
|
31
|
-
sklearnex/linear_model/logistic_regression.py,sha256=
|
|
33
|
+
sklearnex/linear_model/logistic_regression.py,sha256=6TRaDJ8nIHxjofIfUvmeJOP9_EwmUgVKKK1sxe9vS5A,14171
|
|
32
34
|
sklearnex/linear_model/ridge.py,sha256=0oxlM5McYYvl0KxK9OIGJKM6lOADuFSPTdfx-efJNTI,810
|
|
33
|
-
sklearnex/linear_model/tests/test_linear.py,sha256=
|
|
35
|
+
sklearnex/linear_model/tests/test_linear.py,sha256=kLoOcP9p0iCK2PhU438tGuPGuuBekF37FkA-YBcBMpM,4319
|
|
34
36
|
sklearnex/linear_model/tests/test_logreg.py,sha256=mUYDwTDUekERlzxjnVeOeCUcNv4KJAXdTIiELZNSaDc,3283
|
|
35
37
|
sklearnex/manifold/__init__.py,sha256=3FU5fY1YvHAyNeSlUHsZfPnAbvlAUtZpum0Obmok2KE,809
|
|
36
38
|
sklearnex/manifold/t_sne.py,sha256=U6F_dGB6taVuEJvTnVBWD-sri3x3m0Khu3HI4wXidhg,805
|
|
@@ -43,19 +45,19 @@ sklearnex/model_selection/__init__.py,sha256=64045Y-nzLDBepO6IRjt88LhL2DM3KdvpCF
|
|
|
43
45
|
sklearnex/model_selection/split.py,sha256=qjmy8sRf_QEG8LhT0ivn_tICMCYmt7ffZZV1-rLQnko,824
|
|
44
46
|
sklearnex/model_selection/tests/test_model_selection.py,sha256=3kZIq8kba8SW93DBWXupoRymNStR1_mGGYSErQRnwME,1338
|
|
45
47
|
sklearnex/neighbors/__init__.py,sha256=_GMJ2L-6YechRYI2fOFwHjy0kebUncE81z4FmdXUlb8,1078
|
|
46
|
-
sklearnex/neighbors/_lof.py,sha256=
|
|
47
|
-
sklearnex/neighbors/common.py,sha256=
|
|
48
|
-
sklearnex/neighbors/knn_classification.py,sha256=
|
|
49
|
-
sklearnex/neighbors/knn_regression.py,sha256=
|
|
50
|
-
sklearnex/neighbors/knn_unsupervised.py,sha256=
|
|
48
|
+
sklearnex/neighbors/_lof.py,sha256=5MPkWIb6FS55Q8xWzgc22Ec_PsouuN94SPovt-vsBGE,8648
|
|
49
|
+
sklearnex/neighbors/common.py,sha256=8DxDoYtXtEM4RNoMCimpTVSDOOxUIJlNVOQvBXBhkd4,10875
|
|
50
|
+
sklearnex/neighbors/knn_classification.py,sha256=ONoBbtwb5xoVLcpg5COpRNu1ZBOQ2EDh03RzbWDy5yo,8537
|
|
51
|
+
sklearnex/neighbors/knn_regression.py,sha256=YBjvh6h56OaJHSZNGq8ZV8lsB-XpSWduEcVeHRuPorQ,6692
|
|
52
|
+
sklearnex/neighbors/knn_unsupervised.py,sha256=qkj-hSEq8QetYsWlofnik3PpFvo1iBUbIOhywo8wFWk,5362
|
|
51
53
|
sklearnex/neighbors/tests/test_neighbors.py,sha256=gcJeJwDoT7wvyvk423k9TDGTGfbXUSTQETUT-VYQ74U,3409
|
|
52
54
|
sklearnex/preview/__init__.py,sha256=OXC_k2kudA13rVesXb5ZlEC7_mKUS7uUra_BR-Tin30,780
|
|
53
55
|
sklearnex/preview/cluster/__init__.py,sha256=FONzOuTGAb5NwdfFhLco99P_VccRk9NBkDHU3EKuAIs,794
|
|
54
56
|
sklearnex/preview/cluster/_common.py,sha256=bgpzijxgyrAtdNCCHyCNsZ-N70KQYNwMuoCTNdUna6o,2718
|
|
55
|
-
sklearnex/preview/cluster/k_means.py,sha256=
|
|
57
|
+
sklearnex/preview/cluster/k_means.py,sha256=RdF9mwgvZ1xgyeLhCQA2WaPvPsS1ndktXXcaNj6S460,10464
|
|
56
58
|
sklearnex/preview/covariance/__init__.py,sha256=DPYTk8lwcVphtwU8J3CyUYH8Uz6Zr0Uz4S6nn-RY5iM,825
|
|
57
|
-
sklearnex/preview/covariance/covariance.py,sha256=
|
|
58
|
-
sklearnex/preview/covariance/tests/test_covariance.py,sha256=
|
|
59
|
+
sklearnex/preview/covariance/covariance.py,sha256=NjRTWLie7UbpfN16wGSxJSRHRhUnvTn03cPPc8PpPd8,5131
|
|
60
|
+
sklearnex/preview/covariance/tests/test_covariance.py,sha256=FOgvhJxFQo9sNG4Uo-ebuw3ZXJ9tSxdk8qKm0ZJzTdc,2487
|
|
59
61
|
sklearnex/spmd/__init__.py,sha256=ChQy2kEWlo4KGvs0RnbPoPEVhdgl8URV099B1rZtF5Y,889
|
|
60
62
|
sklearnex/spmd/basic_statistics/__init__.py,sha256=NA5RGlwcp27UEeCgz0ngzYYd3MAIRpxlTy86uhM2-RE,821
|
|
61
63
|
sklearnex/spmd/basic_statistics/basic_statistics.py,sha256=_dQ9mhVYxeuChATEpAmHpXDpgW3YvtK1qrG-kLr2MtI,886
|
|
@@ -74,25 +76,26 @@ sklearnex/spmd/linear_model/logistic_regression.py,sha256=q_HkfWcg0RgFbk2t9FeV0Z
|
|
|
74
76
|
sklearnex/spmd/neighbors/__init__.py,sha256=S16sH8N_18LN_8AgC_wGK5EDSNyuN-F-gI6GVlaiWVE,906
|
|
75
77
|
sklearnex/spmd/neighbors/neighbors.py,sha256=SiKAS_RVt34MUcGytBS5pHnI_5vFNxJn8jqt1MOhDh8,940
|
|
76
78
|
sklearnex/svm/__init__.py,sha256=f3e4ZFwZfx6MsXsn94VK1xVm6mWKT5XCiHczo6zNyAQ,1057
|
|
77
|
-
sklearnex/svm/_common.py,sha256=
|
|
78
|
-
sklearnex/svm/nusvc.py,sha256
|
|
79
|
-
sklearnex/svm/nusvr.py,sha256=
|
|
80
|
-
sklearnex/svm/svc.py,sha256=
|
|
81
|
-
sklearnex/svm/svr.py,sha256=
|
|
79
|
+
sklearnex/svm/_common.py,sha256=52csEWTYWEVgUVWUm3RjX1VD_5VyyawXBvc7lBBp5qY,7010
|
|
80
|
+
sklearnex/svm/nusvc.py,sha256=J4F_Tm9oYC-WK1Nf_CNqSnvuYEEZZ9xa3VY-x0G_2cw,9871
|
|
81
|
+
sklearnex/svm/nusvr.py,sha256=ZFBnQzMgD4aRSk3BRIxwKfwErVyDJnNoR7vrIMm5WLk,3655
|
|
82
|
+
sklearnex/svm/svc.py,sha256=u9wQ8dsvQvO4XP_3JSfYFBNJcuDyv3HVG5NY6jZqhZk,11125
|
|
83
|
+
sklearnex/svm/svr.py,sha256=ldNWehrU4vgqX_0T8splmBjPsQln7w_h8L4XNpIgP6A,3655
|
|
82
84
|
sklearnex/svm/tests/test_svm.py,sha256=Ru-aGNGCsRJts7SEEYbnKcVqUx-DqPyUtw-hEoMVpW8,4190
|
|
83
|
-
sklearnex/tests/_utils.py,sha256=
|
|
85
|
+
sklearnex/tests/_utils.py,sha256=hc3LxZDhlncONCGxqvWajQE7iVnSnt98Q9bem-KJDGI,5386
|
|
84
86
|
sklearnex/tests/test_config.py,sha256=SnSJjxAAysISDyC3bYKSJiRHStkB9X-yjLeF11LpRog,1372
|
|
85
87
|
sklearnex/tests/test_memory_usage.py,sha256=LwIuUgG7CUZ2kOk1XlxyaK7O3OlyoVwx40TgljaYs5Q,7327
|
|
86
88
|
sklearnex/tests/test_monkeypatch.py,sha256=_9s_4jFvbttOf8uCuBrS4rn_AzQdFlKyRlthnGacUcU,9669
|
|
87
|
-
sklearnex/tests/test_n_jobs_support.py,sha256=
|
|
89
|
+
sklearnex/tests/test_n_jobs_support.py,sha256=fNGlQz882qAJoJ56ymbID0hpIsO_7PHLmXxSew2JA_k,4124
|
|
88
90
|
sklearnex/tests/test_parallel.py,sha256=0zzlh2VJZWcHw5W4QSUthtAygOb6K0Bg1ekNsrdGJQE,1770
|
|
89
|
-
sklearnex/tests/test_patching.py,sha256=
|
|
91
|
+
sklearnex/tests/test_patching.py,sha256=Gc4MChHY6lVUFkm3sgPF4RDd1uOqHQFfh9ac60d4vfQ,14299
|
|
90
92
|
sklearnex/tests/test_run_to_run_stability_tests.py,sha256=4HDOeJruA1EDILbyQJtsHFmEXC0D1upSHuOT-KyTlEc,14008
|
|
91
|
-
sklearnex/utils/__init__.py,sha256=
|
|
93
|
+
sklearnex/utils/__init__.py,sha256=FFlM8zc2qnSdPYpLjSt4Ma_9FjC8qk8wXJa-5B8hCs0,898
|
|
94
|
+
sklearnex/utils/_namespace.py,sha256=lWzvzcObxq350A-Ms8JyTbaQStR8rgH4DgQYhWruHL4,3166
|
|
92
95
|
sklearnex/utils/parallel.py,sha256=VBcS-KUdyq7XpJUN6ygmNjyWtYLroghbvCxQ8nVU3YI,2085
|
|
93
96
|
sklearnex/utils/validation.py,sha256=fjfhQiKnBQnD7LCBlacMyvsrhGnlMLRXk5Q69uoZIP4,827
|
|
94
|
-
scikit_learn_intelex-2024.
|
|
95
|
-
scikit_learn_intelex-2024.
|
|
96
|
-
scikit_learn_intelex-2024.
|
|
97
|
-
scikit_learn_intelex-2024.
|
|
98
|
-
scikit_learn_intelex-2024.
|
|
97
|
+
scikit_learn_intelex-2024.4.0.dist-info/LICENSE.txt,sha256=7micbUpzQXphq9e_2oL7PpZcvoXzPuQHIDEXyKXC81s,10797
|
|
98
|
+
scikit_learn_intelex-2024.4.0.dist-info/METADATA,sha256=We3kZekomEyuXZpbrpq05hqphdjy8S5Q_geoj0Mb93c,12449
|
|
99
|
+
scikit_learn_intelex-2024.4.0.dist-info/WHEEL,sha256=rxMEw7jRW2YnjujGudhK0a-ZC6J_VMIRJJ7uhbmewD4,107
|
|
100
|
+
scikit_learn_intelex-2024.4.0.dist-info/top_level.txt,sha256=kzKChSWGJEYFmdj5PwE63HNuP_PVOhWfD32ytH9rL9Q,10
|
|
101
|
+
scikit_learn_intelex-2024.4.0.dist-info/RECORD,,
|
sklearnex/_device_offload.py
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import logging
|
|
18
18
|
import sys
|
|
19
|
+
from collections.abc import Iterable
|
|
19
20
|
from functools import wraps
|
|
20
21
|
|
|
21
22
|
import numpy as np
|
|
@@ -200,9 +201,35 @@ def _copy_to_usm(queue, array):
|
|
|
200
201
|
raise RuntimeError(
|
|
201
202
|
"dpctl need to be installed to work " "with __sycl_usm_array_interface__"
|
|
202
203
|
)
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
|
|
205
|
+
if hasattr(array, "__array__"):
|
|
206
|
+
|
|
207
|
+
try:
|
|
208
|
+
mem = MemoryUSMDevice(array.nbytes, queue=queue)
|
|
209
|
+
mem.copy_from_host(array.tobytes())
|
|
210
|
+
return usm_ndarray(array.shape, array.dtype, buffer=mem)
|
|
211
|
+
except ValueError as e:
|
|
212
|
+
# ValueError will raise if device does not support the dtype
|
|
213
|
+
# retry with float32 (needed for fp16 and fp64 support issues)
|
|
214
|
+
# try again as float32, if it is a float32 just raise the error.
|
|
215
|
+
if array.dtype == np.float32:
|
|
216
|
+
raise e
|
|
217
|
+
return _copy_to_usm(queue, array.astype(np.float32))
|
|
218
|
+
else:
|
|
219
|
+
if isinstance(array, Iterable):
|
|
220
|
+
array = [_copy_to_usm(queue, i) for i in array]
|
|
221
|
+
return array
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
if dpnp_available:
|
|
225
|
+
|
|
226
|
+
def _convert_to_dpnp(array):
|
|
227
|
+
if isinstance(array, usm_ndarray):
|
|
228
|
+
return dpnp.array(array, copy=False)
|
|
229
|
+
elif isinstance(array, Iterable):
|
|
230
|
+
for i in range(len(array)):
|
|
231
|
+
array[i] = _convert_to_dpnp(array[i])
|
|
232
|
+
return array
|
|
206
233
|
|
|
207
234
|
|
|
208
235
|
def wrap_output_data(func):
|
|
@@ -217,7 +244,7 @@ def wrap_output_data(func):
|
|
|
217
244
|
if usm_iface is not None:
|
|
218
245
|
result = _copy_to_usm(usm_iface["syclobj"], result)
|
|
219
246
|
if dpnp_available and isinstance(data[0], dpnp.ndarray):
|
|
220
|
-
result =
|
|
247
|
+
result = _convert_to_dpnp(result)
|
|
221
248
|
return result
|
|
222
249
|
|
|
223
250
|
return wrapper
|
|
@@ -15,5 +15,6 @@
|
|
|
15
15
|
# ==============================================================================
|
|
16
16
|
|
|
17
17
|
from .basic_statistics import BasicStatistics
|
|
18
|
+
from .incremental_basic_statistics import IncrementalBasicStatistics
|
|
18
19
|
|
|
19
|
-
__all__ = ["BasicStatistics"]
|
|
20
|
+
__all__ = ["BasicStatistics", "IncrementalBasicStatistics"]
|
|
@@ -0,0 +1,288 @@
|
|
|
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
|
+
import numpy as np
|
|
18
|
+
from sklearn.base import BaseEstimator
|
|
19
|
+
from sklearn.utils import check_array, gen_batches
|
|
20
|
+
from sklearn.utils.validation import _check_sample_weight
|
|
21
|
+
|
|
22
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
23
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
24
|
+
from onedal.basic_statistics import (
|
|
25
|
+
IncrementalBasicStatistics as onedal_IncrementalBasicStatistics,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
from .._device_offload import dispatch
|
|
29
|
+
from .._utils import PatchingConditionsChain
|
|
30
|
+
|
|
31
|
+
if sklearn_check_version("1.2"):
|
|
32
|
+
from sklearn.utils._param_validation import Interval, StrOptions
|
|
33
|
+
|
|
34
|
+
import numbers
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@control_n_jobs(decorated_methods=["partial_fit", "_onedal_finalize_fit"])
|
|
38
|
+
class IncrementalBasicStatistics(BaseEstimator):
|
|
39
|
+
"""
|
|
40
|
+
Incremental estimator for basic statistics.
|
|
41
|
+
Allows to compute basic statistics if data are splitted into batches.
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
result_options: string or list, default='all'
|
|
45
|
+
List of statistics to compute
|
|
46
|
+
|
|
47
|
+
batch_size : int, default=None
|
|
48
|
+
The number of samples to use for each batch. Only used when calling
|
|
49
|
+
``fit``. If ``batch_size`` is ``None``, then ``batch_size``
|
|
50
|
+
is inferred from the data and set to ``5 * n_features``, to provide a
|
|
51
|
+
balance between approximation accuracy and memory consumption.
|
|
52
|
+
|
|
53
|
+
Attributes (are existing only if corresponding result option exists)
|
|
54
|
+
----------
|
|
55
|
+
min : ndarray of shape (n_features,)
|
|
56
|
+
Minimum of each feature over all samples.
|
|
57
|
+
|
|
58
|
+
max : ndarray of shape (n_features,)
|
|
59
|
+
Maximum of each feature over all samples.
|
|
60
|
+
|
|
61
|
+
sum : ndarray of shape (n_features,)
|
|
62
|
+
Sum of each feature over all samples.
|
|
63
|
+
|
|
64
|
+
mean : ndarray of shape (n_features,)
|
|
65
|
+
Mean of each feature over all samples.
|
|
66
|
+
|
|
67
|
+
variance : ndarray of shape (n_features,)
|
|
68
|
+
Variance of each feature over all samples.
|
|
69
|
+
|
|
70
|
+
variation : ndarray of shape (n_features,)
|
|
71
|
+
Variation of each feature over all samples.
|
|
72
|
+
|
|
73
|
+
sum_squares : ndarray of shape (n_features,)
|
|
74
|
+
Sum of squares for each feature over all samples.
|
|
75
|
+
|
|
76
|
+
standard_deviation : ndarray of shape (n_features,)
|
|
77
|
+
Standard deviation of each feature over all samples.
|
|
78
|
+
|
|
79
|
+
sum_squares_centered : ndarray of shape (n_features,)
|
|
80
|
+
Centered sum of squares for each feature over all samples.
|
|
81
|
+
|
|
82
|
+
second_order_raw_moment : ndarray of shape (n_features,)
|
|
83
|
+
Second order moment of each feature over all samples.
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
_onedal_incremental_basic_statistics = staticmethod(onedal_IncrementalBasicStatistics)
|
|
87
|
+
|
|
88
|
+
if sklearn_check_version("1.2"):
|
|
89
|
+
_parameter_constraints: dict = {
|
|
90
|
+
"result_options": [
|
|
91
|
+
StrOptions(
|
|
92
|
+
{
|
|
93
|
+
"all",
|
|
94
|
+
"min",
|
|
95
|
+
"max",
|
|
96
|
+
"sum",
|
|
97
|
+
"mean",
|
|
98
|
+
"variance",
|
|
99
|
+
"variation",
|
|
100
|
+
"sum_squares",
|
|
101
|
+
"standard_deviation",
|
|
102
|
+
"sum_squares_centered",
|
|
103
|
+
"second_order_raw_moment",
|
|
104
|
+
}
|
|
105
|
+
),
|
|
106
|
+
list,
|
|
107
|
+
],
|
|
108
|
+
"batch_size": [Interval(numbers.Integral, 1, None, closed="left"), None],
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
def __init__(self, result_options="all", batch_size=None):
|
|
112
|
+
if result_options == "all":
|
|
113
|
+
self.result_options = (
|
|
114
|
+
self._onedal_incremental_basic_statistics.get_all_result_options()
|
|
115
|
+
)
|
|
116
|
+
else:
|
|
117
|
+
self.result_options = result_options
|
|
118
|
+
self._need_to_finalize = False
|
|
119
|
+
self.batch_size = batch_size
|
|
120
|
+
|
|
121
|
+
def _onedal_supported(self, method_name, *data):
|
|
122
|
+
patching_status = PatchingConditionsChain(
|
|
123
|
+
f"sklearn.covariance.{self.__class__.__name__}.{method_name}"
|
|
124
|
+
)
|
|
125
|
+
return patching_status
|
|
126
|
+
|
|
127
|
+
_onedal_cpu_supported = _onedal_supported
|
|
128
|
+
_onedal_gpu_supported = _onedal_supported
|
|
129
|
+
|
|
130
|
+
def _get_onedal_result_options(self, options):
|
|
131
|
+
if isinstance(options, list):
|
|
132
|
+
onedal_options = "|".join(self.result_options)
|
|
133
|
+
else:
|
|
134
|
+
onedal_options = options
|
|
135
|
+
assert isinstance(onedal_options, str)
|
|
136
|
+
return options
|
|
137
|
+
|
|
138
|
+
def _onedal_finalize_fit(self):
|
|
139
|
+
assert hasattr(self, "_onedal_estimator")
|
|
140
|
+
self._onedal_estimator.finalize_fit()
|
|
141
|
+
self._need_to_finalize = False
|
|
142
|
+
|
|
143
|
+
def _onedal_partial_fit(self, X, sample_weight=None, queue=None):
|
|
144
|
+
first_pass = not hasattr(self, "n_samples_seen_") or self.n_samples_seen_ == 0
|
|
145
|
+
|
|
146
|
+
if sklearn_check_version("1.0"):
|
|
147
|
+
X = self._validate_data(
|
|
148
|
+
X,
|
|
149
|
+
dtype=[np.float64, np.float32],
|
|
150
|
+
reset=first_pass,
|
|
151
|
+
)
|
|
152
|
+
else:
|
|
153
|
+
X = check_array(
|
|
154
|
+
X,
|
|
155
|
+
dtype=[np.float64, np.float32],
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
if sample_weight is not None:
|
|
159
|
+
sample_weight = _check_sample_weight(sample_weight, X)
|
|
160
|
+
|
|
161
|
+
if first_pass:
|
|
162
|
+
self.n_samples_seen_ = X.shape[0]
|
|
163
|
+
self.n_features_in_ = X.shape[1]
|
|
164
|
+
else:
|
|
165
|
+
self.n_samples_seen_ += X.shape[0]
|
|
166
|
+
|
|
167
|
+
onedal_params = {
|
|
168
|
+
"result_options": self._get_onedal_result_options(self.result_options)
|
|
169
|
+
}
|
|
170
|
+
if not hasattr(self, "_onedal_estimator"):
|
|
171
|
+
self._onedal_estimator = self._onedal_incremental_basic_statistics(
|
|
172
|
+
**onedal_params
|
|
173
|
+
)
|
|
174
|
+
self._onedal_estimator.partial_fit(X, sample_weight, queue)
|
|
175
|
+
self._need_to_finalize = True
|
|
176
|
+
|
|
177
|
+
def _onedal_fit(self, X, sample_weight=None, queue=None):
|
|
178
|
+
if sklearn_check_version("1.0"):
|
|
179
|
+
X = self._validate_data(X, dtype=[np.float64, np.float32])
|
|
180
|
+
else:
|
|
181
|
+
X = check_array(X, dtype=[np.float64, np.float32])
|
|
182
|
+
|
|
183
|
+
if sample_weight is not None:
|
|
184
|
+
sample_weight = _check_sample_weight(sample_weight, X)
|
|
185
|
+
|
|
186
|
+
n_samples, n_features = X.shape
|
|
187
|
+
if self.batch_size is None:
|
|
188
|
+
self.batch_size_ = 5 * n_features
|
|
189
|
+
else:
|
|
190
|
+
self.batch_size_ = self.batch_size
|
|
191
|
+
|
|
192
|
+
self.n_samples_seen_ = 0
|
|
193
|
+
if hasattr(self, "_onedal_estimator"):
|
|
194
|
+
self._onedal_estimator._reset()
|
|
195
|
+
|
|
196
|
+
for batch in gen_batches(X.shape[0], self.batch_size_):
|
|
197
|
+
X_batch = X[batch]
|
|
198
|
+
weights_batch = sample_weight[batch] if sample_weight is not None else None
|
|
199
|
+
self._onedal_partial_fit(X_batch, weights_batch, queue=queue)
|
|
200
|
+
|
|
201
|
+
if sklearn_check_version("1.2"):
|
|
202
|
+
self._validate_params()
|
|
203
|
+
|
|
204
|
+
self.n_features_in_ = X.shape[1]
|
|
205
|
+
|
|
206
|
+
self._onedal_finalize_fit()
|
|
207
|
+
|
|
208
|
+
return self
|
|
209
|
+
|
|
210
|
+
def __getattr__(self, attr):
|
|
211
|
+
result_options = self.__dict__["result_options"]
|
|
212
|
+
is_statistic_attr = (
|
|
213
|
+
isinstance(result_options, str) and (attr == result_options)
|
|
214
|
+
) or (isinstance(result_options, list) and (attr in result_options))
|
|
215
|
+
if is_statistic_attr:
|
|
216
|
+
if self._need_to_finalize:
|
|
217
|
+
self._onedal_finalize_fit()
|
|
218
|
+
return getattr(self._onedal_estimator, attr)
|
|
219
|
+
if attr in self.__dict__:
|
|
220
|
+
return self.__dict__[attr]
|
|
221
|
+
|
|
222
|
+
raise AttributeError(
|
|
223
|
+
f"'{self.__class__.__name__}' object has no attribute '{attr}'"
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
def partial_fit(self, X, sample_weight=None):
|
|
227
|
+
"""Incremental fit with X. All of X is processed as a single batch.
|
|
228
|
+
|
|
229
|
+
Parameters
|
|
230
|
+
----------
|
|
231
|
+
X : array-like of shape (n_samples, n_features)
|
|
232
|
+
Data for compute, where `n_samples` is the number of samples and
|
|
233
|
+
`n_features` is the number of features.
|
|
234
|
+
|
|
235
|
+
y : Ignored
|
|
236
|
+
Not used, present for API consistency by convention.
|
|
237
|
+
|
|
238
|
+
sample_weight : array-like of shape (n_samples,), default=None
|
|
239
|
+
Weights for compute weighted statistics, where `n_samples` is the number of samples.
|
|
240
|
+
|
|
241
|
+
Returns
|
|
242
|
+
-------
|
|
243
|
+
self : object
|
|
244
|
+
Returns the instance itself.
|
|
245
|
+
"""
|
|
246
|
+
dispatch(
|
|
247
|
+
self,
|
|
248
|
+
"partial_fit",
|
|
249
|
+
{
|
|
250
|
+
"onedal": self.__class__._onedal_partial_fit,
|
|
251
|
+
"sklearn": None,
|
|
252
|
+
},
|
|
253
|
+
X,
|
|
254
|
+
sample_weight,
|
|
255
|
+
)
|
|
256
|
+
return self
|
|
257
|
+
|
|
258
|
+
def fit(self, X, y=None, sample_weight=None):
|
|
259
|
+
"""Compute statistics with X, using minibatches of size batch_size.
|
|
260
|
+
|
|
261
|
+
Parameters
|
|
262
|
+
----------
|
|
263
|
+
X : array-like of shape (n_samples, n_features)
|
|
264
|
+
Data for compute, where `n_samples` is the number of samples and
|
|
265
|
+
`n_features` is the number of features.
|
|
266
|
+
|
|
267
|
+
y : Ignored
|
|
268
|
+
Not used, present for API consistency by convention.
|
|
269
|
+
|
|
270
|
+
sample_weight : array-like of shape (n_samples,), default=None
|
|
271
|
+
Weights for compute weighted statistics, where `n_samples` is the number of samples.
|
|
272
|
+
|
|
273
|
+
Returns
|
|
274
|
+
-------
|
|
275
|
+
self : object
|
|
276
|
+
Returns the instance itself.
|
|
277
|
+
"""
|
|
278
|
+
dispatch(
|
|
279
|
+
self,
|
|
280
|
+
"fit",
|
|
281
|
+
{
|
|
282
|
+
"onedal": self.__class__._onedal_fit,
|
|
283
|
+
"sklearn": None,
|
|
284
|
+
},
|
|
285
|
+
X,
|
|
286
|
+
sample_weight,
|
|
287
|
+
)
|
|
288
|
+
return self
|