scikit-learn-intelex 2024.1.0__py39-none-win_amd64.whl → 2024.3.0__py39-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.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/__init__.py +9 -7
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/cluster/dbscan.py +6 -4
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/conftest.py +63 -0
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/covariance/__init__.py +19 -0
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/covariance/incremental_covariance.py +130 -0
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/covariance/tests/test_incremental_covariance.py +143 -0
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/decomposition/pca.py +338 -0
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/preview/decomposition/tests/test_preview_pca.py → scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/decomposition/tests/test_pca.py +22 -8
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/dispatcher.py +91 -59
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/ensemble/_forest.py +15 -24
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/ensemble/tests/test_forest.py +15 -19
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/linear_model/__init__.py +1 -2
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/linear_model/linear.py +3 -10
- {scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/preview → scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex}/linear_model/logistic_regression.py +32 -40
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/linear_model/tests/test_logreg.py +91 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/neighbors/__init__.py +1 -1
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/neighbors/_lof.py +204 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_classification.py +13 -18
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_regression.py +12 -17
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_unsupervised.py +10 -15
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/neighbors/tests/test_neighbors.py +12 -16
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/preview/__init__.py +1 -1
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/k_means.py +3 -8
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/covariance.py +46 -12
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/__init__.py +1 -0
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/spmd/covariance/__init__.py +19 -0
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/spmd/covariance/covariance.py +21 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/ensemble/forest.py +4 -12
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/linear_model/__init__.py +2 -1
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/spmd/linear_model/logistic_regression.py +21 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/svm/nusvc.py +9 -6
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/svm/nusvr.py +6 -7
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/svm/svc.py +9 -6
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/svm/svr.py +3 -4
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/tests/_utils.py +155 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/tests/test_memory_usage.py +9 -7
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/tests/test_monkeypatch.py +268 -0
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/tests/test_n_jobs_support.py +93 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/tests/test_parallel.py +6 -8
- scikit_learn_intelex-2024.3.0.data/data/Lib/site-packages/sklearnex/tests/test_patching.py +361 -0
- {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.3.0.dist-info}/METADATA +2 -2
- scikit_learn_intelex-2024.3.0.dist-info/RECORD +98 -0
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/decomposition/pca.py +0 -17
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/decomposition/tests/test_pca.py +0 -27
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/linear_model/tests/test_logreg.py +0 -28
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/neighbors/lof.py +0 -436
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/preview/decomposition/__init__.py +0 -19
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/preview/decomposition/pca.py +0 -376
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/preview/linear_model/__init__.py +0 -19
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/preview/linear_model/tests/test_preview_logistic_regression.py +0 -59
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/tests/_models_info.py +0 -170
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/tests/test_monkeypatch.py +0 -227
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/tests/test_n_jobs_support.py +0 -31
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/tests/test_patching.py +0 -122
- scikit_learn_intelex-2024.1.0.data/data/Lib/site-packages/sklearnex/tests/utils/_launch_algorithms.py +0 -118
- scikit_learn_intelex-2024.1.0.dist-info/RECORD +0 -97
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/__main__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/_config.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/_device_offload.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/_utils.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/basic_statistics/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/basic_statistics/basic_statistics.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/cluster/k_means.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/cluster/tests/test_dbscan.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/cluster/tests/test_kmeans.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/decomposition/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/doc/third-party-programs.txt +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/ensemble/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/glob/__main__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/glob/dispatcher.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/linear_model/coordinate_descent.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/linear_model/logistic_path.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/linear_model/ridge.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/linear_model/tests/test_linear.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/manifold/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/manifold/t_sne.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/manifold/tests/test_tsne.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/metrics/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/metrics/pairwise.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/metrics/ranking.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/metrics/tests/test_metrics.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/model_selection/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/model_selection/split.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/model_selection/tests/test_model_selection.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/neighbors/common.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/_common.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/preview/covariance/tests/test_covariance.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/basic_statistics/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/basic_statistics/basic_statistics.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/dbscan.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/kmeans.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/decomposition/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/decomposition/pca.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/ensemble/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/linear_model/linear_model.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/neighbors/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/spmd/neighbors/neighbors.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/svm/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/svm/_common.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/svm/tests/test_svm.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/tests/test_config.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/tests/test_run_to_run_stability_tests.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/utils/__init__.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/utils/parallel.py +0 -0
- {scikit_learn_intelex-2024.1.0.data → scikit_learn_intelex-2024.3.0.data}/data/Lib/site-packages/sklearnex/utils/validation.py +0 -0
- {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.3.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.3.0.dist-info}/WHEEL +0 -0
- {scikit_learn_intelex-2024.1.0.dist-info → scikit_learn_intelex-2024.3.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,204 @@
|
|
|
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 warnings
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
from sklearn.neighbors import LocalOutlierFactor as sklearn_LocalOutlierFactor
|
|
21
|
+
from sklearn.utils.metaestimators import available_if
|
|
22
|
+
from sklearn.utils.validation import check_is_fitted
|
|
23
|
+
|
|
24
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
25
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
26
|
+
|
|
27
|
+
from .._device_offload import dispatch, wrap_output_data
|
|
28
|
+
from .common import KNeighborsDispatchingBase
|
|
29
|
+
from .knn_unsupervised import NearestNeighbors
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@control_n_jobs(decorated_methods=["fit", "kneighbors"])
|
|
33
|
+
class LocalOutlierFactor(KNeighborsDispatchingBase, sklearn_LocalOutlierFactor):
|
|
34
|
+
__doc__ = (
|
|
35
|
+
sklearn_LocalOutlierFactor.__doc__
|
|
36
|
+
+ "\n NOTE: When X=None, methods kneighbors, kneighbors_graph, and predict will"
|
|
37
|
+
+ "\n only output numpy arrays. In that case, the only way to offload to gpu"
|
|
38
|
+
+ "\n is to use a global queue (e.g. using config_context)"
|
|
39
|
+
)
|
|
40
|
+
if sklearn_check_version("1.2"):
|
|
41
|
+
_parameter_constraints: dict = {
|
|
42
|
+
**sklearn_LocalOutlierFactor._parameter_constraints
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# Only certain methods should be taken from knn to prevent code
|
|
46
|
+
# duplication. Inheriting would yield a complicated inheritance
|
|
47
|
+
# structure and violate the sklearn inheritance path.
|
|
48
|
+
_save_attributes = NearestNeighbors._save_attributes
|
|
49
|
+
_onedal_knn_fit = NearestNeighbors._onedal_fit
|
|
50
|
+
_onedal_kneighbors = NearestNeighbors._onedal_kneighbors
|
|
51
|
+
|
|
52
|
+
def _onedal_fit(self, X, y, queue=None):
|
|
53
|
+
if sklearn_check_version("1.2"):
|
|
54
|
+
self._validate_params()
|
|
55
|
+
|
|
56
|
+
self._onedal_knn_fit(X, y, queue)
|
|
57
|
+
|
|
58
|
+
if self.contamination != "auto":
|
|
59
|
+
if not (0.0 < self.contamination <= 0.5):
|
|
60
|
+
raise ValueError(
|
|
61
|
+
"contamination must be in (0, 0.5], " "got: %f" % self.contamination
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
n_samples = self.n_samples_fit_
|
|
65
|
+
|
|
66
|
+
if self.n_neighbors > n_samples:
|
|
67
|
+
warnings.warn(
|
|
68
|
+
"n_neighbors (%s) is greater than the "
|
|
69
|
+
"total number of samples (%s). n_neighbors "
|
|
70
|
+
"will be set to (n_samples - 1) for estimation."
|
|
71
|
+
% (self.n_neighbors, n_samples)
|
|
72
|
+
)
|
|
73
|
+
self.n_neighbors_ = max(1, min(self.n_neighbors, n_samples - 1))
|
|
74
|
+
|
|
75
|
+
(
|
|
76
|
+
self._distances_fit_X_,
|
|
77
|
+
_neighbors_indices_fit_X_,
|
|
78
|
+
) = self._onedal_kneighbors(n_neighbors=self.n_neighbors_, queue=queue)
|
|
79
|
+
|
|
80
|
+
# Sklearn includes a check for float32 at this point which may not be
|
|
81
|
+
# necessary for onedal
|
|
82
|
+
|
|
83
|
+
self._lrd = self._local_reachability_density(
|
|
84
|
+
self._distances_fit_X_, _neighbors_indices_fit_X_
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# Compute lof score over training samples to define offset_:
|
|
88
|
+
lrd_ratios_array = self._lrd[_neighbors_indices_fit_X_] / self._lrd[:, np.newaxis]
|
|
89
|
+
|
|
90
|
+
self.negative_outlier_factor_ = -np.mean(lrd_ratios_array, axis=1)
|
|
91
|
+
|
|
92
|
+
if self.contamination == "auto":
|
|
93
|
+
# inliers score around -1 (the higher, the less abnormal).
|
|
94
|
+
self.offset_ = -1.5
|
|
95
|
+
else:
|
|
96
|
+
self.offset_ = np.percentile(
|
|
97
|
+
self.negative_outlier_factor_, 100.0 * self.contamination
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
return self
|
|
101
|
+
|
|
102
|
+
def fit(self, X, y=None):
|
|
103
|
+
self._fit_validation(X, y)
|
|
104
|
+
result = dispatch(
|
|
105
|
+
self,
|
|
106
|
+
"fit",
|
|
107
|
+
{
|
|
108
|
+
"onedal": self.__class__._onedal_fit,
|
|
109
|
+
"sklearn": sklearn_LocalOutlierFactor.fit,
|
|
110
|
+
},
|
|
111
|
+
X,
|
|
112
|
+
None,
|
|
113
|
+
)
|
|
114
|
+
return result
|
|
115
|
+
|
|
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
|
+
def _predict(self, X=None):
|
|
121
|
+
check_is_fitted(self)
|
|
122
|
+
|
|
123
|
+
if X is not None:
|
|
124
|
+
output = self.decision_function(X) < 0
|
|
125
|
+
is_inlier = np.ones(output.shape[0], dtype=int)
|
|
126
|
+
is_inlier[output] = -1
|
|
127
|
+
else:
|
|
128
|
+
is_inlier = np.ones(self.n_samples_fit_, dtype=int)
|
|
129
|
+
is_inlier[self.negative_outlier_factor_ < self.offset_] = -1
|
|
130
|
+
|
|
131
|
+
return is_inlier
|
|
132
|
+
|
|
133
|
+
# This had to be done because predict loses the queue when no
|
|
134
|
+
# argument is given and it is a dpctl tensor or dpnp array.
|
|
135
|
+
# This would cause issues in fit_predict. Also, available_if
|
|
136
|
+
# is hard to unwrap, and this is the most straighforward way.
|
|
137
|
+
@available_if(sklearn_LocalOutlierFactor._check_novelty_fit_predict)
|
|
138
|
+
@wrap_output_data
|
|
139
|
+
def fit_predict(self, X, y=None):
|
|
140
|
+
"""Fit the model to the training set X and return the labels.
|
|
141
|
+
|
|
142
|
+
**Not available for novelty detection (when novelty is set to True).**
|
|
143
|
+
Label is 1 for an inlier and -1 for an outlier according to the LOF
|
|
144
|
+
score and the contamination parameter.
|
|
145
|
+
|
|
146
|
+
Parameters
|
|
147
|
+
----------
|
|
148
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features), default=None
|
|
149
|
+
The query sample or samples to compute the Local Outlier Factor
|
|
150
|
+
w.r.t. the training samples.
|
|
151
|
+
|
|
152
|
+
y : Ignored
|
|
153
|
+
Not used, present for API consistency by convention.
|
|
154
|
+
|
|
155
|
+
Returns
|
|
156
|
+
-------
|
|
157
|
+
is_inlier : ndarray of shape (n_samples,)
|
|
158
|
+
Returns -1 for anomalies/outliers and 1 for inliers.
|
|
159
|
+
"""
|
|
160
|
+
return self.fit(X)._predict()
|
|
161
|
+
|
|
162
|
+
@available_if(sklearn_LocalOutlierFactor._check_novelty_predict)
|
|
163
|
+
@wrap_output_data
|
|
164
|
+
def predict(self, X=None):
|
|
165
|
+
"""Predict the labels (1 inlier, -1 outlier) of X according to LOF.
|
|
166
|
+
|
|
167
|
+
**Only available for novelty detection (when novelty is set to True).**
|
|
168
|
+
This method allows to generalize prediction to *new observations* (not
|
|
169
|
+
in the training set). Note that the result of ``clf.fit(X)`` then
|
|
170
|
+
``clf.predict(X)`` with ``novelty=True`` may differ from the result
|
|
171
|
+
obtained by ``clf.fit_predict(X)`` with ``novelty=False``.
|
|
172
|
+
|
|
173
|
+
Parameters
|
|
174
|
+
----------
|
|
175
|
+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
|
|
176
|
+
The query sample or samples to compute the Local Outlier Factor
|
|
177
|
+
w.r.t. the training samples.
|
|
178
|
+
|
|
179
|
+
Returns
|
|
180
|
+
-------
|
|
181
|
+
is_inlier : ndarray of shape (n_samples,)
|
|
182
|
+
Returns -1 for anomalies/outliers and +1 for inliers.
|
|
183
|
+
"""
|
|
184
|
+
return self._predict(X)
|
|
185
|
+
|
|
186
|
+
@wrap_output_data
|
|
187
|
+
def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
|
|
188
|
+
check_is_fitted(self)
|
|
189
|
+
if sklearn_check_version("1.0") and X is not None:
|
|
190
|
+
self._check_feature_names(X, reset=False)
|
|
191
|
+
return dispatch(
|
|
192
|
+
self,
|
|
193
|
+
"kneighbors",
|
|
194
|
+
{
|
|
195
|
+
"onedal": self.__class__._onedal_kneighbors,
|
|
196
|
+
"sklearn": sklearn_LocalOutlierFactor.kneighbors,
|
|
197
|
+
},
|
|
198
|
+
X,
|
|
199
|
+
n_neighbors=n_neighbors,
|
|
200
|
+
return_distance=return_distance,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
fit.__doc__ = sklearn_LocalOutlierFactor.fit.__doc__
|
|
204
|
+
kneighbors.__doc__ = sklearn_LocalOutlierFactor.kneighbors.__doc__
|
|
@@ -14,19 +14,12 @@
|
|
|
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._utils import control_n_jobs, run_with_n_jobs, sklearn_check_version
|
|
17
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
18
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
24
19
|
|
|
25
20
|
if not sklearn_check_version("1.2"):
|
|
26
21
|
from sklearn.neighbors._base import _check_weights
|
|
27
22
|
|
|
28
|
-
import numpy as np
|
|
29
|
-
from sklearn.neighbors._base import VALID_METRICS
|
|
30
23
|
from sklearn.neighbors._classification import (
|
|
31
24
|
KNeighborsClassifier as sklearn_KNeighborsClassifier,
|
|
32
25
|
)
|
|
@@ -34,7 +27,6 @@ from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestN
|
|
|
34
27
|
from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted
|
|
35
28
|
|
|
36
29
|
from onedal.neighbors import KNeighborsClassifier as onedal_KNeighborsClassifier
|
|
37
|
-
from onedal.utils import _check_array, _num_features, _num_samples
|
|
38
30
|
|
|
39
31
|
from .._device_offload import dispatch, wrap_output_data
|
|
40
32
|
from .common import KNeighborsDispatchingBase
|
|
@@ -140,8 +132,9 @@ else:
|
|
|
140
132
|
self.weights = _check_weights(weights)
|
|
141
133
|
|
|
142
134
|
|
|
143
|
-
@control_n_jobs
|
|
135
|
+
@control_n_jobs(decorated_methods=["fit", "predict", "predict_proba", "kneighbors"])
|
|
144
136
|
class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
137
|
+
__doc__ = sklearn_KNeighborsClassifier.__doc__
|
|
145
138
|
if sklearn_check_version("1.2"):
|
|
146
139
|
_parameter_constraints: dict = {**KNeighborsClassifier_._parameter_constraints}
|
|
147
140
|
|
|
@@ -245,7 +238,7 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
245
238
|
@wrap_output_data
|
|
246
239
|
def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
|
|
247
240
|
check_is_fitted(self)
|
|
248
|
-
if sklearn_check_version("1.0"):
|
|
241
|
+
if sklearn_check_version("1.0") and X is not None:
|
|
249
242
|
self._check_feature_names(X, reset=False)
|
|
250
243
|
return dispatch(
|
|
251
244
|
self,
|
|
@@ -255,8 +248,8 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
255
248
|
"sklearn": sklearn_KNeighborsClassifier.kneighbors,
|
|
256
249
|
},
|
|
257
250
|
X,
|
|
258
|
-
n_neighbors,
|
|
259
|
-
return_distance,
|
|
251
|
+
n_neighbors=n_neighbors,
|
|
252
|
+
return_distance=return_distance,
|
|
260
253
|
)
|
|
261
254
|
|
|
262
255
|
@wrap_output_data
|
|
@@ -285,7 +278,6 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
285
278
|
|
|
286
279
|
return result
|
|
287
280
|
|
|
288
|
-
@run_with_n_jobs
|
|
289
281
|
def _onedal_fit(self, X, y, queue=None):
|
|
290
282
|
onedal_params = {
|
|
291
283
|
"n_neighbors": self.n_neighbors,
|
|
@@ -308,15 +300,12 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
308
300
|
|
|
309
301
|
self._save_attributes()
|
|
310
302
|
|
|
311
|
-
@run_with_n_jobs
|
|
312
303
|
def _onedal_predict(self, X, queue=None):
|
|
313
304
|
return self._onedal_estimator.predict(X, queue=queue)
|
|
314
305
|
|
|
315
|
-
@run_with_n_jobs
|
|
316
306
|
def _onedal_predict_proba(self, X, queue=None):
|
|
317
307
|
return self._onedal_estimator.predict_proba(X, queue=queue)
|
|
318
308
|
|
|
319
|
-
@run_with_n_jobs
|
|
320
309
|
def _onedal_kneighbors(
|
|
321
310
|
self, X=None, n_neighbors=None, return_distance=True, queue=None
|
|
322
311
|
):
|
|
@@ -333,3 +322,9 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
333
322
|
self._fit_method = self._onedal_estimator._fit_method
|
|
334
323
|
self.outputs_2d_ = self._onedal_estimator.outputs_2d_
|
|
335
324
|
self._tree = self._onedal_estimator._tree
|
|
325
|
+
|
|
326
|
+
fit.__doc__ = sklearn_KNeighborsClassifier.fit.__doc__
|
|
327
|
+
predict.__doc__ = sklearn_KNeighborsClassifier.predict.__doc__
|
|
328
|
+
predict_proba.__doc__ = sklearn_KNeighborsClassifier.predict_proba.__doc__
|
|
329
|
+
kneighbors.__doc__ = sklearn_KNeighborsClassifier.kneighbors.__doc__
|
|
330
|
+
radius_neighbors.__doc__ = sklearn_NearestNeighbors.radius_neighbors.__doc__
|
|
@@ -14,19 +14,12 @@
|
|
|
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._utils import control_n_jobs, run_with_n_jobs, sklearn_check_version
|
|
17
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
18
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
24
19
|
|
|
25
20
|
if not sklearn_check_version("1.2"):
|
|
26
21
|
from sklearn.neighbors._base import _check_weights
|
|
27
22
|
|
|
28
|
-
import numpy as np
|
|
29
|
-
from sklearn.neighbors._base import VALID_METRICS
|
|
30
23
|
from sklearn.neighbors._regression import (
|
|
31
24
|
KNeighborsRegressor as sklearn_KNeighborsRegressor,
|
|
32
25
|
)
|
|
@@ -34,7 +27,6 @@ from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestN
|
|
|
34
27
|
from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted
|
|
35
28
|
|
|
36
29
|
from onedal.neighbors import KNeighborsRegressor as onedal_KNeighborsRegressor
|
|
37
|
-
from onedal.utils import _check_array, _num_features, _num_samples
|
|
38
30
|
|
|
39
31
|
from .._device_offload import dispatch, wrap_output_data
|
|
40
32
|
from .common import KNeighborsDispatchingBase
|
|
@@ -136,8 +128,9 @@ else:
|
|
|
136
128
|
self.weights = _check_weights(weights)
|
|
137
129
|
|
|
138
130
|
|
|
139
|
-
@control_n_jobs
|
|
131
|
+
@control_n_jobs(decorated_methods=["fit", "predict", "kneighbors"])
|
|
140
132
|
class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
|
|
133
|
+
__doc__ = sklearn_KNeighborsRegressor.__doc__
|
|
141
134
|
if sklearn_check_version("1.2"):
|
|
142
135
|
_parameter_constraints: dict = {**KNeighborsRegressor_._parameter_constraints}
|
|
143
136
|
|
|
@@ -226,7 +219,7 @@ class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
|
|
|
226
219
|
@wrap_output_data
|
|
227
220
|
def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
|
|
228
221
|
check_is_fitted(self)
|
|
229
|
-
if sklearn_check_version("1.0"):
|
|
222
|
+
if sklearn_check_version("1.0") and X is not None:
|
|
230
223
|
self._check_feature_names(X, reset=False)
|
|
231
224
|
return dispatch(
|
|
232
225
|
self,
|
|
@@ -236,8 +229,8 @@ class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
|
|
|
236
229
|
"sklearn": sklearn_KNeighborsRegressor.kneighbors,
|
|
237
230
|
},
|
|
238
231
|
X,
|
|
239
|
-
n_neighbors,
|
|
240
|
-
return_distance,
|
|
232
|
+
n_neighbors=n_neighbors,
|
|
233
|
+
return_distance=return_distance,
|
|
241
234
|
)
|
|
242
235
|
|
|
243
236
|
@wrap_output_data
|
|
@@ -266,7 +259,6 @@ class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
|
|
|
266
259
|
|
|
267
260
|
return result
|
|
268
261
|
|
|
269
|
-
@run_with_n_jobs
|
|
270
262
|
def _onedal_fit(self, X, y, queue=None):
|
|
271
263
|
onedal_params = {
|
|
272
264
|
"n_neighbors": self.n_neighbors,
|
|
@@ -289,11 +281,9 @@ class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
|
|
|
289
281
|
|
|
290
282
|
self._save_attributes()
|
|
291
283
|
|
|
292
|
-
@run_with_n_jobs
|
|
293
284
|
def _onedal_predict(self, X, queue=None):
|
|
294
285
|
return self._onedal_estimator.predict(X, queue=queue)
|
|
295
286
|
|
|
296
|
-
@run_with_n_jobs
|
|
297
287
|
def _onedal_kneighbors(
|
|
298
288
|
self, X=None, n_neighbors=None, return_distance=True, queue=None
|
|
299
289
|
):
|
|
@@ -308,3 +298,8 @@ class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
|
|
|
308
298
|
self._y = self._onedal_estimator._y
|
|
309
299
|
self._fit_method = self._onedal_estimator._fit_method
|
|
310
300
|
self._tree = self._onedal_estimator._tree
|
|
301
|
+
|
|
302
|
+
fit.__doc__ = sklearn_KNeighborsRegressor.__doc__
|
|
303
|
+
predict.__doc__ = sklearn_KNeighborsRegressor.predict.__doc__
|
|
304
|
+
kneighbors.__doc__ = sklearn_KNeighborsRegressor.kneighbors.__doc__
|
|
305
|
+
radius_neighbors.__doc__ = sklearn_NearestNeighbors.radius_neighbors.__doc__
|
|
@@ -19,20 +19,13 @@ try:
|
|
|
19
19
|
except ImportError:
|
|
20
20
|
from distutils.version import LooseVersion as Version
|
|
21
21
|
|
|
22
|
-
import warnings
|
|
23
|
-
|
|
24
|
-
import numpy as np
|
|
25
22
|
from sklearn import __version__ as sklearn_version
|
|
26
|
-
from sklearn.neighbors._ball_tree import BallTree
|
|
27
|
-
from sklearn.neighbors._base import VALID_METRICS
|
|
28
|
-
from sklearn.neighbors._base import NeighborsBase as sklearn_NeighborsBase
|
|
29
|
-
from sklearn.neighbors._kd_tree import KDTree
|
|
30
23
|
from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestNeighbors
|
|
31
24
|
from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted
|
|
32
25
|
|
|
33
|
-
from daal4py.sklearn.
|
|
26
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
27
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
34
28
|
from onedal.neighbors import NearestNeighbors as onedal_NearestNeighbors
|
|
35
|
-
from onedal.utils import _check_array, _num_features, _num_samples
|
|
36
29
|
|
|
37
30
|
from .._device_offload import dispatch, wrap_output_data
|
|
38
31
|
from .common import KNeighborsDispatchingBase
|
|
@@ -95,8 +88,9 @@ else:
|
|
|
95
88
|
)
|
|
96
89
|
|
|
97
90
|
|
|
98
|
-
@control_n_jobs
|
|
91
|
+
@control_n_jobs(decorated_methods=["fit", "kneighbors"])
|
|
99
92
|
class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
|
|
93
|
+
__doc__ = sklearn_NearestNeighbors.__doc__
|
|
100
94
|
if sklearn_check_version("1.2"):
|
|
101
95
|
_parameter_constraints: dict = {**NearestNeighbors_._parameter_constraints}
|
|
102
96
|
|
|
@@ -150,8 +144,8 @@ class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
|
|
|
150
144
|
"sklearn": sklearn_NearestNeighbors.kneighbors,
|
|
151
145
|
},
|
|
152
146
|
X,
|
|
153
|
-
n_neighbors,
|
|
154
|
-
return_distance,
|
|
147
|
+
n_neighbors=n_neighbors,
|
|
148
|
+
return_distance=return_distance,
|
|
155
149
|
)
|
|
156
150
|
|
|
157
151
|
@wrap_output_data
|
|
@@ -180,7 +174,6 @@ class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
|
|
|
180
174
|
|
|
181
175
|
return result
|
|
182
176
|
|
|
183
|
-
@run_with_n_jobs
|
|
184
177
|
def _onedal_fit(self, X, y=None, queue=None):
|
|
185
178
|
onedal_params = {
|
|
186
179
|
"n_neighbors": self.n_neighbors,
|
|
@@ -202,11 +195,9 @@ class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
|
|
|
202
195
|
|
|
203
196
|
self._save_attributes()
|
|
204
197
|
|
|
205
|
-
@run_with_n_jobs
|
|
206
198
|
def _onedal_predict(self, X, queue=None):
|
|
207
199
|
return self._onedal_estimator.predict(X, queue=queue)
|
|
208
200
|
|
|
209
|
-
@run_with_n_jobs
|
|
210
201
|
def _onedal_kneighbors(
|
|
211
202
|
self, X=None, n_neighbors=None, return_distance=True, queue=None
|
|
212
203
|
):
|
|
@@ -221,3 +212,7 @@ class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
|
|
|
221
212
|
self._fit_X = self._onedal_estimator._fit_X
|
|
222
213
|
self._fit_method = self._onedal_estimator._fit_method
|
|
223
214
|
self._tree = self._onedal_estimator._tree
|
|
215
|
+
|
|
216
|
+
fit.__doc__ = sklearn_NearestNeighbors.__doc__
|
|
217
|
+
kneighbors.__doc__ = sklearn_NearestNeighbors.kneighbors.__doc__
|
|
218
|
+
radius_neighbors.__doc__ = sklearn_NearestNeighbors.radius_neighbors.__doc__
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
# ===============================================================================
|
|
16
16
|
|
|
17
|
-
import numpy as np
|
|
18
17
|
import pytest
|
|
19
18
|
from numpy.testing import assert_allclose
|
|
20
19
|
|
|
@@ -23,12 +22,16 @@ from onedal.tests.utils._dataframes_support import (
|
|
|
23
22
|
_convert_to_dataframe,
|
|
24
23
|
get_dataframes_and_queues,
|
|
25
24
|
)
|
|
25
|
+
from sklearnex.neighbors import (
|
|
26
|
+
KNeighborsClassifier,
|
|
27
|
+
KNeighborsRegressor,
|
|
28
|
+
LocalOutlierFactor,
|
|
29
|
+
NearestNeighbors,
|
|
30
|
+
)
|
|
26
31
|
|
|
27
32
|
|
|
28
33
|
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
29
34
|
def test_sklearnex_import_knn_classifier(dataframe, queue):
|
|
30
|
-
from sklearnex.neighbors import KNeighborsClassifier
|
|
31
|
-
|
|
32
35
|
X = _convert_to_dataframe([[0], [1], [2], [3]], sycl_queue=queue, target_df=dataframe)
|
|
33
36
|
y = _convert_to_dataframe([0, 0, 1, 1], sycl_queue=queue, target_df=dataframe)
|
|
34
37
|
neigh = KNeighborsClassifier(n_neighbors=3).fit(X, y)
|
|
@@ -40,8 +43,6 @@ def test_sklearnex_import_knn_classifier(dataframe, queue):
|
|
|
40
43
|
|
|
41
44
|
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
42
45
|
def test_sklearnex_import_knn_regression(dataframe, queue):
|
|
43
|
-
from sklearnex.neighbors import KNeighborsRegressor
|
|
44
|
-
|
|
45
46
|
X = _convert_to_dataframe([[0], [1], [2], [3]], sycl_queue=queue, target_df=dataframe)
|
|
46
47
|
y = _convert_to_dataframe([0, 0, 1, 1], sycl_queue=queue, target_df=dataframe)
|
|
47
48
|
neigh = KNeighborsRegressor(n_neighbors=2).fit(X, y)
|
|
@@ -51,18 +52,16 @@ def test_sklearnex_import_knn_regression(dataframe, queue):
|
|
|
51
52
|
assert_allclose(pred, [0.5])
|
|
52
53
|
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
# investigate failure for `dpnp.ndarrays` and `dpctl.tensors`.
|
|
55
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
56
56
|
@pytest.mark.parametrize(
|
|
57
|
-
"
|
|
57
|
+
"estimator",
|
|
58
|
+
[LocalOutlierFactor, NearestNeighbors],
|
|
58
59
|
)
|
|
59
|
-
def
|
|
60
|
-
from sklearnex.neighbors import NearestNeighbors
|
|
61
|
-
|
|
60
|
+
def test_sklearnex_kneighbors(estimator, dataframe, queue):
|
|
62
61
|
X = [[0, 0, 2], [1, 0, 0], [0, 0, 1]]
|
|
63
62
|
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
64
63
|
test = _convert_to_dataframe([[0, 0, 1.3]], sycl_queue=queue, target_df=dataframe)
|
|
65
|
-
neigh =
|
|
64
|
+
neigh = estimator(n_neighbors=2).fit(X)
|
|
66
65
|
result = neigh.kneighbors(test, 2, return_distance=False)
|
|
67
66
|
result = _as_numpy(result)
|
|
68
67
|
assert "sklearnex" in neigh.__module__
|
|
@@ -71,14 +70,11 @@ def test_sklearnex_import_nn(dataframe, queue):
|
|
|
71
70
|
|
|
72
71
|
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
73
72
|
def test_sklearnex_import_lof(dataframe, queue):
|
|
74
|
-
from sklearnex.neighbors import LocalOutlierFactor
|
|
75
|
-
|
|
76
73
|
X = [[7, 7, 7], [1, 0, 0], [0, 0, 1], [0, 0, 1]]
|
|
77
74
|
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
78
75
|
lof = LocalOutlierFactor(n_neighbors=2)
|
|
79
76
|
result = lof.fit_predict(X)
|
|
80
77
|
result = _as_numpy(result)
|
|
81
|
-
assert hasattr(lof, "
|
|
78
|
+
assert hasattr(lof, "_onedal_estimator")
|
|
82
79
|
assert "sklearnex" in lof.__module__
|
|
83
|
-
assert "sklearnex" in lof._knn.__module__
|
|
84
80
|
assert_allclose(result, [-1, 1, 1, 1])
|
|
@@ -29,18 +29,15 @@ if daal_check_version((2023, "P", 200)):
|
|
|
29
29
|
check_is_fitted,
|
|
30
30
|
)
|
|
31
31
|
|
|
32
|
-
from daal4py.sklearn.
|
|
33
|
-
|
|
34
|
-
run_with_n_jobs,
|
|
35
|
-
sklearn_check_version,
|
|
36
|
-
)
|
|
32
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
33
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
37
34
|
from onedal.cluster import KMeans as onedal_KMeans
|
|
38
35
|
|
|
39
36
|
from ..._device_offload import dispatch, wrap_output_data
|
|
40
37
|
from ..._utils import PatchingConditionsChain
|
|
41
38
|
from ._common import BaseKMeans
|
|
42
39
|
|
|
43
|
-
@control_n_jobs
|
|
40
|
+
@control_n_jobs(decorated_methods=["fit", "predict"])
|
|
44
41
|
class KMeans(sklearn_KMeans, BaseKMeans):
|
|
45
42
|
__doc__ = sklearn_KMeans.__doc__
|
|
46
43
|
n_iter_, inertia_ = None, None
|
|
@@ -212,7 +209,6 @@ if daal_check_version((2023, "P", 200)):
|
|
|
212
209
|
|
|
213
210
|
return self
|
|
214
211
|
|
|
215
|
-
@run_with_n_jobs
|
|
216
212
|
def _onedal_fit(self, X, _, sample_weight, queue=None):
|
|
217
213
|
assert sample_weight is None
|
|
218
214
|
|
|
@@ -294,7 +290,6 @@ if daal_check_version((2023, "P", 200)):
|
|
|
294
290
|
X,
|
|
295
291
|
)
|
|
296
292
|
|
|
297
|
-
@run_with_n_jobs
|
|
298
293
|
def _onedal_predict(self, X, queue=None):
|
|
299
294
|
X = self._validate_data(
|
|
300
295
|
X, accept_sparse=False, reset=False, dtype=[np.float64, np.float32]
|