scikit-learn-intelex 2024.3.0__py312-none-manylinux1_x86_64.whl → 2024.5.0__py312-none-manylinux1_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of scikit-learn-intelex might be problematic. Click here for more details.
- {scikit_learn_intelex-2024.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
|
@@ -0,0 +1,384 @@
|
|
|
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
|
+
import pytest
|
|
19
|
+
from numpy.testing import assert_allclose
|
|
20
|
+
|
|
21
|
+
from onedal.basic_statistics.tests.test_incremental_basic_statistics import (
|
|
22
|
+
expected_max,
|
|
23
|
+
expected_mean,
|
|
24
|
+
expected_sum,
|
|
25
|
+
options_and_tests,
|
|
26
|
+
)
|
|
27
|
+
from onedal.tests.utils._dataframes_support import (
|
|
28
|
+
_convert_to_dataframe,
|
|
29
|
+
get_dataframes_and_queues,
|
|
30
|
+
)
|
|
31
|
+
from sklearnex.basic_statistics import IncrementalBasicStatistics
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
35
|
+
@pytest.mark.parametrize("weighted", [True, False])
|
|
36
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
37
|
+
def test_partial_fit_multiple_options_on_gold_data(dataframe, queue, weighted, dtype):
|
|
38
|
+
X = np.array([[0, 0], [1, 1]])
|
|
39
|
+
X = X.astype(dtype=dtype)
|
|
40
|
+
X_split = np.array_split(X, 2)
|
|
41
|
+
if weighted:
|
|
42
|
+
weights = np.array([1, 0.5])
|
|
43
|
+
weights = weights.astype(dtype=dtype)
|
|
44
|
+
weights_split = np.array_split(weights, 2)
|
|
45
|
+
|
|
46
|
+
incbs = IncrementalBasicStatistics()
|
|
47
|
+
for i in range(2):
|
|
48
|
+
X_split_df = _convert_to_dataframe(
|
|
49
|
+
X_split[i], sycl_queue=queue, target_df=dataframe
|
|
50
|
+
)
|
|
51
|
+
if weighted:
|
|
52
|
+
weights_split_df = _convert_to_dataframe(
|
|
53
|
+
weights_split[i], sycl_queue=queue, target_df=dataframe
|
|
54
|
+
)
|
|
55
|
+
result = incbs.partial_fit(X_split_df, sample_weight=weights_split_df)
|
|
56
|
+
else:
|
|
57
|
+
result = incbs.partial_fit(X_split_df)
|
|
58
|
+
|
|
59
|
+
if weighted:
|
|
60
|
+
expected_weighted_mean = np.array([0.25, 0.25])
|
|
61
|
+
expected_weighted_min = np.array([0, 0])
|
|
62
|
+
expected_weighted_max = np.array([0.5, 0.5])
|
|
63
|
+
assert_allclose(expected_weighted_mean, result.mean)
|
|
64
|
+
assert_allclose(expected_weighted_max, result.max)
|
|
65
|
+
assert_allclose(expected_weighted_min, result.min)
|
|
66
|
+
else:
|
|
67
|
+
expected_mean = np.array([0.5, 0.5])
|
|
68
|
+
expected_min = np.array([0, 0])
|
|
69
|
+
expected_max = np.array([1, 1])
|
|
70
|
+
assert_allclose(expected_mean, result.mean)
|
|
71
|
+
assert_allclose(expected_max, result.max)
|
|
72
|
+
assert_allclose(expected_min, result.min)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
76
|
+
@pytest.mark.parametrize("num_batches", [2, 10])
|
|
77
|
+
@pytest.mark.parametrize("option", options_and_tests)
|
|
78
|
+
@pytest.mark.parametrize("row_count", [100, 1000])
|
|
79
|
+
@pytest.mark.parametrize("column_count", [10, 100])
|
|
80
|
+
@pytest.mark.parametrize("weighted", [True, False])
|
|
81
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
82
|
+
def test_partial_fit_single_option_on_random_data(
|
|
83
|
+
dataframe, queue, num_batches, option, row_count, column_count, weighted, dtype
|
|
84
|
+
):
|
|
85
|
+
result_option, function, tols = option
|
|
86
|
+
fp32tol, fp64tol = tols
|
|
87
|
+
seed = 77
|
|
88
|
+
gen = np.random.default_rng(seed)
|
|
89
|
+
X = gen.uniform(low=-0.3, high=+0.7, size=(row_count, column_count))
|
|
90
|
+
X = X.astype(dtype=dtype)
|
|
91
|
+
X_split = np.array_split(X, num_batches)
|
|
92
|
+
if weighted:
|
|
93
|
+
weights = gen.uniform(low=-0.5, high=+1.0, size=row_count)
|
|
94
|
+
weights = weights.astype(dtype=dtype)
|
|
95
|
+
weights_split = np.array_split(weights, num_batches)
|
|
96
|
+
incbs = IncrementalBasicStatistics(result_options=result_option)
|
|
97
|
+
|
|
98
|
+
for i in range(num_batches):
|
|
99
|
+
X_split_df = _convert_to_dataframe(
|
|
100
|
+
X_split[i], sycl_queue=queue, target_df=dataframe
|
|
101
|
+
)
|
|
102
|
+
if weighted:
|
|
103
|
+
weights_split_df = _convert_to_dataframe(
|
|
104
|
+
weights_split[i], sycl_queue=queue, target_df=dataframe
|
|
105
|
+
)
|
|
106
|
+
result = incbs.partial_fit(X_split_df, sample_weight=weights_split_df)
|
|
107
|
+
else:
|
|
108
|
+
result = incbs.partial_fit(X_split_df)
|
|
109
|
+
|
|
110
|
+
res = getattr(result, result_option)
|
|
111
|
+
if weighted:
|
|
112
|
+
weighted_data = np.diag(weights) @ X
|
|
113
|
+
gtr = function(weighted_data)
|
|
114
|
+
else:
|
|
115
|
+
gtr = function(X)
|
|
116
|
+
|
|
117
|
+
tol = fp32tol if res.dtype == np.float32 else fp64tol
|
|
118
|
+
assert_allclose(gtr, res, atol=tol)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
122
|
+
@pytest.mark.parametrize("num_batches", [2, 10])
|
|
123
|
+
@pytest.mark.parametrize("row_count", [100, 1000])
|
|
124
|
+
@pytest.mark.parametrize("column_count", [10, 100])
|
|
125
|
+
@pytest.mark.parametrize("weighted", [True, False])
|
|
126
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
127
|
+
def test_partial_fit_multiple_options_on_random_data(
|
|
128
|
+
dataframe, queue, num_batches, row_count, column_count, weighted, dtype
|
|
129
|
+
):
|
|
130
|
+
seed = 42
|
|
131
|
+
gen = np.random.default_rng(seed)
|
|
132
|
+
X = gen.uniform(low=-0.3, high=+0.7, size=(row_count, column_count))
|
|
133
|
+
X = X.astype(dtype=dtype)
|
|
134
|
+
X_split = np.array_split(X, num_batches)
|
|
135
|
+
if weighted:
|
|
136
|
+
weights = gen.uniform(low=-0.5, high=+1.0, size=row_count)
|
|
137
|
+
weights = weights.astype(dtype=dtype)
|
|
138
|
+
weights_split = np.array_split(weights, num_batches)
|
|
139
|
+
incbs = IncrementalBasicStatistics(result_options=["mean", "max", "sum"])
|
|
140
|
+
|
|
141
|
+
for i in range(num_batches):
|
|
142
|
+
X_split_df = _convert_to_dataframe(
|
|
143
|
+
X_split[i], sycl_queue=queue, target_df=dataframe
|
|
144
|
+
)
|
|
145
|
+
if weighted:
|
|
146
|
+
weights_split_df = _convert_to_dataframe(
|
|
147
|
+
weights_split[i], sycl_queue=queue, target_df=dataframe
|
|
148
|
+
)
|
|
149
|
+
result = incbs.partial_fit(X_split_df, sample_weight=weights_split_df)
|
|
150
|
+
else:
|
|
151
|
+
result = incbs.partial_fit(X_split_df)
|
|
152
|
+
|
|
153
|
+
res_mean, res_max, res_sum = result.mean, result.max, result.sum
|
|
154
|
+
if weighted:
|
|
155
|
+
weighted_data = np.diag(weights) @ X
|
|
156
|
+
gtr_mean, gtr_max, gtr_sum = (
|
|
157
|
+
expected_mean(weighted_data),
|
|
158
|
+
expected_max(weighted_data),
|
|
159
|
+
expected_sum(weighted_data),
|
|
160
|
+
)
|
|
161
|
+
else:
|
|
162
|
+
gtr_mean, gtr_max, gtr_sum = (
|
|
163
|
+
expected_mean(X),
|
|
164
|
+
expected_max(X),
|
|
165
|
+
expected_sum(X),
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
tol = 3e-4 if res_mean.dtype == np.float32 else 1e-7
|
|
169
|
+
assert_allclose(gtr_mean, res_mean, atol=tol)
|
|
170
|
+
assert_allclose(gtr_max, res_max, atol=tol)
|
|
171
|
+
assert_allclose(gtr_sum, res_sum, atol=tol)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
175
|
+
@pytest.mark.parametrize("num_batches", [2, 10])
|
|
176
|
+
@pytest.mark.parametrize("row_count", [100, 1000])
|
|
177
|
+
@pytest.mark.parametrize("column_count", [10, 100])
|
|
178
|
+
@pytest.mark.parametrize("weighted", [True, False])
|
|
179
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
180
|
+
def test_partial_fit_all_option_on_random_data(
|
|
181
|
+
dataframe, queue, num_batches, row_count, column_count, weighted, dtype
|
|
182
|
+
):
|
|
183
|
+
seed = 77
|
|
184
|
+
gen = np.random.default_rng(seed)
|
|
185
|
+
X = gen.uniform(low=-0.3, high=+0.7, size=(row_count, column_count))
|
|
186
|
+
X = X.astype(dtype=dtype)
|
|
187
|
+
X_split = np.array_split(X, num_batches)
|
|
188
|
+
if weighted:
|
|
189
|
+
weights = gen.uniform(low=-0.5, high=+1.0, size=row_count)
|
|
190
|
+
weights = weights.astype(dtype=dtype)
|
|
191
|
+
weights_split = np.array_split(weights, num_batches)
|
|
192
|
+
incbs = IncrementalBasicStatistics(result_options="all")
|
|
193
|
+
|
|
194
|
+
for i in range(num_batches):
|
|
195
|
+
X_split_df = _convert_to_dataframe(
|
|
196
|
+
X_split[i], sycl_queue=queue, target_df=dataframe
|
|
197
|
+
)
|
|
198
|
+
if weighted:
|
|
199
|
+
weights_split_df = _convert_to_dataframe(
|
|
200
|
+
weights_split[i], sycl_queue=queue, target_df=dataframe
|
|
201
|
+
)
|
|
202
|
+
result = incbs.partial_fit(X_split_df, sample_weight=weights_split_df)
|
|
203
|
+
else:
|
|
204
|
+
result = incbs.partial_fit(X_split_df)
|
|
205
|
+
|
|
206
|
+
if weighted:
|
|
207
|
+
weighted_data = np.diag(weights) @ X
|
|
208
|
+
|
|
209
|
+
for option in options_and_tests:
|
|
210
|
+
result_option, function, tols = option
|
|
211
|
+
fp32tol, fp64tol = tols
|
|
212
|
+
res = getattr(result, result_option)
|
|
213
|
+
if weighted:
|
|
214
|
+
gtr = function(weighted_data)
|
|
215
|
+
else:
|
|
216
|
+
gtr = function(X)
|
|
217
|
+
tol = fp32tol if res.dtype == np.float32 else fp64tol
|
|
218
|
+
assert_allclose(gtr, res, atol=tol)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
222
|
+
@pytest.mark.parametrize("weighted", [True, False])
|
|
223
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
224
|
+
def test_fit_multiple_options_on_gold_data(dataframe, queue, weighted, dtype):
|
|
225
|
+
X = np.array([[0, 0], [1, 1]])
|
|
226
|
+
X = X.astype(dtype=dtype)
|
|
227
|
+
X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
228
|
+
if weighted:
|
|
229
|
+
weights = np.array([1, 0.5])
|
|
230
|
+
weights = weights.astype(dtype=dtype)
|
|
231
|
+
weights_df = _convert_to_dataframe(weights, sycl_queue=queue, target_df=dataframe)
|
|
232
|
+
incbs = IncrementalBasicStatistics(batch_size=1)
|
|
233
|
+
|
|
234
|
+
if weighted:
|
|
235
|
+
result = incbs.fit(X_df, sample_weight=weights_df)
|
|
236
|
+
else:
|
|
237
|
+
result = incbs.fit(X_df)
|
|
238
|
+
|
|
239
|
+
if weighted:
|
|
240
|
+
expected_weighted_mean = np.array([0.25, 0.25])
|
|
241
|
+
expected_weighted_min = np.array([0, 0])
|
|
242
|
+
expected_weighted_max = np.array([0.5, 0.5])
|
|
243
|
+
assert_allclose(expected_weighted_mean, result.mean)
|
|
244
|
+
assert_allclose(expected_weighted_max, result.max)
|
|
245
|
+
assert_allclose(expected_weighted_min, result.min)
|
|
246
|
+
else:
|
|
247
|
+
expected_mean = np.array([0.5, 0.5])
|
|
248
|
+
expected_min = np.array([0, 0])
|
|
249
|
+
expected_max = np.array([1, 1])
|
|
250
|
+
assert_allclose(expected_mean, result.mean)
|
|
251
|
+
assert_allclose(expected_max, result.max)
|
|
252
|
+
assert_allclose(expected_min, result.min)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
256
|
+
@pytest.mark.parametrize("num_batches", [2, 10])
|
|
257
|
+
@pytest.mark.parametrize("option", options_and_tests)
|
|
258
|
+
@pytest.mark.parametrize("row_count", [100, 1000])
|
|
259
|
+
@pytest.mark.parametrize("column_count", [10, 100])
|
|
260
|
+
@pytest.mark.parametrize("weighted", [True, False])
|
|
261
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
262
|
+
def test_fit_single_option_on_random_data(
|
|
263
|
+
dataframe, queue, num_batches, option, row_count, column_count, weighted, dtype
|
|
264
|
+
):
|
|
265
|
+
result_option, function, tols = option
|
|
266
|
+
fp32tol, fp64tol = tols
|
|
267
|
+
seed = 77
|
|
268
|
+
gen = np.random.default_rng(seed)
|
|
269
|
+
batch_size = row_count // num_batches
|
|
270
|
+
X = gen.uniform(low=-0.3, high=+0.7, size=(row_count, column_count))
|
|
271
|
+
X = X.astype(dtype=dtype)
|
|
272
|
+
X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
273
|
+
if weighted:
|
|
274
|
+
weights = gen.uniform(low=-0.5, high=1.0, size=row_count)
|
|
275
|
+
weights = weights.astype(dtype=dtype)
|
|
276
|
+
weights_df = _convert_to_dataframe(weights, sycl_queue=queue, target_df=dataframe)
|
|
277
|
+
incbs = IncrementalBasicStatistics(
|
|
278
|
+
result_options=result_option, batch_size=batch_size
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
if weighted:
|
|
282
|
+
result = incbs.fit(X_df, sample_weight=weights_df)
|
|
283
|
+
else:
|
|
284
|
+
result = incbs.fit(X_df)
|
|
285
|
+
|
|
286
|
+
res = getattr(result, result_option)
|
|
287
|
+
if weighted:
|
|
288
|
+
weighted_data = np.diag(weights) @ X
|
|
289
|
+
gtr = function(weighted_data)
|
|
290
|
+
else:
|
|
291
|
+
gtr = function(X)
|
|
292
|
+
|
|
293
|
+
tol = fp32tol if res.dtype == np.float32 else fp64tol
|
|
294
|
+
assert_allclose(gtr, res, atol=tol)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
298
|
+
@pytest.mark.parametrize("num_batches", [2, 10])
|
|
299
|
+
@pytest.mark.parametrize("row_count", [100, 1000])
|
|
300
|
+
@pytest.mark.parametrize("column_count", [10, 100])
|
|
301
|
+
@pytest.mark.parametrize("weighted", [True, False])
|
|
302
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
303
|
+
def test_fit_multiple_options_on_random_data(
|
|
304
|
+
dataframe, queue, num_batches, row_count, column_count, weighted, dtype
|
|
305
|
+
):
|
|
306
|
+
seed = 77
|
|
307
|
+
gen = np.random.default_rng(seed)
|
|
308
|
+
batch_size = row_count // num_batches
|
|
309
|
+
X = gen.uniform(low=-0.3, high=+0.7, size=(row_count, column_count))
|
|
310
|
+
X = X.astype(dtype=dtype)
|
|
311
|
+
X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
312
|
+
if weighted:
|
|
313
|
+
weights = gen.uniform(low=-0.5, high=1.0, size=row_count)
|
|
314
|
+
weights = weights.astype(dtype=dtype)
|
|
315
|
+
weights_df = _convert_to_dataframe(weights, sycl_queue=queue, target_df=dataframe)
|
|
316
|
+
incbs = IncrementalBasicStatistics(
|
|
317
|
+
result_options=["mean", "max", "sum"], batch_size=batch_size
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
if weighted:
|
|
321
|
+
result = incbs.fit(X_df, sample_weight=weights_df)
|
|
322
|
+
else:
|
|
323
|
+
result = incbs.fit(X_df)
|
|
324
|
+
|
|
325
|
+
res_mean, res_max, res_sum = result.mean, result.max, result.sum
|
|
326
|
+
if weighted:
|
|
327
|
+
weighted_data = np.diag(weights) @ X
|
|
328
|
+
gtr_mean, gtr_max, gtr_sum = (
|
|
329
|
+
expected_mean(weighted_data),
|
|
330
|
+
expected_max(weighted_data),
|
|
331
|
+
expected_sum(weighted_data),
|
|
332
|
+
)
|
|
333
|
+
else:
|
|
334
|
+
gtr_mean, gtr_max, gtr_sum = (
|
|
335
|
+
expected_mean(X),
|
|
336
|
+
expected_max(X),
|
|
337
|
+
expected_sum(X),
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
tol = 3e-4 if res_mean.dtype == np.float32 else 1e-7
|
|
341
|
+
assert_allclose(gtr_mean, res_mean, atol=tol)
|
|
342
|
+
assert_allclose(gtr_max, res_max, atol=tol)
|
|
343
|
+
assert_allclose(gtr_sum, res_sum, atol=tol)
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
347
|
+
@pytest.mark.parametrize("num_batches", [2, 10])
|
|
348
|
+
@pytest.mark.parametrize("row_count", [100, 1000])
|
|
349
|
+
@pytest.mark.parametrize("column_count", [10, 100])
|
|
350
|
+
@pytest.mark.parametrize("weighted", [True, False])
|
|
351
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
352
|
+
def test_fit_all_option_on_random_data(
|
|
353
|
+
dataframe, queue, num_batches, row_count, column_count, weighted, dtype
|
|
354
|
+
):
|
|
355
|
+
seed = 77
|
|
356
|
+
gen = np.random.default_rng(seed)
|
|
357
|
+
batch_size = row_count // num_batches
|
|
358
|
+
X = gen.uniform(low=-0.3, high=+0.7, size=(row_count, column_count))
|
|
359
|
+
X = X.astype(dtype=dtype)
|
|
360
|
+
X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
361
|
+
if weighted:
|
|
362
|
+
weights = gen.uniform(low=-0.5, high=+1.0, size=row_count)
|
|
363
|
+
weights = weights.astype(dtype=dtype)
|
|
364
|
+
weights_df = _convert_to_dataframe(weights, sycl_queue=queue, target_df=dataframe)
|
|
365
|
+
incbs = IncrementalBasicStatistics(result_options="all", batch_size=batch_size)
|
|
366
|
+
|
|
367
|
+
if weighted:
|
|
368
|
+
result = incbs.fit(X_df, sample_weight=weights_df)
|
|
369
|
+
else:
|
|
370
|
+
result = incbs.fit(X_df)
|
|
371
|
+
|
|
372
|
+
if weighted:
|
|
373
|
+
weighted_data = np.diag(weights) @ X
|
|
374
|
+
|
|
375
|
+
for option in options_and_tests:
|
|
376
|
+
result_option, function, tols = option
|
|
377
|
+
fp32tol, fp64tol = tols
|
|
378
|
+
res = getattr(result, result_option)
|
|
379
|
+
if weighted:
|
|
380
|
+
gtr = function(weighted_data)
|
|
381
|
+
else:
|
|
382
|
+
gtr = function(X)
|
|
383
|
+
tol = fp32tol if res.dtype == np.float32 else fp64tol
|
|
384
|
+
assert_allclose(gtr, res, atol=tol)
|