scikit-learn-intelex 2024.5.0__py311-none-win_amd64.whl → 2024.7.0__py311-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.5.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.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/cluster/dbscan.py +3 -1
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/cluster/k_means.py +8 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/cluster/tests/test_dbscan.py +8 -6
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/conftest.py +11 -1
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/covariance/incremental_covariance.py +64 -13
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/decomposition/pca.py +25 -1
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/decomposition/tests/test_pca.py +4 -2
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/dispatcher.py +109 -1
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/ensemble/_forest.py +121 -57
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/ensemble/tests/test_forest.py +7 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/glob/dispatcher.py +16 -2
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/incremental_linear.py +102 -25
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/linear.py +25 -39
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/logistic_regression.py +92 -74
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/ridge.py +7 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/tests/test_incremental_linear.py +10 -10
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/tests/test_linear.py +30 -5
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/metrics/pairwise.py +5 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/metrics/ranking.py +3 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/model_selection/split.py +3 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/_lof.py +9 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/common.py +45 -1
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_classification.py +1 -20
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_regression.py +25 -20
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_unsupervised.py +31 -7
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/__init__.py +1 -1
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/preview/decomposition/__init__.py +19 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/preview/decomposition/incremental_pca.py +228 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/preview/decomposition/tests/test_incremental_pca.py +266 -0
- scikit_learn_intelex-2024.5.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.7.0.data/data/Lib/site-packages/sklearnex/svm/_common.py +328 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/nusvc.py +40 -4
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/nusvr.py +31 -2
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/svc.py +40 -4
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/svr.py +31 -2
- {scikit_learn_intelex-2024.5.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.7.0.data/data/Lib/site-packages/sklearnex/tests/_utils.py +328 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/tests/_utils_spmd.py +185 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/tests/test_common.py +54 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_config.py +4 -0
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/tests/test_memory_usage.py +290 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_monkeypatch.py +12 -4
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_patching.py +21 -25
- scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/tests/test_run_to_run_stability.py +295 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/utils/_namespace.py +1 -1
- {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/METADATA +5 -2
- scikit_learn_intelex-2024.7.0.dist-info/RECORD +122 -0
- {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/WHEEL +1 -1
- scikit_learn_intelex-2024.5.0.data/data/Lib/site-packages/sklearnex/_device_offload.py +0 -257
- scikit_learn_intelex-2024.5.0.data/data/Lib/site-packages/sklearnex/basic_statistics/basic_statistics.py +0 -17
- scikit_learn_intelex-2024.5.0.data/data/Lib/site-packages/sklearnex/svm/_common.py +0 -185
- scikit_learn_intelex-2024.5.0.data/data/Lib/site-packages/sklearnex/tests/_utils.py +0 -173
- scikit_learn_intelex-2024.5.0.data/data/Lib/site-packages/sklearnex/tests/test_memory_usage.py +0 -231
- scikit_learn_intelex-2024.5.0.data/data/Lib/site-packages/sklearnex/tests/test_run_to_run_stability_tests.py +0 -428
- scikit_learn_intelex-2024.5.0.dist-info/RECORD +0 -104
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/__main__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/_utils.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/basic_statistics/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/covariance/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/decomposition/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/ensemble/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/glob/__main__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/linear_model/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/manifold/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/metrics/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/model_selection/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/neighbors/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/_common.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/covariance.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/dbscan.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/kmeans.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/covariance/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/covariance/covariance.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/decomposition/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/decomposition/pca.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/ensemble/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/ensemble/forest.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.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.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/neighbors/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/spmd/neighbors/neighbors.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/svm/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/tests/test_parallel.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/utils/__init__.py +0 -0
- {scikit_learn_intelex-2024.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/utils/parallel.py +0 -0
- {scikit_learn_intelex-2024.5.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.5.0.data → scikit_learn_intelex-2024.7.0.data}/data/Lib/site-packages/sklearnex/utils/validation.py +0 -0
- {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.5.0.dist-info → scikit_learn_intelex-2024.7.0.dist-info}/top_level.txt +0 -0
scikit_learn_intelex-2024.7.0.data/data/Lib/site-packages/sklearnex/preview/linear_model/ridge.py
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
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 logging
|
|
18
|
+
|
|
19
|
+
from daal4py.sklearn._utils import daal_check_version, sklearn_check_version
|
|
20
|
+
|
|
21
|
+
if daal_check_version((2024, "P", 600)):
|
|
22
|
+
import numbers
|
|
23
|
+
|
|
24
|
+
import numpy as np
|
|
25
|
+
from scipy.sparse import issparse
|
|
26
|
+
from sklearn.linear_model import Ridge as sklearn_Ridge
|
|
27
|
+
from sklearn.metrics import r2_score
|
|
28
|
+
from sklearn.utils.validation import check_is_fitted, check_X_y
|
|
29
|
+
|
|
30
|
+
from daal4py.sklearn.linear_model._ridge import _fit_ridge as daal4py_fit_ridge
|
|
31
|
+
|
|
32
|
+
if sklearn_check_version("1.0") and not sklearn_check_version("1.2"):
|
|
33
|
+
from sklearn.linear_model._base import _deprecate_normalize
|
|
34
|
+
if sklearn_check_version("1.1") and not sklearn_check_version("1.2"):
|
|
35
|
+
from sklearn.utils import check_scalar
|
|
36
|
+
|
|
37
|
+
from onedal.linear_model import Ridge as onedal_Ridge
|
|
38
|
+
from onedal.utils import _num_features, _num_samples
|
|
39
|
+
|
|
40
|
+
from ..._device_offload import dispatch, wrap_output_data
|
|
41
|
+
from ..._utils import PatchingConditionsChain
|
|
42
|
+
|
|
43
|
+
def _is_numeric_scalar(value):
|
|
44
|
+
"""
|
|
45
|
+
Determines if the provided value is a numeric scalar.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
value: The value to be checked.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
bool: True if the value is a numeric scalar, False otherwise.
|
|
52
|
+
"""
|
|
53
|
+
return isinstance(value, numbers.Real)
|
|
54
|
+
|
|
55
|
+
class Ridge(sklearn_Ridge):
|
|
56
|
+
__doc__ = sklearn_Ridge.__doc__
|
|
57
|
+
|
|
58
|
+
if sklearn_check_version("1.2"):
|
|
59
|
+
_parameter_constraints: dict = {**sklearn_Ridge._parameter_constraints}
|
|
60
|
+
|
|
61
|
+
def __init__(
|
|
62
|
+
self,
|
|
63
|
+
alpha=1.0,
|
|
64
|
+
fit_intercept=True,
|
|
65
|
+
copy_X=True,
|
|
66
|
+
max_iter=None,
|
|
67
|
+
tol=1e-4,
|
|
68
|
+
solver="auto",
|
|
69
|
+
positive=False,
|
|
70
|
+
random_state=None,
|
|
71
|
+
):
|
|
72
|
+
super().__init__(
|
|
73
|
+
alpha=alpha,
|
|
74
|
+
fit_intercept=fit_intercept,
|
|
75
|
+
copy_X=copy_X,
|
|
76
|
+
max_iter=max_iter,
|
|
77
|
+
tol=tol,
|
|
78
|
+
solver=solver,
|
|
79
|
+
positive=positive,
|
|
80
|
+
random_state=random_state,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
elif sklearn_check_version("1.0"):
|
|
84
|
+
|
|
85
|
+
def __init__(
|
|
86
|
+
self,
|
|
87
|
+
alpha=1.0,
|
|
88
|
+
fit_intercept=True,
|
|
89
|
+
normalize="deprecated",
|
|
90
|
+
copy_X=True,
|
|
91
|
+
max_iter=None,
|
|
92
|
+
tol=1e-3,
|
|
93
|
+
solver="auto",
|
|
94
|
+
positive=False,
|
|
95
|
+
random_state=None,
|
|
96
|
+
):
|
|
97
|
+
super().__init__(
|
|
98
|
+
alpha=alpha,
|
|
99
|
+
fit_intercept=fit_intercept,
|
|
100
|
+
normalize=normalize,
|
|
101
|
+
copy_X=copy_X,
|
|
102
|
+
max_iter=max_iter,
|
|
103
|
+
solver=solver,
|
|
104
|
+
tol=tol,
|
|
105
|
+
positive=positive,
|
|
106
|
+
random_state=random_state,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
else:
|
|
110
|
+
|
|
111
|
+
def __init__(
|
|
112
|
+
self,
|
|
113
|
+
alpha=1.0,
|
|
114
|
+
fit_intercept=True,
|
|
115
|
+
normalize=False,
|
|
116
|
+
copy_X=True,
|
|
117
|
+
max_iter=None,
|
|
118
|
+
tol=1e-3,
|
|
119
|
+
solver="auto",
|
|
120
|
+
random_state=None,
|
|
121
|
+
):
|
|
122
|
+
super().__init__(
|
|
123
|
+
alpha=alpha,
|
|
124
|
+
fit_intercept=fit_intercept,
|
|
125
|
+
normalize=normalize,
|
|
126
|
+
copy_X=copy_X,
|
|
127
|
+
max_iter=max_iter,
|
|
128
|
+
tol=tol,
|
|
129
|
+
solver=solver,
|
|
130
|
+
random_state=random_state,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
def fit(self, X, y, sample_weight=None):
|
|
134
|
+
# It is necessary to properly update coefs for predict if we
|
|
135
|
+
# fallback to sklearn in dispatch
|
|
136
|
+
if hasattr(self, "_onedal_estimator"):
|
|
137
|
+
del self._onedal_estimator
|
|
138
|
+
|
|
139
|
+
dispatch(
|
|
140
|
+
self,
|
|
141
|
+
"fit",
|
|
142
|
+
{
|
|
143
|
+
"onedal": self.__class__._onedal_fit,
|
|
144
|
+
"sklearn": sklearn_Ridge.fit,
|
|
145
|
+
},
|
|
146
|
+
X,
|
|
147
|
+
y,
|
|
148
|
+
sample_weight,
|
|
149
|
+
)
|
|
150
|
+
return self
|
|
151
|
+
|
|
152
|
+
@wrap_output_data
|
|
153
|
+
def predict(self, X):
|
|
154
|
+
check_is_fitted(self)
|
|
155
|
+
|
|
156
|
+
return dispatch(
|
|
157
|
+
self,
|
|
158
|
+
"predict",
|
|
159
|
+
{
|
|
160
|
+
"onedal": self.__class__._onedal_predict,
|
|
161
|
+
"sklearn": sklearn_Ridge.predict,
|
|
162
|
+
},
|
|
163
|
+
X,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
@wrap_output_data
|
|
167
|
+
def score(self, X, y, sample_weight=None):
|
|
168
|
+
check_is_fitted(self)
|
|
169
|
+
|
|
170
|
+
return dispatch(
|
|
171
|
+
self,
|
|
172
|
+
"score",
|
|
173
|
+
{
|
|
174
|
+
"onedal": self.__class__._onedal_score,
|
|
175
|
+
"sklearn": sklearn_Ridge.score,
|
|
176
|
+
},
|
|
177
|
+
X,
|
|
178
|
+
y,
|
|
179
|
+
sample_weight=sample_weight,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
def _onedal_fit_supported(self, patching_status, method_name, *data):
|
|
183
|
+
assert method_name == "fit"
|
|
184
|
+
assert len(data) == 3
|
|
185
|
+
X, y, sample_weight = data
|
|
186
|
+
|
|
187
|
+
normalize_is_set = (
|
|
188
|
+
hasattr(self, "normalize")
|
|
189
|
+
and self.normalize
|
|
190
|
+
and self.normalize != "deprecated"
|
|
191
|
+
)
|
|
192
|
+
positive_is_set = hasattr(self, "positive") and self.positive
|
|
193
|
+
|
|
194
|
+
n_samples = _num_samples(X)
|
|
195
|
+
n_features = _num_features(X, fallback_1d=True)
|
|
196
|
+
|
|
197
|
+
# Check if equations are well defined
|
|
198
|
+
is_underdetermined = n_samples < (n_features + int(self.fit_intercept))
|
|
199
|
+
|
|
200
|
+
patching_status.and_conditions(
|
|
201
|
+
[
|
|
202
|
+
(
|
|
203
|
+
self.solver == "auto",
|
|
204
|
+
f"'{self.solver}' solver is not supported. "
|
|
205
|
+
"Only 'auto' solver is supported.",
|
|
206
|
+
),
|
|
207
|
+
(
|
|
208
|
+
not issparse(X) and not issparse(y),
|
|
209
|
+
"Sparse input is not supported.",
|
|
210
|
+
),
|
|
211
|
+
(
|
|
212
|
+
not is_underdetermined,
|
|
213
|
+
"The shape of X (fitting) does not satisfy oneDAL requirements:"
|
|
214
|
+
"Number of features + 1 >= number of samples.",
|
|
215
|
+
),
|
|
216
|
+
(sample_weight is None, "Sample weight is not supported."),
|
|
217
|
+
(not normalize_is_set, "Normalization is not supported."),
|
|
218
|
+
(
|
|
219
|
+
not positive_is_set,
|
|
220
|
+
"Forced positive coefficients are not supported.",
|
|
221
|
+
),
|
|
222
|
+
]
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
return patching_status
|
|
226
|
+
|
|
227
|
+
def _onedal_predict_supported(self, patching_status, method_name, *data):
|
|
228
|
+
assert method_name in ["predict", "score"]
|
|
229
|
+
assert len(data) <= 2
|
|
230
|
+
|
|
231
|
+
n_samples = _num_samples(data[0])
|
|
232
|
+
model_is_sparse = issparse(self.coef_) or (
|
|
233
|
+
self.fit_intercept and issparse(self.intercept_)
|
|
234
|
+
)
|
|
235
|
+
patching_status.and_conditions(
|
|
236
|
+
[
|
|
237
|
+
(
|
|
238
|
+
self.solver == "auto",
|
|
239
|
+
f"'{self.solver}' solver is not supported. "
|
|
240
|
+
"Only 'auto' solver is supported.",
|
|
241
|
+
),
|
|
242
|
+
(n_samples > 0, "Number of samples is less than 1."),
|
|
243
|
+
(not issparse(data[0]), "Sparse input is not supported."),
|
|
244
|
+
(not model_is_sparse, "Sparse coefficients are not supported."),
|
|
245
|
+
]
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
return patching_status
|
|
249
|
+
|
|
250
|
+
def _onedal_gpu_supported(self, method_name, *data):
|
|
251
|
+
patching_status = PatchingConditionsChain(
|
|
252
|
+
f"sklearn.linear_model.{self.__class__.__name__}.fit"
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
if method_name == "fit":
|
|
256
|
+
patching_status.and_condition(
|
|
257
|
+
_is_numeric_scalar(self.alpha),
|
|
258
|
+
"Non-scalar alpha is not supported for GPU.",
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
return self._onedal_fit_supported(patching_status, method_name, *data)
|
|
262
|
+
|
|
263
|
+
if method_name in ["predict", "score"]:
|
|
264
|
+
return self._onedal_predict_supported(patching_status, method_name, *data)
|
|
265
|
+
|
|
266
|
+
raise RuntimeError(
|
|
267
|
+
f"Unknown method {method_name} in {self.__class__.__name__}"
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
def _onedal_cpu_supported(self, method_name, *data):
|
|
271
|
+
patching_status = PatchingConditionsChain(
|
|
272
|
+
f"sklearn.linear_model.{self.__class__.__name__}.fit"
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
if method_name == "fit":
|
|
276
|
+
return self._onedal_fit_supported(patching_status, method_name, *data)
|
|
277
|
+
|
|
278
|
+
if method_name in ["predict", "score"]:
|
|
279
|
+
return self._onedal_predict_supported(patching_status, method_name, *data)
|
|
280
|
+
|
|
281
|
+
raise RuntimeError(
|
|
282
|
+
f"Unknown method {method_name} in {self.__class__.__name__}"
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
def _initialize_onedal_estimator(self):
|
|
286
|
+
onedal_params = {
|
|
287
|
+
"fit_intercept": self.fit_intercept,
|
|
288
|
+
"alpha": self.alpha,
|
|
289
|
+
"copy_X": self.copy_X,
|
|
290
|
+
}
|
|
291
|
+
self._onedal_estimator = onedal_Ridge(**onedal_params)
|
|
292
|
+
|
|
293
|
+
def _daal_fit(self, X, y, sample_weight=None):
|
|
294
|
+
daal4py_fit_ridge(self, X, y, sample_weight)
|
|
295
|
+
self._onedal_estimator.n_features_in_ = _num_features(X, fallback_1d=True)
|
|
296
|
+
self._onedal_estimator.coef_ = self.coef_
|
|
297
|
+
self._onedal_estimator.intercept_ = self.intercept_
|
|
298
|
+
|
|
299
|
+
def _onedal_fit(self, X, y, sample_weight, queue=None):
|
|
300
|
+
# `Sample weight` is not supported. Expected to be None value.
|
|
301
|
+
assert sample_weight is None
|
|
302
|
+
|
|
303
|
+
if sklearn_check_version("1.2"):
|
|
304
|
+
self._validate_params()
|
|
305
|
+
elif sklearn_check_version("1.1"):
|
|
306
|
+
if self.max_iter is not None:
|
|
307
|
+
self.max_iter = check_scalar(
|
|
308
|
+
self.max_iter, "max_iter", target_type=numbers.Integral, min_val=1
|
|
309
|
+
)
|
|
310
|
+
self.tol = check_scalar(
|
|
311
|
+
self.tol, "tol", target_type=numbers.Real, min_val=0.0
|
|
312
|
+
)
|
|
313
|
+
if self.alpha is not None and not isinstance(
|
|
314
|
+
self.alpha, (np.ndarray, tuple)
|
|
315
|
+
):
|
|
316
|
+
self.alpha = check_scalar(
|
|
317
|
+
self.alpha,
|
|
318
|
+
"alpha",
|
|
319
|
+
target_type=numbers.Real,
|
|
320
|
+
min_val=0.0,
|
|
321
|
+
include_boundaries="left",
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
check_params = {
|
|
325
|
+
"X": X,
|
|
326
|
+
"y": y,
|
|
327
|
+
"dtype": [np.float64, np.float32],
|
|
328
|
+
"accept_sparse": ["csr", "csc", "coo"],
|
|
329
|
+
"y_numeric": True,
|
|
330
|
+
"multi_output": True,
|
|
331
|
+
}
|
|
332
|
+
if sklearn_check_version("1.0"):
|
|
333
|
+
X, y = self._validate_data(**check_params)
|
|
334
|
+
else:
|
|
335
|
+
X, y = check_X_y(**check_params)
|
|
336
|
+
|
|
337
|
+
if sklearn_check_version("1.0") and not sklearn_check_version("1.2"):
|
|
338
|
+
self._normalize = _deprecate_normalize(
|
|
339
|
+
self.normalize,
|
|
340
|
+
default=False,
|
|
341
|
+
estimator_name=self.__class__.__name__,
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
self._initialize_onedal_estimator()
|
|
345
|
+
|
|
346
|
+
# Falling back to daal4py if the device is CPU and alpha is array-like
|
|
347
|
+
# since onedal does not yet support non-scalars for alpha, thus
|
|
348
|
+
# should only be used for GPU/CPU with scalar alpha to not limit the functionality
|
|
349
|
+
cpu_device = queue is None or queue.sycl_device.is_cpu
|
|
350
|
+
if cpu_device and not _is_numeric_scalar(self.alpha):
|
|
351
|
+
self._daal_fit(X, y)
|
|
352
|
+
else:
|
|
353
|
+
self._onedal_estimator.fit(X, y, queue=queue)
|
|
354
|
+
|
|
355
|
+
self._save_attributes()
|
|
356
|
+
|
|
357
|
+
def _onedal_predict(self, X, queue=None):
|
|
358
|
+
if sklearn_check_version("1.0"):
|
|
359
|
+
X = self._validate_data(X, accept_sparse=False, reset=False)
|
|
360
|
+
|
|
361
|
+
if not hasattr(self, "_onedal_estimator"):
|
|
362
|
+
self._initialize_onedal_estimator()
|
|
363
|
+
self._onedal_estimator.coef_ = self.coef_
|
|
364
|
+
self._onedal_estimator.intercept_ = self.intercept_
|
|
365
|
+
|
|
366
|
+
res = self._onedal_estimator.predict(X, queue=queue)
|
|
367
|
+
return res
|
|
368
|
+
|
|
369
|
+
def _onedal_score(self, X, y, sample_weight=None, queue=None):
|
|
370
|
+
return r2_score(
|
|
371
|
+
y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
@property
|
|
375
|
+
def coef_(self):
|
|
376
|
+
return self._coef
|
|
377
|
+
|
|
378
|
+
@coef_.setter
|
|
379
|
+
def coef_(self, value):
|
|
380
|
+
if hasattr(self, "_onedal_estimator"):
|
|
381
|
+
self._onedal_estimator.coef_ = value
|
|
382
|
+
# checking if the model is already fitted and if so, deleting the model
|
|
383
|
+
if hasattr(self._onedal_estimator, "_onedal_model"):
|
|
384
|
+
del self._onedal_estimator._onedal_model
|
|
385
|
+
self._coef = value
|
|
386
|
+
|
|
387
|
+
@property
|
|
388
|
+
def intercept_(self):
|
|
389
|
+
return self._intercept
|
|
390
|
+
|
|
391
|
+
@intercept_.setter
|
|
392
|
+
def intercept_(self, value):
|
|
393
|
+
if hasattr(self, "_onedal_estimator"):
|
|
394
|
+
self._onedal_estimator.intercept_ = value
|
|
395
|
+
# checking if the model is already fitted and if so, deleting the model
|
|
396
|
+
if hasattr(self._onedal_estimator, "_onedal_model"):
|
|
397
|
+
del self._onedal_estimator._onedal_model
|
|
398
|
+
self._intercept = value
|
|
399
|
+
|
|
400
|
+
def _save_attributes(self):
|
|
401
|
+
self.n_features_in_ = self._onedal_estimator.n_features_in_
|
|
402
|
+
self._coef = self._onedal_estimator.coef_
|
|
403
|
+
self._intercept = self._onedal_estimator.intercept_
|
|
404
|
+
|
|
405
|
+
fit.__doc__ = sklearn_Ridge.fit.__doc__
|
|
406
|
+
predict.__doc__ = sklearn_Ridge.predict.__doc__
|
|
407
|
+
score.__doc__ = sklearn_Ridge.score.__doc__
|
|
408
|
+
|
|
409
|
+
else:
|
|
410
|
+
from daal4py.sklearn.linear_model._ridge import Ridge
|
|
411
|
+
from onedal._device_offload import support_usm_ndarray
|
|
412
|
+
|
|
413
|
+
Ridge.fit = support_usm_ndarray(queue_param=False)(Ridge.fit)
|
|
414
|
+
Ridge.predict = support_usm_ndarray(queue_param=False)(Ridge.predict)
|
|
415
|
+
Ridge.score = support_usm_ndarray(queue_param=False)(Ridge.score)
|
|
416
|
+
|
|
417
|
+
logging.warning(
|
|
418
|
+
"Preview Ridge requires oneDAL version >= 2024.6 but it was not found"
|
|
419
|
+
)
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
|
18
|
+
import pytest
|
|
19
|
+
from numpy.testing import assert_allclose
|
|
20
|
+
from sklearn.exceptions import NotFittedError
|
|
21
|
+
|
|
22
|
+
from daal4py.sklearn._utils import daal_check_version
|
|
23
|
+
from onedal.tests.utils._dataframes_support import (
|
|
24
|
+
_convert_to_dataframe,
|
|
25
|
+
get_dataframes_and_queues,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
30
|
+
def test_sklearnex_import_ridge(dataframe, queue):
|
|
31
|
+
from sklearnex.preview.linear_model import Ridge
|
|
32
|
+
|
|
33
|
+
X = numpy.array([[1, 1], [1, 2], [2, 2], [2, 3]])
|
|
34
|
+
y = numpy.dot(X, numpy.array([1, 2])) + 3
|
|
35
|
+
X_c = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
36
|
+
y_c = _convert_to_dataframe(y, sycl_queue=queue, target_df=dataframe)
|
|
37
|
+
ridge_reg = Ridge(alpha=0.5).fit(X_c, y_c)
|
|
38
|
+
|
|
39
|
+
if daal_check_version((2024, "P", 600)):
|
|
40
|
+
assert "preview" in ridge_reg.__module__
|
|
41
|
+
else:
|
|
42
|
+
assert "daal4py" in ridge_reg.__module__
|
|
43
|
+
|
|
44
|
+
assert_allclose(ridge_reg.intercept_, 3.86, rtol=1e-2)
|
|
45
|
+
assert_allclose(ridge_reg.coef_, [0.91, 1.64], rtol=1e-2)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
49
|
+
@pytest.mark.parametrize("sample_size", [100, 1000])
|
|
50
|
+
@pytest.mark.parametrize("feature_size", [10, 50])
|
|
51
|
+
@pytest.mark.parametrize("alpha", [0.1, 0.5, 1.0])
|
|
52
|
+
def test_ridge_coefficients(dataframe, queue, sample_size, feature_size, alpha):
|
|
53
|
+
from sklearnex.preview.linear_model import Ridge
|
|
54
|
+
|
|
55
|
+
X = numpy.random.rand(sample_size, feature_size)
|
|
56
|
+
y = numpy.random.rand(sample_size)
|
|
57
|
+
X_c = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
58
|
+
y_c = _convert_to_dataframe(y, sycl_queue=queue, target_df=dataframe)
|
|
59
|
+
ridge_reg = Ridge(fit_intercept=False, alpha=alpha).fit(X_c, y_c)
|
|
60
|
+
|
|
61
|
+
# computing the coefficients manually
|
|
62
|
+
# using the normal equation formula: (X^T * X + lambda * I)^-1 * X^T * y
|
|
63
|
+
lambda_identity = alpha * numpy.eye(X.shape[1])
|
|
64
|
+
inverse_term = numpy.linalg.inv(numpy.dot(X.T, X) + lambda_identity)
|
|
65
|
+
xt_y = numpy.dot(X.T, y)
|
|
66
|
+
coefficients_manual = numpy.dot(inverse_term, xt_y)
|
|
67
|
+
|
|
68
|
+
assert_allclose(ridge_reg.coef_, coefficients_manual, rtol=1e-6, atol=1e-6)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if daal_check_version((2024, "P", 600)):
|
|
72
|
+
|
|
73
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
74
|
+
def test_ridge_score_before_fit(dataframe, queue):
|
|
75
|
+
from sklearnex.preview.linear_model import Ridge
|
|
76
|
+
|
|
77
|
+
sample_count, feature_count = 10, 5
|
|
78
|
+
|
|
79
|
+
model = Ridge(fit_intercept=True, alpha=0.5)
|
|
80
|
+
|
|
81
|
+
X, y = numpy.random.rand(sample_count, feature_count), numpy.random.rand(
|
|
82
|
+
sample_count
|
|
83
|
+
)
|
|
84
|
+
X_c = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
85
|
+
y_c = _convert_to_dataframe(y, sycl_queue=queue, target_df=dataframe)
|
|
86
|
+
|
|
87
|
+
with pytest.raises(NotFittedError):
|
|
88
|
+
model.score(X_c, y_c)
|
|
89
|
+
|
|
90
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
91
|
+
def test_ridge_predict_before_fit(dataframe, queue):
|
|
92
|
+
from sklearnex.preview.linear_model import Ridge
|
|
93
|
+
|
|
94
|
+
sample_count, feature_count = 10, 5
|
|
95
|
+
|
|
96
|
+
model = Ridge(fit_intercept=True, alpha=0.5)
|
|
97
|
+
|
|
98
|
+
X = numpy.random.rand(sample_count, feature_count)
|
|
99
|
+
X_c = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
100
|
+
|
|
101
|
+
with pytest.raises(NotFittedError):
|
|
102
|
+
model.predict(X_c)
|
|
@@ -0,0 +1,107 @@
|
|
|
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_basic_statistics import options_and_tests
|
|
22
|
+
from onedal.tests.utils._dataframes_support import (
|
|
23
|
+
_convert_to_dataframe,
|
|
24
|
+
get_dataframes_and_queues,
|
|
25
|
+
)
|
|
26
|
+
from sklearnex.tests._utils_spmd import (
|
|
27
|
+
_generate_statistic_data,
|
|
28
|
+
_get_local_tensor,
|
|
29
|
+
_mpi_libs_and_gpu_available,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.skipif(
|
|
34
|
+
not _mpi_libs_and_gpu_available,
|
|
35
|
+
reason="GPU device and MPI libs required for test",
|
|
36
|
+
)
|
|
37
|
+
@pytest.mark.parametrize(
|
|
38
|
+
"dataframe,queue",
|
|
39
|
+
get_dataframes_and_queues(dataframe_filter_="dpnp,dpctl", device_filter_="gpu"),
|
|
40
|
+
)
|
|
41
|
+
@pytest.mark.mpi
|
|
42
|
+
def test_basic_stats_spmd_gold(dataframe, queue):
|
|
43
|
+
# Import spmd and batch algo
|
|
44
|
+
from onedal.basic_statistics import BasicStatistics as BasicStatistics_Batch
|
|
45
|
+
from sklearnex.spmd.basic_statistics import BasicStatistics as BasicStatistics_SPMD
|
|
46
|
+
|
|
47
|
+
# Create gold data and convert to dataframe
|
|
48
|
+
data = np.array(
|
|
49
|
+
[
|
|
50
|
+
[0.0, 0.0, 0.0],
|
|
51
|
+
[0.0, 1.0, 2.0],
|
|
52
|
+
[0.0, 2.0, 4.0],
|
|
53
|
+
[0.0, 3.0, 8.0],
|
|
54
|
+
[0.0, 4.0, 16.0],
|
|
55
|
+
[0.0, 5.0, 32.0],
|
|
56
|
+
[0.0, 6.0, 64.0],
|
|
57
|
+
]
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
local_dpt_data = _convert_to_dataframe(
|
|
61
|
+
_get_local_tensor(data), sycl_queue=queue, target_df=dataframe
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Ensure results of batch algo match spmd
|
|
65
|
+
spmd_result = BasicStatistics_SPMD().fit(local_dpt_data)
|
|
66
|
+
batch_result = BasicStatistics_Batch().fit(data)
|
|
67
|
+
|
|
68
|
+
for option in (opt[0] for opt in options_and_tests):
|
|
69
|
+
assert_allclose(getattr(spmd_result, option), getattr(batch_result, option))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@pytest.mark.skipif(
|
|
73
|
+
not _mpi_libs_and_gpu_available,
|
|
74
|
+
reason="GPU device and MPI libs required for test",
|
|
75
|
+
)
|
|
76
|
+
@pytest.mark.parametrize("n_samples", [100, 10000])
|
|
77
|
+
@pytest.mark.parametrize("n_features", [10, 100])
|
|
78
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
79
|
+
@pytest.mark.parametrize(
|
|
80
|
+
"dataframe,queue",
|
|
81
|
+
get_dataframes_and_queues(dataframe_filter_="dpnp,dpctl", device_filter_="gpu"),
|
|
82
|
+
)
|
|
83
|
+
@pytest.mark.mpi
|
|
84
|
+
def test_basic_stats_spmd_synthetic(n_samples, n_features, dataframe, queue, dtype):
|
|
85
|
+
# Import spmd and batch algo
|
|
86
|
+
from onedal.basic_statistics import BasicStatistics as BasicStatistics_Batch
|
|
87
|
+
from sklearnex.spmd.basic_statistics import BasicStatistics as BasicStatistics_SPMD
|
|
88
|
+
|
|
89
|
+
# Generate data and convert to dataframe
|
|
90
|
+
data = _generate_statistic_data(n_samples, n_features, dtype=dtype)
|
|
91
|
+
|
|
92
|
+
local_dpt_data = _convert_to_dataframe(
|
|
93
|
+
_get_local_tensor(data), sycl_queue=queue, target_df=dataframe
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# Ensure results of batch algo match spmd
|
|
97
|
+
spmd_result = BasicStatistics_SPMD().fit(local_dpt_data)
|
|
98
|
+
batch_result = BasicStatistics_Batch().fit(data)
|
|
99
|
+
|
|
100
|
+
tol = 1e-5 if dtype == np.float32 else 1e-7
|
|
101
|
+
for option in (opt[0] for opt in options_and_tests):
|
|
102
|
+
assert_allclose(
|
|
103
|
+
getattr(spmd_result, option),
|
|
104
|
+
getattr(batch_result, option),
|
|
105
|
+
atol=tol,
|
|
106
|
+
rtol=tol,
|
|
107
|
+
)
|