scikit-learn-intelex 2024.6.0__py310-none-win_amd64.whl → 2024.7.0__py310-none-win_amd64.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.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/_config.py +3 -15
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/_device_offload.py +98 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/basic_statistics/basic_statistics.py +143 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/basic_statistics/tests/test_basic_statistics.py +251 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +1 -1
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/cluster/dbscan.py +0 -1
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/cluster/k_means.py +8 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/cluster/tests/test_kmeans.py +15 -3
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/covariance/incremental_covariance.py +64 -13
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/covariance/tests/test_incremental_covariance.py +35 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/decomposition/pca.py +25 -1
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/dispatcher.py +94 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/ensemble/_forest.py +8 -35
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/ensemble/tests/test_forest.py +9 -12
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/coordinate_descent.py +13 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/linear.py +2 -34
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/logistic_regression.py +79 -59
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/ridge.py +7 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/tests/test_linear.py +28 -3
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/tests/test_logreg.py +45 -3
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/manifold/t_sne.py +21 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/metrics/pairwise.py +5 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/metrics/ranking.py +3 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/model_selection/split.py +3 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/_lof.py +9 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/common.py +45 -1
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_classification.py +1 -20
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_regression.py +1 -20
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_unsupervised.py +31 -7
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/__init__.py +1 -1
- scikit_learn_intelex-2024.6.0.data/data/Lib/site-packages/sklearnex/manifold/t_sne.py → scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/preview/linear_model/__init__.py +19 -17
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/preview/linear_model/ridge.py +419 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/preview/linear_model/tests/test_ridge.py +102 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py +107 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/spmd/cluster/tests/test_dbscan_spmd.py +97 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/spmd/cluster/tests/test_kmeans_spmd.py +172 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/spmd/covariance/tests/test_covariance_spmd.py +107 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/spmd/decomposition/tests/test_pca_spmd.py +128 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/spmd/ensemble/tests/test_forest_spmd.py +265 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py +145 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py +163 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py +288 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/_common.py +19 -21
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/tests/test_svm.py +12 -20
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/_utils.py +143 -20
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/tests/_utils_spmd.py +185 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_config.py +4 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_monkeypatch.py +12 -4
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_patching.py +16 -13
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_run_to_run_stability.py +21 -9
- {scikit_learn_intelex-2024.6.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/METADATA +2 -2
- scikit_learn_intelex-2024.7.0.dist-info/RECORD +122 -0
- scikit_learn_intelex-2024.6.0.data/data/Lib/site-packages/sklearnex/_device_offload.py +0 -257
- scikit_learn_intelex-2024.6.0.data/data/Lib/site-packages/sklearnex/basic_statistics/basic_statistics.py +0 -17
- scikit_learn_intelex-2024.6.0.dist-info/RECORD +0 -108
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/__main__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/_utils.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/basic_statistics/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/basic_statistics/incremental_basic_statistics.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/cluster/tests/test_dbscan.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/conftest.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/covariance/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/decomposition/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/decomposition/tests/test_pca.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/doc/third-party-programs.txt +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/ensemble/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/glob/__main__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/glob/dispatcher.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/incremental_linear.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/logistic_path.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/tests/test_incremental_linear.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/manifold/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/manifold/tests/test_tsne.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/metrics/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/metrics/tests/test_metrics.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/model_selection/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/model_selection/tests/test_model_selection.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/tests/test_neighbors.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/_common.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/k_means.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/covariance.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/tests/test_covariance.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/decomposition/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/decomposition/incremental_pca.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/decomposition/tests/test_incremental_pca.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/basic_statistics/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/basic_statistics/basic_statistics.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/dbscan.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/kmeans.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/covariance/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/covariance/covariance.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/decomposition/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/decomposition/pca.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/ensemble/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/ensemble/forest.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/linear_model/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/linear_model/linear_model.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/linear_model/logistic_regression.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/neighbors/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/neighbors/neighbors.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/nusvc.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/nusvr.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/svc.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/svr.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_common.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_memory_usage.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_n_jobs_support.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_parallel.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/utils/__init__.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/utils/_namespace.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/utils/parallel.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/utils/tests/test_finite.py +0 -0
- {scikit_learn_intelex-2024.6.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/utils/validation.py +0 -0
- {scikit_learn_intelex-2024.6.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.6.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/WHEEL +0 -0
- {scikit_learn_intelex-2024.6.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/top_level.txt +0 -0
|
@@ -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
|
+
import pytest
|
|
19
|
+
from numpy.testing import assert_allclose
|
|
20
|
+
|
|
21
|
+
from onedal.tests.utils._dataframes_support import (
|
|
22
|
+
_convert_to_dataframe,
|
|
23
|
+
get_dataframes_and_queues,
|
|
24
|
+
)
|
|
25
|
+
from sklearnex.tests._utils_spmd import (
|
|
26
|
+
_assert_unordered_allclose,
|
|
27
|
+
_generate_classification_data,
|
|
28
|
+
_generate_regression_data,
|
|
29
|
+
_get_local_tensor,
|
|
30
|
+
_mpi_libs_and_gpu_available,
|
|
31
|
+
_spmd_assert_allclose,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.skipif(
|
|
36
|
+
not _mpi_libs_and_gpu_available,
|
|
37
|
+
reason="GPU device and MPI libs required for test",
|
|
38
|
+
)
|
|
39
|
+
@pytest.mark.parametrize(
|
|
40
|
+
"dataframe,queue",
|
|
41
|
+
get_dataframes_and_queues(dataframe_filter_="dpnp,dpctl", device_filter_="gpu"),
|
|
42
|
+
)
|
|
43
|
+
@pytest.mark.mpi
|
|
44
|
+
def test_knncls_spmd_gold(dataframe, queue):
|
|
45
|
+
# Import spmd and batch algo
|
|
46
|
+
from sklearnex.neighbors import KNeighborsClassifier as KNeighborsClassifier_Batch
|
|
47
|
+
from sklearnex.spmd.neighbors import KNeighborsClassifier as KNeighborsClassifier_SPMD
|
|
48
|
+
|
|
49
|
+
# Create gold data and convert to dataframe
|
|
50
|
+
X_train = np.array(
|
|
51
|
+
[
|
|
52
|
+
[0.0, 0.0],
|
|
53
|
+
[0.0, 1.0],
|
|
54
|
+
[1.0, 0.0],
|
|
55
|
+
[0.0, 2.0],
|
|
56
|
+
[2.0, 0.0],
|
|
57
|
+
[0.9, 1.0],
|
|
58
|
+
[0.0, -1.0],
|
|
59
|
+
[-1.0, 0.0],
|
|
60
|
+
[-1.0, -1.0],
|
|
61
|
+
]
|
|
62
|
+
)
|
|
63
|
+
# TODO: handle situations where not all classes are present on all ranks?
|
|
64
|
+
y_train = np.array([0, 1, 0, 1, 0, 1, 0, 1, 0])
|
|
65
|
+
X_test = np.array(
|
|
66
|
+
[
|
|
67
|
+
[1.0, -0.5],
|
|
68
|
+
[-5.0, 1.0],
|
|
69
|
+
[0.0, 1.0],
|
|
70
|
+
[10.0, -10.0],
|
|
71
|
+
]
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
local_dpt_X_train = _convert_to_dataframe(
|
|
75
|
+
_get_local_tensor(X_train), sycl_queue=queue, target_df=dataframe
|
|
76
|
+
)
|
|
77
|
+
local_dpt_y_train = _convert_to_dataframe(
|
|
78
|
+
_get_local_tensor(y_train), sycl_queue=queue, target_df=dataframe
|
|
79
|
+
)
|
|
80
|
+
local_dpt_X_test = _convert_to_dataframe(
|
|
81
|
+
_get_local_tensor(X_test), sycl_queue=queue, target_df=dataframe
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# Ensure predictions of batch algo match spmd
|
|
85
|
+
spmd_model = KNeighborsClassifier_SPMD(n_neighbors=1, algorithm="brute").fit(
|
|
86
|
+
local_dpt_X_train, local_dpt_y_train
|
|
87
|
+
)
|
|
88
|
+
batch_model = KNeighborsClassifier_Batch(n_neighbors=1, algorithm="brute").fit(
|
|
89
|
+
X_train, y_train
|
|
90
|
+
)
|
|
91
|
+
spmd_dists, spmd_indcs = spmd_model.kneighbors(local_dpt_X_test)
|
|
92
|
+
batch_dists, batch_indcs = batch_model.kneighbors(X_test)
|
|
93
|
+
spmd_result = spmd_model.predict(local_dpt_X_test)
|
|
94
|
+
batch_result = batch_model.predict(X_test)
|
|
95
|
+
|
|
96
|
+
_assert_unordered_allclose(spmd_indcs, batch_indcs, localize=True)
|
|
97
|
+
_assert_unordered_allclose(spmd_dists, batch_dists, localize=True)
|
|
98
|
+
_spmd_assert_allclose(spmd_result, batch_result)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@pytest.mark.skipif(
|
|
102
|
+
not _mpi_libs_and_gpu_available,
|
|
103
|
+
reason="GPU device and MPI libs required for test",
|
|
104
|
+
)
|
|
105
|
+
@pytest.mark.parametrize("n_samples", [200, 10000])
|
|
106
|
+
@pytest.mark.parametrize("n_features_and_classes", [(5, 2), (25, 2), (25, 10)])
|
|
107
|
+
@pytest.mark.parametrize("n_neighbors", [1, 5, 20])
|
|
108
|
+
@pytest.mark.parametrize("weights", ["uniform", "distance"])
|
|
109
|
+
@pytest.mark.parametrize(
|
|
110
|
+
"dataframe,queue",
|
|
111
|
+
get_dataframes_and_queues(dataframe_filter_="dpnp,dpctl", device_filter_="gpu"),
|
|
112
|
+
)
|
|
113
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
114
|
+
@pytest.mark.mpi
|
|
115
|
+
def test_knncls_spmd_synthetic(
|
|
116
|
+
n_samples,
|
|
117
|
+
n_features_and_classes,
|
|
118
|
+
n_neighbors,
|
|
119
|
+
weights,
|
|
120
|
+
dataframe,
|
|
121
|
+
queue,
|
|
122
|
+
dtype,
|
|
123
|
+
metric="euclidean",
|
|
124
|
+
):
|
|
125
|
+
n_features, n_classes = n_features_and_classes
|
|
126
|
+
# Import spmd and batch algo
|
|
127
|
+
from sklearnex.neighbors import KNeighborsClassifier as KNeighborsClassifier_Batch
|
|
128
|
+
from sklearnex.spmd.neighbors import KNeighborsClassifier as KNeighborsClassifier_SPMD
|
|
129
|
+
|
|
130
|
+
# Generate data and convert to dataframe
|
|
131
|
+
X_train, X_test, y_train, _ = _generate_classification_data(
|
|
132
|
+
n_samples, n_features, n_classes, dtype=dtype
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
local_dpt_X_train = _convert_to_dataframe(
|
|
136
|
+
_get_local_tensor(X_train), sycl_queue=queue, target_df=dataframe
|
|
137
|
+
)
|
|
138
|
+
local_dpt_y_train = _convert_to_dataframe(
|
|
139
|
+
_get_local_tensor(y_train), sycl_queue=queue, target_df=dataframe
|
|
140
|
+
)
|
|
141
|
+
local_dpt_X_test = _convert_to_dataframe(
|
|
142
|
+
_get_local_tensor(X_test), sycl_queue=queue, target_df=dataframe
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
# Ensure predictions of batch algo match spmd
|
|
146
|
+
spmd_model = KNeighborsClassifier_SPMD(
|
|
147
|
+
n_neighbors=n_neighbors, weights=weights, metric=metric, algorithm="brute"
|
|
148
|
+
).fit(local_dpt_X_train, local_dpt_y_train)
|
|
149
|
+
batch_model = KNeighborsClassifier_Batch(
|
|
150
|
+
n_neighbors=n_neighbors, weights=weights, metric=metric, algorithm="brute"
|
|
151
|
+
).fit(X_train, y_train)
|
|
152
|
+
spmd_dists, spmd_indcs = spmd_model.kneighbors(local_dpt_X_test)
|
|
153
|
+
batch_dists, batch_indcs = batch_model.kneighbors(X_test)
|
|
154
|
+
spmd_result = spmd_model.predict(local_dpt_X_test)
|
|
155
|
+
batch_result = batch_model.predict(X_test)
|
|
156
|
+
|
|
157
|
+
tol = 1e-4
|
|
158
|
+
if dtype == np.float64:
|
|
159
|
+
_assert_unordered_allclose(spmd_indcs, batch_indcs, localize=True)
|
|
160
|
+
_assert_unordered_allclose(
|
|
161
|
+
spmd_dists, batch_dists, localize=True, rtol=tol, atol=tol
|
|
162
|
+
)
|
|
163
|
+
_spmd_assert_allclose(spmd_result, batch_result)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@pytest.mark.skipif(
|
|
167
|
+
not _mpi_libs_and_gpu_available,
|
|
168
|
+
reason="GPU device and MPI libs required for test",
|
|
169
|
+
)
|
|
170
|
+
@pytest.mark.parametrize(
|
|
171
|
+
"dataframe,queue",
|
|
172
|
+
get_dataframes_and_queues(dataframe_filter_="dpnp,dpctl", device_filter_="gpu"),
|
|
173
|
+
)
|
|
174
|
+
@pytest.mark.mpi
|
|
175
|
+
def test_knnreg_spmd_gold(dataframe, queue):
|
|
176
|
+
# Import spmd and batch algo
|
|
177
|
+
from sklearnex.neighbors import KNeighborsRegressor as KNeighborsRegressor_Batch
|
|
178
|
+
from sklearnex.spmd.neighbors import KNeighborsRegressor as KNeighborsRegressor_SPMD
|
|
179
|
+
|
|
180
|
+
# Create gold data and convert to dataframe
|
|
181
|
+
X_train = np.array(
|
|
182
|
+
[
|
|
183
|
+
[0.0, 0.0],
|
|
184
|
+
[0.0, 1.0],
|
|
185
|
+
[1.0, 0.0],
|
|
186
|
+
[0.0, 2.0],
|
|
187
|
+
[2.0, 0.0],
|
|
188
|
+
[1.0, 1.0],
|
|
189
|
+
[0.0, -1.0],
|
|
190
|
+
[-1.0, 0.0],
|
|
191
|
+
[-1.0, -1.0],
|
|
192
|
+
]
|
|
193
|
+
)
|
|
194
|
+
y_train = np.array([3.0, 5.0, 4.0, 7.0, 5.0, 6.0, 1.0, 2.0, 0.0])
|
|
195
|
+
X_test = np.array(
|
|
196
|
+
[
|
|
197
|
+
[1.0, -0.5],
|
|
198
|
+
[-5.0, 1.0],
|
|
199
|
+
[0.0, 1.0],
|
|
200
|
+
[10.0, -10.0],
|
|
201
|
+
]
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
local_dpt_X_train = _convert_to_dataframe(
|
|
205
|
+
_get_local_tensor(X_train), sycl_queue=queue, target_df=dataframe
|
|
206
|
+
)
|
|
207
|
+
local_dpt_y_train = _convert_to_dataframe(
|
|
208
|
+
_get_local_tensor(y_train), sycl_queue=queue, target_df=dataframe
|
|
209
|
+
)
|
|
210
|
+
local_dpt_X_test = _convert_to_dataframe(
|
|
211
|
+
_get_local_tensor(X_test), sycl_queue=queue, target_df=dataframe
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
# Ensure predictions of batch algo match spmd
|
|
215
|
+
spmd_model = KNeighborsRegressor_SPMD(n_neighbors=1, algorithm="brute").fit(
|
|
216
|
+
local_dpt_X_train, local_dpt_y_train
|
|
217
|
+
)
|
|
218
|
+
batch_model = KNeighborsRegressor_Batch(n_neighbors=1, algorithm="brute").fit(
|
|
219
|
+
X_train, y_train
|
|
220
|
+
)
|
|
221
|
+
spmd_dists, spmd_indcs = spmd_model.kneighbors(local_dpt_X_test)
|
|
222
|
+
batch_dists, batch_indcs = batch_model.kneighbors(X_test)
|
|
223
|
+
spmd_result = spmd_model.predict(local_dpt_X_test)
|
|
224
|
+
batch_result = batch_model.predict(X_test)
|
|
225
|
+
|
|
226
|
+
_assert_unordered_allclose(spmd_indcs, batch_indcs, localize=True)
|
|
227
|
+
_assert_unordered_allclose(spmd_dists, batch_dists, localize=True)
|
|
228
|
+
_spmd_assert_allclose(spmd_result, batch_result)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@pytest.mark.skipif(
|
|
232
|
+
not _mpi_libs_and_gpu_available,
|
|
233
|
+
reason="GPU device and MPI libs required for test",
|
|
234
|
+
)
|
|
235
|
+
@pytest.mark.parametrize("n_samples", [200, 10000])
|
|
236
|
+
@pytest.mark.parametrize("n_features", [5, 25])
|
|
237
|
+
@pytest.mark.parametrize("n_neighbors", [1, 5, 20])
|
|
238
|
+
@pytest.mark.parametrize("weights", ["uniform", "distance"])
|
|
239
|
+
@pytest.mark.parametrize(
|
|
240
|
+
"metric", ["euclidean", "manhattan", "minkowski", "chebyshev", "cosine"]
|
|
241
|
+
)
|
|
242
|
+
@pytest.mark.parametrize(
|
|
243
|
+
"dataframe,queue",
|
|
244
|
+
get_dataframes_and_queues(dataframe_filter_="dpnp,dpctl", device_filter_="gpu"),
|
|
245
|
+
)
|
|
246
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
247
|
+
@pytest.mark.mpi
|
|
248
|
+
def test_knnreg_spmd_synthetic(
|
|
249
|
+
n_samples, n_features, n_neighbors, weights, metric, dataframe, queue, dtype
|
|
250
|
+
):
|
|
251
|
+
# Import spmd and batch algo
|
|
252
|
+
from sklearnex.neighbors import KNeighborsRegressor as KNeighborsRegressor_Batch
|
|
253
|
+
from sklearnex.spmd.neighbors import KNeighborsRegressor as KNeighborsRegressor_SPMD
|
|
254
|
+
|
|
255
|
+
# Generate data and convert to dataframe
|
|
256
|
+
X_train, X_test, y_train, _ = _generate_regression_data(
|
|
257
|
+
n_samples, n_features, dtype=dtype
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
local_dpt_X_train = _convert_to_dataframe(
|
|
261
|
+
_get_local_tensor(X_train), sycl_queue=queue, target_df=dataframe
|
|
262
|
+
)
|
|
263
|
+
local_dpt_y_train = _convert_to_dataframe(
|
|
264
|
+
_get_local_tensor(y_train), sycl_queue=queue, target_df=dataframe
|
|
265
|
+
)
|
|
266
|
+
local_dpt_X_test = _convert_to_dataframe(
|
|
267
|
+
_get_local_tensor(X_test), sycl_queue=queue, target_df=dataframe
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
# Ensure predictions of batch algo match spmd
|
|
271
|
+
spmd_model = KNeighborsRegressor_SPMD(
|
|
272
|
+
n_neighbors=n_neighbors, weights=weights, metric=metric, algorithm="brute"
|
|
273
|
+
).fit(local_dpt_X_train, local_dpt_y_train)
|
|
274
|
+
batch_model = KNeighborsRegressor_Batch(
|
|
275
|
+
n_neighbors=n_neighbors, weights=weights, metric=metric, algorithm="brute"
|
|
276
|
+
).fit(X_train, y_train)
|
|
277
|
+
spmd_dists, spmd_indcs = spmd_model.kneighbors(local_dpt_X_test)
|
|
278
|
+
batch_dists, batch_indcs = batch_model.kneighbors(X_test)
|
|
279
|
+
spmd_result = spmd_model.predict(local_dpt_X_test)
|
|
280
|
+
batch_result = batch_model.predict(X_test)
|
|
281
|
+
|
|
282
|
+
tol = 0.005 if dtype == np.float32 else 1e-4
|
|
283
|
+
if dtype == np.float64:
|
|
284
|
+
_assert_unordered_allclose(spmd_indcs, batch_indcs, localize=True)
|
|
285
|
+
_assert_unordered_allclose(
|
|
286
|
+
spmd_dists, batch_dists, localize=True, rtol=tol, atol=tol
|
|
287
|
+
)
|
|
288
|
+
_spmd_assert_allclose(spmd_result, batch_result, rtol=tol, atol=tol)
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
# ==============================================================================
|
|
16
16
|
|
|
17
|
+
import warnings
|
|
17
18
|
from abc import ABC
|
|
18
19
|
from numbers import Number, Real
|
|
19
20
|
|
|
@@ -22,7 +23,6 @@ from scipy import sparse as sp
|
|
|
22
23
|
from sklearn.base import BaseEstimator, ClassifierMixin
|
|
23
24
|
from sklearn.calibration import CalibratedClassifierCV
|
|
24
25
|
from sklearn.metrics import r2_score
|
|
25
|
-
from sklearn.model_selection import StratifiedKFold
|
|
26
26
|
from sklearn.preprocessing import LabelEncoder
|
|
27
27
|
|
|
28
28
|
from daal4py.sklearn._utils import sklearn_check_version
|
|
@@ -230,6 +230,17 @@ class BaseSVC(BaseSVM):
|
|
|
230
230
|
return recip_freq[le.transform(classes)]
|
|
231
231
|
|
|
232
232
|
def _fit_proba(self, X, y, sample_weight=None, queue=None):
|
|
233
|
+
# TODO: rewrite this method when probabilities output is implemented in oneDAL
|
|
234
|
+
|
|
235
|
+
# LibSVM uses the random seed to control cross-validation for probability generation
|
|
236
|
+
# CalibratedClassifierCV with "prefit" does not use an RNG nor a seed. This may
|
|
237
|
+
# impact users without their knowledge, so display a warning.
|
|
238
|
+
if self.random_state is not None:
|
|
239
|
+
warnings.warn(
|
|
240
|
+
"random_state does not influence oneDAL SVM results",
|
|
241
|
+
RuntimeWarning,
|
|
242
|
+
)
|
|
243
|
+
|
|
233
244
|
params = self.get_params()
|
|
234
245
|
params["probability"] = False
|
|
235
246
|
params["decision_function_shape"] = "ovr"
|
|
@@ -240,26 +251,13 @@ class BaseSVC(BaseSVM):
|
|
|
240
251
|
cfg = get_config()
|
|
241
252
|
cfg["target_offload"] = queue
|
|
242
253
|
with config_context(**cfg):
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
clf_base,
|
|
251
|
-
ensemble=False,
|
|
252
|
-
cv=cv,
|
|
253
|
-
method="sigmoid",
|
|
254
|
-
)
|
|
255
|
-
self.clf_prob.fit(X, y, sample_weight)
|
|
256
|
-
|
|
257
|
-
except ValueError:
|
|
258
|
-
clf_base = clf_base.fit(X, y, sample_weight)
|
|
259
|
-
self.clf_prob = CalibratedClassifierCV(
|
|
260
|
-
clf_base, cv="prefit", method="sigmoid"
|
|
261
|
-
)
|
|
262
|
-
self.clf_prob.fit(X, y, sample_weight)
|
|
254
|
+
clf_base.fit(X, y)
|
|
255
|
+
self.clf_prob = CalibratedClassifierCV(
|
|
256
|
+
clf_base,
|
|
257
|
+
ensemble=False,
|
|
258
|
+
cv="prefit",
|
|
259
|
+
method="sigmoid",
|
|
260
|
+
).fit(X, y)
|
|
263
261
|
|
|
264
262
|
def _save_attributes(self):
|
|
265
263
|
self.support_vectors_ = self._onedal_estimator.support_vectors_
|
|
@@ -25,12 +25,10 @@ from onedal.tests.utils._dataframes_support import (
|
|
|
25
25
|
)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
# investigate failure for `dpnp.ndarrays` and `dpctl.tensors` on `GPU`
|
|
30
|
-
@pytest.mark.parametrize(
|
|
31
|
-
"dataframe,queue", get_dataframes_and_queues(device_filter_="cpu")
|
|
32
|
-
)
|
|
28
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
33
29
|
def test_sklearnex_import_svc(dataframe, queue):
|
|
30
|
+
if queue and queue.sycl_device.is_gpu:
|
|
31
|
+
pytest.skip("SVC fit for the GPU sycl_queue is buggy.")
|
|
34
32
|
from sklearnex.svm import SVC
|
|
35
33
|
|
|
36
34
|
X = np.array([[-2, -1], [-1, -1], [-1, -2], [+1, +1], [+1, +2], [+2, +1]])
|
|
@@ -43,12 +41,10 @@ def test_sklearnex_import_svc(dataframe, queue):
|
|
|
43
41
|
assert_allclose(_as_numpy(svc.support_), [1, 3])
|
|
44
42
|
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
# investigate failure for `dpnp.ndarrays` and `dpctl.tensors` on `GPU`
|
|
48
|
-
@pytest.mark.parametrize(
|
|
49
|
-
"dataframe,queue", get_dataframes_and_queues(device_filter_="cpu")
|
|
50
|
-
)
|
|
44
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
51
45
|
def test_sklearnex_import_nusvc(dataframe, queue):
|
|
46
|
+
if queue and queue.sycl_device.is_gpu:
|
|
47
|
+
pytest.skip("NuSVC fit for the GPU sycl_queue is buggy.")
|
|
52
48
|
from sklearnex.svm import NuSVC
|
|
53
49
|
|
|
54
50
|
X = np.array([[-2, -1], [-1, -1], [-1, -2], [+1, +1], [+1, +2], [+2, +1]])
|
|
@@ -63,12 +59,10 @@ def test_sklearnex_import_nusvc(dataframe, queue):
|
|
|
63
59
|
assert_allclose(_as_numpy(svc.support_), [0, 1, 3, 4])
|
|
64
60
|
|
|
65
61
|
|
|
66
|
-
|
|
67
|
-
# investigate failure for `dpnp.ndarrays` and `dpctl.tensors` on `GPU`
|
|
68
|
-
@pytest.mark.parametrize(
|
|
69
|
-
"dataframe,queue", get_dataframes_and_queues(device_filter_="cpu")
|
|
70
|
-
)
|
|
62
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
71
63
|
def test_sklearnex_import_svr(dataframe, queue):
|
|
64
|
+
if queue and queue.sycl_device.is_gpu:
|
|
65
|
+
pytest.skip("SVR fit for the GPU sycl_queue is buggy.")
|
|
72
66
|
from sklearnex.svm import SVR
|
|
73
67
|
|
|
74
68
|
X = np.array([[-2, -1], [-1, -1], [-1, -2], [+1, +1], [+1, +2], [+2, +1]])
|
|
@@ -81,12 +75,10 @@ def test_sklearnex_import_svr(dataframe, queue):
|
|
|
81
75
|
assert_allclose(_as_numpy(svc.support_), [1, 3])
|
|
82
76
|
|
|
83
77
|
|
|
84
|
-
|
|
85
|
-
# investigate failure for `dpnp.ndarrays` and `dpctl.tensors` on `GPU`
|
|
86
|
-
@pytest.mark.parametrize(
|
|
87
|
-
"dataframe,queue", get_dataframes_and_queues(device_filter_="cpu")
|
|
88
|
-
)
|
|
78
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
89
79
|
def test_sklearnex_import_nusvr(dataframe, queue):
|
|
80
|
+
if queue and queue.sycl_device.is_gpu:
|
|
81
|
+
pytest.skip("NuSVR fit for the GPU sycl_queue is buggy.")
|
|
90
82
|
from sklearnex.svm import NuSVR
|
|
91
83
|
|
|
92
84
|
X = np.array([[-2, -1], [-1, -1], [-1, -2], [+1, +1], [+1, +2], [+2, +1]])
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
# ==============================================================================
|
|
16
16
|
|
|
17
17
|
from functools import partial
|
|
18
|
-
from inspect import isclass
|
|
18
|
+
from inspect import getattr_static, isclass, signature
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
from scipy import sparse as sp
|
|
@@ -44,6 +44,22 @@ from sklearnex.svm import SVC, NuSVC
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
def _load_all_models(with_sklearnex=True, estimator=True):
|
|
47
|
+
"""Convert sklearnex patch_map into a dictionary of estimators or functions
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
with_sklearnex: bool (default=True)
|
|
52
|
+
Discover estimators and methods with sklearnex patching enabled (True)
|
|
53
|
+
or disabled (False) from the sklearnex patch_map
|
|
54
|
+
|
|
55
|
+
estimator: bool (default=True)
|
|
56
|
+
yield estimators (True) or functions (False)
|
|
57
|
+
|
|
58
|
+
Returns
|
|
59
|
+
-------
|
|
60
|
+
dict: {name:estimator}
|
|
61
|
+
estimator is a class or function from sklearn or sklearnex
|
|
62
|
+
"""
|
|
47
63
|
# insure that patch state is correct as dictated by patch_sklearn boolean
|
|
48
64
|
# and return it to the previous state no matter what occurs.
|
|
49
65
|
already_patched_map = sklearn_is_patched(return_map=True)
|
|
@@ -91,11 +107,17 @@ mixin_map = [
|
|
|
91
107
|
|
|
92
108
|
|
|
93
109
|
class _sklearn_clone_dict(dict):
|
|
110
|
+
"""Special dict type for returning state-free sklearn/sklearnex estimators
|
|
111
|
+
with the same parameters"""
|
|
94
112
|
|
|
95
113
|
def __getitem__(self, key):
|
|
96
114
|
return clone(super().__getitem__(key))
|
|
97
115
|
|
|
98
116
|
|
|
117
|
+
# Special dictionary of sklearnex estimators which must be specifically tested, this
|
|
118
|
+
# could be because of supported non-default parameters, blocked support via sklearn's
|
|
119
|
+
# 'available_if' decorator, or not being a native sklearn estimator (i.e. those not in
|
|
120
|
+
# the default PATCHED_MODELS dictionary)
|
|
99
121
|
SPECIAL_INSTANCES = _sklearn_clone_dict(
|
|
100
122
|
{
|
|
101
123
|
str(i): i
|
|
@@ -112,38 +134,107 @@ SPECIAL_INSTANCES = _sklearn_clone_dict(
|
|
|
112
134
|
)
|
|
113
135
|
|
|
114
136
|
|
|
115
|
-
def gen_models_info(algorithms):
|
|
137
|
+
def gen_models_info(algorithms, required_inputs=["X", "y"]):
|
|
138
|
+
"""Generate estimator-attribute pairs for pytest test collection.
|
|
139
|
+
|
|
140
|
+
Parameters
|
|
141
|
+
----------
|
|
142
|
+
algorithms : iterable (list, tuple, 1D array-like object)
|
|
143
|
+
Iterable of valid sklearnex estimators or keys from PATCHED_MODELS
|
|
144
|
+
|
|
145
|
+
required_inputs : list, tuple of strings or None
|
|
146
|
+
list of required args/kwargs for callable attribute (only non-private,
|
|
147
|
+
non-BaseEstimator attributes). Only one must be present, None
|
|
148
|
+
signifies taking all non-private attribues, callable or not.
|
|
149
|
+
|
|
150
|
+
Returns
|
|
151
|
+
-------
|
|
152
|
+
list of 2-element tuples: (estimator, string)
|
|
153
|
+
Returns a list of valid methods or attributes without "fit"
|
|
154
|
+
"""
|
|
116
155
|
output = []
|
|
117
|
-
for
|
|
156
|
+
for estimator in algorithms:
|
|
118
157
|
|
|
119
|
-
if
|
|
120
|
-
est = PATCHED_MODELS[
|
|
121
|
-
elif isinstance(algorithms[
|
|
122
|
-
est = algorithms[
|
|
158
|
+
if estimator in PATCHED_MODELS:
|
|
159
|
+
est = PATCHED_MODELS[estimator]
|
|
160
|
+
elif isinstance(algorithms[estimator], BaseEstimator):
|
|
161
|
+
est = algorithms[estimator].__class__
|
|
162
|
+
else:
|
|
163
|
+
raise KeyError(f"Unrecognized sklearnex estimator: {estimator}")
|
|
164
|
+
|
|
165
|
+
# remove BaseEstimator methods (get_params, set_params)
|
|
166
|
+
candidates = set(dir(est)) - set(dir(BaseEstimator))
|
|
167
|
+
# remove private methods
|
|
168
|
+
candidates = set([attr for attr in candidates if not attr.startswith("_")])
|
|
169
|
+
# required to enable other methods
|
|
170
|
+
candidates = candidates - {"fit"}
|
|
171
|
+
|
|
172
|
+
# allow only callable methods with any of the required inputs
|
|
173
|
+
if required_inputs:
|
|
174
|
+
methods = []
|
|
175
|
+
for attr in candidates:
|
|
176
|
+
attribute = getattr_static(est, attr)
|
|
177
|
+
if callable(attribute):
|
|
178
|
+
params = signature(attribute).parameters
|
|
179
|
+
if any([inp in params for inp in required_inputs]):
|
|
180
|
+
methods += [attr]
|
|
123
181
|
else:
|
|
124
|
-
|
|
182
|
+
methods = candidates
|
|
125
183
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
184
|
+
output += (
|
|
185
|
+
[(estimator, method) for method in methods]
|
|
186
|
+
if methods
|
|
187
|
+
else [(estimator, None)]
|
|
129
188
|
)
|
|
130
189
|
|
|
131
|
-
for mixin, method, _ in mixin_map:
|
|
132
|
-
if issubclass(est, mixin):
|
|
133
|
-
methods |= candidates & set(method)
|
|
134
|
-
|
|
135
|
-
output += [[i, j] for j in methods] if methods else [[i, None]]
|
|
136
|
-
|
|
137
190
|
# In the case that no methods are available, set method to None.
|
|
138
191
|
# This will allow estimators without mixins to still test the fit
|
|
139
192
|
# method in various tests.
|
|
140
193
|
return output
|
|
141
194
|
|
|
142
195
|
|
|
143
|
-
def
|
|
196
|
+
def call_method(estimator, method, X, y, **kwargs):
|
|
197
|
+
"""Generalized interface to call most sklearn estimator methods
|
|
198
|
+
|
|
199
|
+
Parameters
|
|
200
|
+
----------
|
|
201
|
+
estimator : sklearn or sklearnex estimator instance
|
|
202
|
+
|
|
203
|
+
method: string
|
|
204
|
+
Valid callable method to estimator
|
|
205
|
+
|
|
206
|
+
X: array-like
|
|
207
|
+
data
|
|
208
|
+
|
|
209
|
+
y: array-like (for 'score', 'partial-fit', and 'path')
|
|
210
|
+
X-dependent data
|
|
211
|
+
|
|
212
|
+
**kwargs: keyword dict
|
|
213
|
+
keyword arguments to estimator.method
|
|
214
|
+
|
|
215
|
+
Returns
|
|
216
|
+
-------
|
|
217
|
+
return value from estimator.method
|
|
218
|
+
"""
|
|
219
|
+
# useful for repository wide testing
|
|
220
|
+
if method == "inverse_transform":
|
|
221
|
+
# PCA's inverse_transform takes (n_samples, n_components)
|
|
222
|
+
data = (
|
|
223
|
+
(X[:, : estimator.n_components_],)
|
|
224
|
+
if X.shape[1] != estimator.n_components_
|
|
225
|
+
else (X,)
|
|
226
|
+
)
|
|
227
|
+
elif method not in ["score", "partial_fit", "path"]:
|
|
228
|
+
data = (X,)
|
|
229
|
+
else:
|
|
230
|
+
data = (X, y)
|
|
231
|
+
return getattr(estimator, method)(*data, **kwargs)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _gen_dataset_type(est):
|
|
144
235
|
# est should be an estimator or estimator class
|
|
145
236
|
# dataset initialized to classification, but will be swapped
|
|
146
|
-
# for other types as necessary
|
|
237
|
+
# for other types as necessary. Private method.
|
|
147
238
|
dataset = "classification"
|
|
148
239
|
estimator = est.__class__ if isinstance(est, BaseEstimator) else est
|
|
149
240
|
|
|
@@ -167,7 +258,39 @@ def gen_dataset(
|
|
|
167
258
|
target_df=None,
|
|
168
259
|
dtype=None,
|
|
169
260
|
):
|
|
170
|
-
|
|
261
|
+
"""Generate dataset for pytest testing.
|
|
262
|
+
|
|
263
|
+
Parameters
|
|
264
|
+
----------
|
|
265
|
+
est : sklearn or sklearnex estimator class
|
|
266
|
+
Must inherit an sklearn Mixin or sklearn's BaseEstimator
|
|
267
|
+
|
|
268
|
+
dataset: dataset dict
|
|
269
|
+
Dictionary with keys "classification" and/or "regression"
|
|
270
|
+
Value must be a list of object which yield X, y array
|
|
271
|
+
objects when called, ideally using a lambda or
|
|
272
|
+
functools.partial.
|
|
273
|
+
|
|
274
|
+
sparse: bool (default False)
|
|
275
|
+
Convert X data to a scipy.sparse csr_matrix format.
|
|
276
|
+
|
|
277
|
+
queue: SYCL queue or None
|
|
278
|
+
Queue necessary for device offloading following the
|
|
279
|
+
SYCL 2020 standard, usually generated by dpctl.
|
|
280
|
+
|
|
281
|
+
target_df: string or None
|
|
282
|
+
dataframe type for returned dataset, as dictated by
|
|
283
|
+
onedal's _convert_to_dataframe.
|
|
284
|
+
|
|
285
|
+
dtype: numpy dtype or None
|
|
286
|
+
target datatype for returned datasets (see DTYPES).
|
|
287
|
+
|
|
288
|
+
Returns
|
|
289
|
+
-------
|
|
290
|
+
list of 2-element list X,y: (array-like, array-like)
|
|
291
|
+
list of datasets for analysis
|
|
292
|
+
"""
|
|
293
|
+
dataset_type = _gen_dataset_type(est)
|
|
171
294
|
output = []
|
|
172
295
|
# load data
|
|
173
296
|
flag = dtype is None
|