scikit-learn-intelex 2024.2.0__py311-none-win_amd64.whl → 2024.4.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.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/__init__.py +9 -7
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/_device_offload.py +31 -4
- {scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/spmd → scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex}/basic_statistics/__init__.py +2 -1
- scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
- scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +386 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/cluster/dbscan.py +3 -1
- scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/conftest.py +63 -0
- scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/decomposition/pca.py +335 -0
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/preview/decomposition/tests/test_preview_pca.py → scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/decomposition/tests/test_pca.py +22 -8
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/dispatcher.py +74 -43
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/ensemble/_forest.py +78 -89
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/ensemble/tests/test_forest.py +15 -19
- scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/linear_model/linear.py +316 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/linear_model/logistic_regression.py +63 -11
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/linear_model/tests/test_linear.py +40 -5
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/linear_model/tests/test_logreg.py +0 -2
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/neighbors/_lof.py +74 -20
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/neighbors/common.py +4 -1
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_classification.py +44 -131
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/neighbors/knn_unsupervised.py → scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/neighbors/knn_regression.py +198 -221
- scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/neighbors/knn_unsupervised.py +146 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/neighbors/tests/test_neighbors.py +0 -5
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/preview/__init__.py +1 -1
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/k_means.py +5 -73
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/covariance.py +6 -5
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/tests/test_covariance.py +18 -5
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/ensemble/forest.py +4 -12
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/svm/_common.py +4 -7
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/svm/nusvc.py +70 -50
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/svm/nusvr.py +6 -52
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/svm/svc.py +70 -51
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/svm/svr.py +3 -49
- scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/tests/_utils.py +164 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/tests/test_memory_usage.py +8 -3
- scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/tests/test_monkeypatch.py +268 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/tests/test_n_jobs_support.py +8 -2
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/tests/test_parallel.py +6 -8
- scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/tests/test_patching.py +371 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/utils/__init__.py +2 -1
- scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/utils/_namespace.py +97 -0
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/METADATA +2 -2
- scikit_learn_intelex-2024.4.0.dist-info/RECORD +101 -0
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/decomposition/pca.py +0 -17
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/decomposition/tests/test_pca.py +0 -27
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/linear_model/linear.py +0 -381
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/neighbors/knn_regression.py +0 -308
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/preview/decomposition/__init__.py +0 -19
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/preview/decomposition/pca.py +0 -374
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/tests/_models_info.py +0 -170
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/tests/test_monkeypatch.py +0 -240
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/tests/test_patching.py +0 -136
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/tests/utils/_launch_algorithms.py +0 -118
- scikit_learn_intelex-2024.2.0.dist-info/RECORD +0 -101
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/__main__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/_config.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/_utils.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/basic_statistics/basic_statistics.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/cluster/k_means.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/cluster/tests/test_dbscan.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/cluster/tests/test_kmeans.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/covariance/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/covariance/incremental_covariance.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/covariance/tests/test_incremental_covariance.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/decomposition/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/doc/third-party-programs.txt +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/ensemble/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/glob/__main__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/glob/dispatcher.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/linear_model/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/linear_model/coordinate_descent.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/linear_model/logistic_path.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/linear_model/ridge.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/manifold/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/manifold/t_sne.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/manifold/tests/test_tsne.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/metrics/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/metrics/pairwise.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/metrics/ranking.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/metrics/tests/test_metrics.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/model_selection/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/model_selection/split.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/model_selection/tests/test_model_selection.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/neighbors/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/_common.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex → scikit_learn_intelex-2024.4.0.data/data/Lib/site-packages/sklearnex/spmd}/basic_statistics/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/basic_statistics/basic_statistics.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/dbscan.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/kmeans.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/covariance/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/covariance/covariance.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/decomposition/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/decomposition/pca.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/ensemble/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/linear_model/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/linear_model/linear_model.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/linear_model/logistic_regression.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/neighbors/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/spmd/neighbors/neighbors.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/svm/__init__.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/svm/tests/test_svm.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/tests/test_config.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/tests/test_run_to_run_stability_tests.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/utils/parallel.py +0 -0
- {scikit_learn_intelex-2024.2.0.data → scikit_learn_intelex-2024.4.0.data}/data/Lib/site-packages/sklearnex/utils/validation.py +0 -0
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/WHEEL +0 -0
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/top_level.txt +0 -0
|
@@ -38,19 +38,27 @@ if daal_check_version((2024, "P", 1)):
|
|
|
38
38
|
import numpy as np
|
|
39
39
|
from scipy.sparse import issparse
|
|
40
40
|
from sklearn.linear_model import LogisticRegression as sklearn_LogisticRegression
|
|
41
|
+
from sklearn.metrics import accuracy_score
|
|
42
|
+
from sklearn.utils.multiclass import type_of_target
|
|
41
43
|
from sklearn.utils.validation import check_X_y
|
|
42
44
|
|
|
43
45
|
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
44
46
|
from daal4py.sklearn._utils import sklearn_check_version
|
|
45
47
|
from onedal.linear_model import LogisticRegression as onedal_LogisticRegression
|
|
46
|
-
from onedal.utils import
|
|
48
|
+
from onedal.utils import _num_samples
|
|
47
49
|
|
|
48
50
|
from .._device_offload import dispatch, wrap_output_data
|
|
49
51
|
from .._utils import PatchingConditionsChain, get_patch_message
|
|
50
52
|
from ..utils.validation import _assert_all_finite
|
|
51
53
|
|
|
52
54
|
@control_n_jobs(
|
|
53
|
-
decorated_methods=[
|
|
55
|
+
decorated_methods=[
|
|
56
|
+
"fit",
|
|
57
|
+
"predict",
|
|
58
|
+
"predict_proba",
|
|
59
|
+
"predict_log_proba",
|
|
60
|
+
"score",
|
|
61
|
+
]
|
|
54
62
|
)
|
|
55
63
|
class LogisticRegression(sklearn_LogisticRegression, BaseLogisticRegression):
|
|
56
64
|
__doc__ = sklearn_LogisticRegression.__doc__
|
|
@@ -72,9 +80,9 @@ if daal_check_version((2024, "P", 1)):
|
|
|
72
80
|
intercept_scaling=1,
|
|
73
81
|
class_weight=None,
|
|
74
82
|
random_state=None,
|
|
75
|
-
solver="lbfgs"
|
|
83
|
+
solver="lbfgs",
|
|
76
84
|
max_iter=100,
|
|
77
|
-
multi_class="auto"
|
|
85
|
+
multi_class="auto",
|
|
78
86
|
verbose=0,
|
|
79
87
|
warm_start=False,
|
|
80
88
|
n_jobs=None,
|
|
@@ -160,6 +168,27 @@ if daal_check_version((2024, "P", 1)):
|
|
|
160
168
|
X,
|
|
161
169
|
)
|
|
162
170
|
|
|
171
|
+
@wrap_output_data
|
|
172
|
+
def score(self, X, y, sample_weight=None):
|
|
173
|
+
if sklearn_check_version("1.0"):
|
|
174
|
+
self._check_feature_names(X, reset=False)
|
|
175
|
+
return dispatch(
|
|
176
|
+
self,
|
|
177
|
+
"score",
|
|
178
|
+
{
|
|
179
|
+
"onedal": self.__class__._onedal_score,
|
|
180
|
+
"sklearn": sklearn_LogisticRegression.score,
|
|
181
|
+
},
|
|
182
|
+
X,
|
|
183
|
+
y,
|
|
184
|
+
sample_weight=sample_weight,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
def _onedal_score(self, X, y, sample_weight=None, queue=None):
|
|
188
|
+
return accuracy_score(
|
|
189
|
+
y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
|
|
190
|
+
)
|
|
191
|
+
|
|
163
192
|
def _test_type_and_finiteness(self, X_in):
|
|
164
193
|
X = np.asarray(X_in)
|
|
165
194
|
|
|
@@ -185,7 +214,10 @@ if daal_check_version((2024, "P", 1)):
|
|
|
185
214
|
[
|
|
186
215
|
(self.penalty == "l2", "Only l2 penalty is supported."),
|
|
187
216
|
(self.dual == False, "dual=True is not supported."),
|
|
188
|
-
(
|
|
217
|
+
(
|
|
218
|
+
self.intercept_scaling == 1,
|
|
219
|
+
"Intercept scaling is not supported.",
|
|
220
|
+
),
|
|
189
221
|
(self.class_weight is None, "Class weight is not supported"),
|
|
190
222
|
(self.solver == "newton-cg", "Only newton-cg solver is supported."),
|
|
191
223
|
(
|
|
@@ -195,6 +227,10 @@ if daal_check_version((2024, "P", 1)):
|
|
|
195
227
|
(self.warm_start == False, "Warm start is not supported."),
|
|
196
228
|
(self.l1_ratio is None, "l1 ratio is not supported."),
|
|
197
229
|
(sample_weight is None, "Sample weight is not supported."),
|
|
230
|
+
(
|
|
231
|
+
type_of_target(y) == "binary",
|
|
232
|
+
"Only binary classification is supported",
|
|
233
|
+
),
|
|
198
234
|
]
|
|
199
235
|
)
|
|
200
236
|
|
|
@@ -213,24 +249,34 @@ if daal_check_version((2024, "P", 1)):
|
|
|
213
249
|
return patching_status
|
|
214
250
|
|
|
215
251
|
def _onedal_gpu_predict_supported(self, method_name, *data):
|
|
216
|
-
assert method_name in [
|
|
217
|
-
|
|
252
|
+
assert method_name in [
|
|
253
|
+
"predict",
|
|
254
|
+
"predict_proba",
|
|
255
|
+
"predict_log_proba",
|
|
256
|
+
"score",
|
|
257
|
+
]
|
|
218
258
|
|
|
219
259
|
class_name = self.__class__.__name__
|
|
220
260
|
patching_status = PatchingConditionsChain(
|
|
221
261
|
f"sklearn.linear_model.{class_name}.{method_name}"
|
|
222
262
|
)
|
|
223
263
|
|
|
224
|
-
n_samples = _num_samples(
|
|
264
|
+
n_samples = _num_samples(data[0])
|
|
225
265
|
model_is_sparse = issparse(self.coef_) or (
|
|
226
266
|
self.fit_intercept and issparse(self.intercept_)
|
|
227
267
|
)
|
|
228
268
|
dal_ready = patching_status.and_conditions(
|
|
229
269
|
[
|
|
230
270
|
(n_samples > 0, "Number of samples is less than 1."),
|
|
231
|
-
(
|
|
271
|
+
(
|
|
272
|
+
not any([issparse(i) for i in data]),
|
|
273
|
+
"Sparse input is not supported.",
|
|
274
|
+
),
|
|
232
275
|
(not model_is_sparse, "Sparse coefficients are not supported."),
|
|
233
|
-
(
|
|
276
|
+
(
|
|
277
|
+
hasattr(self, "_onedal_estimator"),
|
|
278
|
+
"oneDAL model was not trained.",
|
|
279
|
+
),
|
|
234
280
|
]
|
|
235
281
|
)
|
|
236
282
|
if not dal_ready:
|
|
@@ -245,7 +291,7 @@ if daal_check_version((2024, "P", 1)):
|
|
|
245
291
|
def _onedal_gpu_supported(self, method_name, *data):
|
|
246
292
|
if method_name == "fit":
|
|
247
293
|
return self._onedal_gpu_fit_supported(method_name, *data)
|
|
248
|
-
if method_name in ["predict", "predict_proba", "predict_log_proba"]:
|
|
294
|
+
if method_name in ["predict", "predict_proba", "predict_log_proba", "score"]:
|
|
249
295
|
return self._onedal_gpu_predict_supported(method_name, *data)
|
|
250
296
|
raise RuntimeError(
|
|
251
297
|
f"Unknown method {method_name} in {self.__class__.__name__}"
|
|
@@ -324,6 +370,12 @@ if daal_check_version((2024, "P", 1)):
|
|
|
324
370
|
assert hasattr(self, "_onedal_estimator")
|
|
325
371
|
return self._onedal_estimator.predict_log_proba(X, queue=queue)
|
|
326
372
|
|
|
373
|
+
fit.__doc__ = sklearn_LogisticRegression.fit.__doc__
|
|
374
|
+
predict.__doc__ = sklearn_LogisticRegression.predict.__doc__
|
|
375
|
+
predict_proba.__doc__ = sklearn_LogisticRegression.predict_proba.__doc__
|
|
376
|
+
predict_log_proba.__doc__ = sklearn_LogisticRegression.predict_log_proba.__doc__
|
|
377
|
+
score.__doc__ = sklearn_LogisticRegression.score.__doc__
|
|
378
|
+
|
|
327
379
|
else:
|
|
328
380
|
LogisticRegression = LogisticRegression_daal4py
|
|
329
381
|
|
|
@@ -28,26 +28,33 @@ from onedal.tests.utils._dataframes_support import (
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
31
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
31
32
|
@pytest.mark.parametrize("macro_block", [None, 1024])
|
|
32
|
-
def test_sklearnex_import_linear(dataframe, queue, macro_block):
|
|
33
|
+
def test_sklearnex_import_linear(dataframe, queue, dtype, macro_block):
|
|
33
34
|
from sklearnex.linear_model import LinearRegression
|
|
34
35
|
|
|
35
36
|
X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
|
|
36
37
|
y = np.dot(X, np.array([1, 2])) + 3
|
|
38
|
+
X = X.astype(dtype=dtype)
|
|
39
|
+
y = y.astype(dtype=dtype)
|
|
37
40
|
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
38
41
|
y = _convert_to_dataframe(y, sycl_queue=queue, target_df=dataframe)
|
|
42
|
+
|
|
39
43
|
linreg = LinearRegression()
|
|
40
44
|
if daal_check_version((2024, "P", 0)) and macro_block is not None:
|
|
41
45
|
hparams = linreg.get_hyperparameters("fit")
|
|
42
46
|
hparams.cpu_macro_block = macro_block
|
|
43
47
|
hparams.gpu_macro_block = macro_block
|
|
48
|
+
|
|
44
49
|
linreg.fit(X, y)
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
|
|
51
|
+
assert hasattr(linreg, "_onedal_estimator")
|
|
47
52
|
assert "sklearnex" in linreg.__module__
|
|
48
53
|
assert linreg.n_features_in_ == 2
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
|
|
55
|
+
tol = 1e-5 if X.dtype == np.float32 else 1e-7
|
|
56
|
+
assert_allclose(_as_numpy(linreg.intercept_), 3.0, rtol=tol)
|
|
57
|
+
assert_allclose(_as_numpy(linreg.coef_), [1.0, 2.0], rtol=tol)
|
|
51
58
|
|
|
52
59
|
|
|
53
60
|
def test_sklearnex_import_ridge():
|
|
@@ -80,3 +87,31 @@ def test_sklearnex_import_elastic():
|
|
|
80
87
|
assert "daal4py" in elasticnet.__module__
|
|
81
88
|
assert_allclose(elasticnet.intercept_, 1.451, atol=1e-3)
|
|
82
89
|
assert_allclose(elasticnet.coef_, [18.838, 64.559], atol=1e-3)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
93
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
94
|
+
def test_sklearnex_reconstruct_model(dataframe, queue, dtype):
|
|
95
|
+
from sklearnex.linear_model import LinearRegression
|
|
96
|
+
|
|
97
|
+
seed = 42
|
|
98
|
+
num_samples = 3500
|
|
99
|
+
num_features, num_targets = 14, 9
|
|
100
|
+
|
|
101
|
+
gen = np.random.default_rng(seed)
|
|
102
|
+
intercept = gen.random(size=num_targets, dtype=dtype)
|
|
103
|
+
coef = gen.random(size=(num_targets, num_features), dtype=dtype).T
|
|
104
|
+
|
|
105
|
+
X = gen.random(size=(num_samples, num_features), dtype=dtype)
|
|
106
|
+
gtr = X @ coef + intercept[np.newaxis, :]
|
|
107
|
+
|
|
108
|
+
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
109
|
+
|
|
110
|
+
linreg = LinearRegression(fit_intercept=True)
|
|
111
|
+
linreg.coef_ = coef.T
|
|
112
|
+
linreg.intercept_ = intercept
|
|
113
|
+
|
|
114
|
+
y_pred = linreg.predict(X)
|
|
115
|
+
|
|
116
|
+
tol = 1e-5 if X.dtype == np.float32 else 1e-7
|
|
117
|
+
assert_allclose(gtr, _as_numpy(y_pred), rtol=tol)
|
|
@@ -14,9 +14,7 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
# ===============================================================================
|
|
16
16
|
|
|
17
|
-
import numpy as np
|
|
18
17
|
import pytest
|
|
19
|
-
from numpy.testing import assert_allclose
|
|
20
18
|
from sklearn.datasets import load_breast_cancer, load_iris
|
|
21
19
|
from sklearn.metrics import accuracy_score
|
|
22
20
|
from sklearn.model_selection import train_test_split
|
|
@@ -23,13 +23,13 @@ from sklearn.utils.validation import check_is_fitted
|
|
|
23
23
|
|
|
24
24
|
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
25
25
|
from daal4py.sklearn._utils import sklearn_check_version
|
|
26
|
+
from sklearnex._device_offload import dispatch, wrap_output_data
|
|
27
|
+
from sklearnex.neighbors.common import KNeighborsDispatchingBase
|
|
28
|
+
from sklearnex.neighbors.knn_unsupervised import NearestNeighbors
|
|
29
|
+
from sklearnex.utils import get_namespace
|
|
26
30
|
|
|
27
|
-
from .._device_offload import dispatch, wrap_output_data
|
|
28
|
-
from .common import KNeighborsDispatchingBase
|
|
29
|
-
from .knn_unsupervised import NearestNeighbors
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
@control_n_jobs(decorated_methods=["fit", "kneighbors"])
|
|
32
|
+
@control_n_jobs(decorated_methods=["fit", "_kneighbors"])
|
|
33
33
|
class LocalOutlierFactor(KNeighborsDispatchingBase, sklearn_LocalOutlierFactor):
|
|
34
34
|
__doc__ = (
|
|
35
35
|
sklearn_LocalOutlierFactor.__doc__
|
|
@@ -100,7 +100,6 @@ class LocalOutlierFactor(KNeighborsDispatchingBase, sklearn_LocalOutlierFactor):
|
|
|
100
100
|
return self
|
|
101
101
|
|
|
102
102
|
def fit(self, X, y=None):
|
|
103
|
-
self._fit_validation(X, y)
|
|
104
103
|
result = dispatch(
|
|
105
104
|
self,
|
|
106
105
|
"fit",
|
|
@@ -113,16 +112,13 @@ class LocalOutlierFactor(KNeighborsDispatchingBase, sklearn_LocalOutlierFactor):
|
|
|
113
112
|
)
|
|
114
113
|
return result
|
|
115
114
|
|
|
116
|
-
# Subtle order change to remove check_array and preserve dpnp and
|
|
117
|
-
# dpctl conformance. decision_function will return a dpnp or dpctl
|
|
118
|
-
# instance via kneighbors and an equivalent check_array exists in
|
|
119
|
-
# that call already in sklearn so no loss of functionality occurs
|
|
120
115
|
def _predict(self, X=None):
|
|
121
116
|
check_is_fitted(self)
|
|
122
117
|
|
|
123
118
|
if X is not None:
|
|
119
|
+
xp, _ = get_namespace(X)
|
|
124
120
|
output = self.decision_function(X) < 0
|
|
125
|
-
is_inlier =
|
|
121
|
+
is_inlier = xp.ones_like(output, dtype=int)
|
|
126
122
|
is_inlier[output] = -1
|
|
127
123
|
else:
|
|
128
124
|
is_inlier = np.ones(self.n_samples_fit_, dtype=int)
|
|
@@ -137,15 +133,29 @@ class LocalOutlierFactor(KNeighborsDispatchingBase, sklearn_LocalOutlierFactor):
|
|
|
137
133
|
@available_if(sklearn_LocalOutlierFactor._check_novelty_fit_predict)
|
|
138
134
|
@wrap_output_data
|
|
139
135
|
def fit_predict(self, X, y=None):
|
|
136
|
+
"""Fit the model to the training set X and return the labels.
|
|
137
|
+
|
|
138
|
+
**Not available for novelty detection (when novelty is set to True).**
|
|
139
|
+
Label is 1 for an inlier and -1 for an outlier according to the LOF
|
|
140
|
+
score and the contamination parameter.
|
|
141
|
+
|
|
142
|
+
Parameters
|
|
143
|
+
----------
|
|
144
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features), default=None
|
|
145
|
+
The query sample or samples to compute the Local Outlier Factor
|
|
146
|
+
w.r.t. the training samples.
|
|
147
|
+
|
|
148
|
+
y : Ignored
|
|
149
|
+
Not used, present for API consistency by convention.
|
|
150
|
+
|
|
151
|
+
Returns
|
|
152
|
+
-------
|
|
153
|
+
is_inlier : ndarray of shape (n_samples,)
|
|
154
|
+
Returns -1 for anomalies/outliers and 1 for inliers.
|
|
155
|
+
"""
|
|
140
156
|
return self.fit(X)._predict()
|
|
141
157
|
|
|
142
|
-
|
|
143
|
-
@wrap_output_data
|
|
144
|
-
def predict(self, X=None):
|
|
145
|
-
return self._predict(X)
|
|
146
|
-
|
|
147
|
-
@wrap_output_data
|
|
148
|
-
def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
|
|
158
|
+
def _kneighbors(self, X=None, n_neighbors=None, return_distance=True):
|
|
149
159
|
check_is_fitted(self)
|
|
150
160
|
if sklearn_check_version("1.0") and X is not None:
|
|
151
161
|
self._check_feature_names(X, reset=False)
|
|
@@ -161,7 +171,51 @@ class LocalOutlierFactor(KNeighborsDispatchingBase, sklearn_LocalOutlierFactor):
|
|
|
161
171
|
return_distance=return_distance,
|
|
162
172
|
)
|
|
163
173
|
|
|
174
|
+
kneighbors = wrap_output_data(_kneighbors)
|
|
175
|
+
|
|
176
|
+
@available_if(sklearn_LocalOutlierFactor._check_novelty_score_samples)
|
|
177
|
+
@wrap_output_data
|
|
178
|
+
def score_samples(self, X):
|
|
179
|
+
"""Opposite of the Local Outlier Factor of X.
|
|
180
|
+
|
|
181
|
+
It is the opposite as bigger is better, i.e. large values correspond
|
|
182
|
+
to inliers.
|
|
183
|
+
|
|
184
|
+
**Only available for novelty detection (when novelty is set to True).**
|
|
185
|
+
The argument X is supposed to contain *new data*: if X contains a
|
|
186
|
+
point from training, it considers the later in its own neighborhood.
|
|
187
|
+
Also, the samples in X are not considered in the neighborhood of any
|
|
188
|
+
point. Because of this, the scores obtained via ``score_samples`` may
|
|
189
|
+
differ from the standard LOF scores.
|
|
190
|
+
The standard LOF scores for the training data is available via the
|
|
191
|
+
``negative_outlier_factor_`` attribute.
|
|
192
|
+
|
|
193
|
+
Parameters
|
|
194
|
+
----------
|
|
195
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
196
|
+
The query sample or samples to compute the Local Outlier Factor
|
|
197
|
+
w.r.t. the training samples.
|
|
198
|
+
|
|
199
|
+
Returns
|
|
200
|
+
-------
|
|
201
|
+
opposite_lof_scores : ndarray of shape (n_samples,)
|
|
202
|
+
The opposite of the Local Outlier Factor of each input samples.
|
|
203
|
+
The lower, the more abnormal.
|
|
204
|
+
"""
|
|
205
|
+
check_is_fitted(self)
|
|
206
|
+
|
|
207
|
+
distances_X, neighbors_indices_X = self._kneighbors(
|
|
208
|
+
X, n_neighbors=self.n_neighbors_
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
X_lrd = self._local_reachability_density(
|
|
212
|
+
distances_X,
|
|
213
|
+
neighbors_indices_X,
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
lrd_ratios_array = self._lrd[neighbors_indices_X] / X_lrd[:, np.newaxis]
|
|
217
|
+
|
|
218
|
+
return -np.mean(lrd_ratios_array, axis=1)
|
|
219
|
+
|
|
164
220
|
fit.__doc__ = sklearn_LocalOutlierFactor.fit.__doc__
|
|
165
|
-
fit_predict.__doc__ = sklearn_LocalOutlierFactor.fit_predict.__doc__
|
|
166
|
-
predict.__doc__ = sklearn_LocalOutlierFactor.predict.__doc__
|
|
167
221
|
kneighbors.__doc__ = sklearn_LocalOutlierFactor.kneighbors.__doc__
|
|
@@ -137,6 +137,9 @@ class KNeighborsDispatchingBase:
|
|
|
137
137
|
self.n_features_in_ = X.data.shape[1]
|
|
138
138
|
|
|
139
139
|
def _onedal_supported(self, device, method_name, *data):
|
|
140
|
+
if method_name == "fit":
|
|
141
|
+
self._fit_validation(data[0], data[1])
|
|
142
|
+
|
|
140
143
|
class_name = self.__class__.__name__
|
|
141
144
|
is_classifier = "Classifier" in class_name
|
|
142
145
|
is_regressor = "Regressor" in class_name
|
|
@@ -249,7 +252,7 @@ class KNeighborsDispatchingBase:
|
|
|
249
252
|
class_count >= 2, "One-class case is not supported."
|
|
250
253
|
)
|
|
251
254
|
return patching_status
|
|
252
|
-
if method_name in ["predict", "predict_proba", "kneighbors"]:
|
|
255
|
+
if method_name in ["predict", "predict_proba", "kneighbors", "score"]:
|
|
253
256
|
patching_status.and_condition(
|
|
254
257
|
hasattr(self, "_onedal_estimator"), "oneDAL model was not trained."
|
|
255
258
|
)
|
|
@@ -14,137 +14,30 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
# ===============================================================================
|
|
16
16
|
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
from sklearn.neighbors._ball_tree import BallTree
|
|
20
|
-
from sklearn.neighbors._base import NeighborsBase as sklearn_NeighborsBase
|
|
21
|
-
from sklearn.neighbors._kd_tree import KDTree
|
|
22
|
-
|
|
23
|
-
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
24
|
-
from daal4py.sklearn._utils import sklearn_check_version
|
|
25
|
-
|
|
26
|
-
if not sklearn_check_version("1.2"):
|
|
27
|
-
from sklearn.neighbors._base import _check_weights
|
|
28
|
-
|
|
29
|
-
import numpy as np
|
|
30
|
-
from sklearn.neighbors._base import VALID_METRICS
|
|
17
|
+
from sklearn.metrics import accuracy_score
|
|
31
18
|
from sklearn.neighbors._classification import (
|
|
32
19
|
KNeighborsClassifier as sklearn_KNeighborsClassifier,
|
|
33
20
|
)
|
|
34
21
|
from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestNeighbors
|
|
35
22
|
from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted
|
|
36
23
|
|
|
24
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
25
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
37
26
|
from onedal.neighbors import KNeighborsClassifier as onedal_KNeighborsClassifier
|
|
38
|
-
from onedal.utils import _check_array, _num_features, _num_samples
|
|
39
27
|
|
|
40
28
|
from .._device_offload import dispatch, wrap_output_data
|
|
41
29
|
from .common import KNeighborsDispatchingBase
|
|
42
30
|
|
|
43
|
-
if sklearn_check_version("0.24"):
|
|
44
|
-
|
|
45
|
-
class KNeighborsClassifier_(sklearn_KNeighborsClassifier):
|
|
46
|
-
if sklearn_check_version("1.2"):
|
|
47
|
-
_parameter_constraints: dict = {
|
|
48
|
-
**sklearn_KNeighborsClassifier._parameter_constraints
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@_deprecate_positional_args
|
|
52
|
-
def __init__(
|
|
53
|
-
self,
|
|
54
|
-
n_neighbors=5,
|
|
55
|
-
*,
|
|
56
|
-
weights="uniform",
|
|
57
|
-
algorithm="auto",
|
|
58
|
-
leaf_size=30,
|
|
59
|
-
p=2,
|
|
60
|
-
metric="minkowski",
|
|
61
|
-
metric_params=None,
|
|
62
|
-
n_jobs=None,
|
|
63
|
-
**kwargs,
|
|
64
|
-
):
|
|
65
|
-
super().__init__(
|
|
66
|
-
n_neighbors=n_neighbors,
|
|
67
|
-
algorithm=algorithm,
|
|
68
|
-
leaf_size=leaf_size,
|
|
69
|
-
metric=metric,
|
|
70
|
-
p=p,
|
|
71
|
-
metric_params=metric_params,
|
|
72
|
-
n_jobs=n_jobs,
|
|
73
|
-
**kwargs,
|
|
74
|
-
)
|
|
75
|
-
self.weights = (
|
|
76
|
-
weights if sklearn_check_version("1.0") else _check_weights(weights)
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
elif sklearn_check_version("0.22"):
|
|
80
|
-
from sklearn.neighbors._base import (
|
|
81
|
-
SupervisedIntegerMixin as BaseSupervisedIntegerMixin,
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
class KNeighborsClassifier_(sklearn_KNeighborsClassifier, BaseSupervisedIntegerMixin):
|
|
85
|
-
@_deprecate_positional_args
|
|
86
|
-
def __init__(
|
|
87
|
-
self,
|
|
88
|
-
n_neighbors=5,
|
|
89
|
-
*,
|
|
90
|
-
weights="uniform",
|
|
91
|
-
algorithm="auto",
|
|
92
|
-
leaf_size=30,
|
|
93
|
-
p=2,
|
|
94
|
-
metric="minkowski",
|
|
95
|
-
metric_params=None,
|
|
96
|
-
n_jobs=None,
|
|
97
|
-
**kwargs,
|
|
98
|
-
):
|
|
99
|
-
super().__init__(
|
|
100
|
-
n_neighbors=n_neighbors,
|
|
101
|
-
algorithm=algorithm,
|
|
102
|
-
leaf_size=leaf_size,
|
|
103
|
-
metric=metric,
|
|
104
|
-
p=p,
|
|
105
|
-
metric_params=metric_params,
|
|
106
|
-
n_jobs=n_jobs,
|
|
107
|
-
**kwargs,
|
|
108
|
-
)
|
|
109
|
-
self.weights = _check_weights(weights)
|
|
110
|
-
|
|
111
|
-
else:
|
|
112
|
-
from sklearn.neighbors.base import (
|
|
113
|
-
SupervisedIntegerMixin as BaseSupervisedIntegerMixin,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
class KNeighborsClassifier_(sklearn_KNeighborsClassifier, BaseSupervisedIntegerMixin):
|
|
117
|
-
@_deprecate_positional_args
|
|
118
|
-
def __init__(
|
|
119
|
-
self,
|
|
120
|
-
n_neighbors=5,
|
|
121
|
-
*,
|
|
122
|
-
weights="uniform",
|
|
123
|
-
algorithm="auto",
|
|
124
|
-
leaf_size=30,
|
|
125
|
-
p=2,
|
|
126
|
-
metric="minkowski",
|
|
127
|
-
metric_params=None,
|
|
128
|
-
n_jobs=None,
|
|
129
|
-
**kwargs,
|
|
130
|
-
):
|
|
131
|
-
super().__init__(
|
|
132
|
-
n_neighbors=n_neighbors,
|
|
133
|
-
algorithm=algorithm,
|
|
134
|
-
leaf_size=leaf_size,
|
|
135
|
-
metric=metric,
|
|
136
|
-
p=p,
|
|
137
|
-
metric_params=metric_params,
|
|
138
|
-
n_jobs=n_jobs,
|
|
139
|
-
**kwargs,
|
|
140
|
-
)
|
|
141
|
-
self.weights = _check_weights(weights)
|
|
142
|
-
|
|
143
31
|
|
|
144
|
-
@control_n_jobs(
|
|
145
|
-
|
|
32
|
+
@control_n_jobs(
|
|
33
|
+
decorated_methods=["fit", "predict", "predict_proba", "kneighbors", "score"]
|
|
34
|
+
)
|
|
35
|
+
class KNeighborsClassifier(sklearn_KNeighborsClassifier, KNeighborsDispatchingBase):
|
|
36
|
+
__doc__ = sklearn_KNeighborsClassifier.__doc__
|
|
146
37
|
if sklearn_check_version("1.2"):
|
|
147
|
-
_parameter_constraints: dict = {
|
|
38
|
+
_parameter_constraints: dict = {
|
|
39
|
+
**sklearn_KNeighborsClassifier._parameter_constraints
|
|
40
|
+
}
|
|
148
41
|
|
|
149
42
|
if sklearn_check_version("1.0"):
|
|
150
43
|
|
|
@@ -200,7 +93,6 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
200
93
|
)
|
|
201
94
|
|
|
202
95
|
def fit(self, X, y):
|
|
203
|
-
self._fit_validation(X, y)
|
|
204
96
|
dispatch(
|
|
205
97
|
self,
|
|
206
98
|
"fit",
|
|
@@ -243,6 +135,23 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
243
135
|
X,
|
|
244
136
|
)
|
|
245
137
|
|
|
138
|
+
@wrap_output_data
|
|
139
|
+
def score(self, X, y, sample_weight=None):
|
|
140
|
+
check_is_fitted(self)
|
|
141
|
+
if sklearn_check_version("1.0"):
|
|
142
|
+
self._check_feature_names(X, reset=False)
|
|
143
|
+
return dispatch(
|
|
144
|
+
self,
|
|
145
|
+
"score",
|
|
146
|
+
{
|
|
147
|
+
"onedal": self.__class__._onedal_score,
|
|
148
|
+
"sklearn": sklearn_KNeighborsClassifier.score,
|
|
149
|
+
},
|
|
150
|
+
X,
|
|
151
|
+
y,
|
|
152
|
+
sample_weight=sample_weight,
|
|
153
|
+
)
|
|
154
|
+
|
|
246
155
|
@wrap_output_data
|
|
247
156
|
def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
|
|
248
157
|
check_is_fitted(self)
|
|
@@ -271,18 +180,10 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
271
180
|
or getattr(self, "_tree", 0) is None
|
|
272
181
|
and self._fit_method == "kd_tree"
|
|
273
182
|
):
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if sklearn_check_version("0.22"):
|
|
279
|
-
result = sklearn_NearestNeighbors.radius_neighbors(
|
|
280
|
-
self, X, radius, return_distance, sort_results
|
|
281
|
-
)
|
|
282
|
-
else:
|
|
283
|
-
result = sklearn_NearestNeighbors.radius_neighbors(
|
|
284
|
-
self, X, radius, return_distance
|
|
285
|
-
)
|
|
183
|
+
sklearn_NearestNeighbors.fit(self, self._fit_X, getattr(self, "_y", None))
|
|
184
|
+
result = sklearn_NearestNeighbors.radius_neighbors(
|
|
185
|
+
self, X, radius, return_distance, sort_results
|
|
186
|
+
)
|
|
286
187
|
|
|
287
188
|
return result
|
|
288
189
|
|
|
@@ -321,6 +222,11 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
321
222
|
X, n_neighbors, return_distance, queue=queue
|
|
322
223
|
)
|
|
323
224
|
|
|
225
|
+
def _onedal_score(self, X, y, sample_weight=None, queue=None):
|
|
226
|
+
return accuracy_score(
|
|
227
|
+
y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
|
|
228
|
+
)
|
|
229
|
+
|
|
324
230
|
def _save_attributes(self):
|
|
325
231
|
self.classes_ = self._onedal_estimator.classes_
|
|
326
232
|
self.n_features_in_ = self._onedal_estimator.n_features_in_
|
|
@@ -330,3 +236,10 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
330
236
|
self._fit_method = self._onedal_estimator._fit_method
|
|
331
237
|
self.outputs_2d_ = self._onedal_estimator.outputs_2d_
|
|
332
238
|
self._tree = self._onedal_estimator._tree
|
|
239
|
+
|
|
240
|
+
fit.__doc__ = sklearn_KNeighborsClassifier.fit.__doc__
|
|
241
|
+
predict.__doc__ = sklearn_KNeighborsClassifier.predict.__doc__
|
|
242
|
+
predict_proba.__doc__ = sklearn_KNeighborsClassifier.predict_proba.__doc__
|
|
243
|
+
score.__doc__ = sklearn_KNeighborsClassifier.score.__doc__
|
|
244
|
+
kneighbors.__doc__ = sklearn_KNeighborsClassifier.kneighbors.__doc__
|
|
245
|
+
radius_neighbors.__doc__ = sklearn_NearestNeighbors.radius_neighbors.__doc__
|