scikit-learn-intelex 2024.0.1__py312-none-win_amd64.whl → 2024.2.0__py312-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.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/__init__.py +3 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/__main__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/_utils.py +15 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/cluster/__init__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/cluster/dbscan.py +2 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/cluster/k_means.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/cluster/tests/test_dbscan.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/cluster/tests/test_kmeans.py +0 -1
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/covariance/__init__.py +19 -0
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/covariance/incremental_covariance.py +130 -0
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/covariance/tests/test_incremental_covariance.py +143 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/decomposition/__init__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/decomposition/pca.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/decomposition/tests/test_pca.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/dispatcher.py +35 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/ensemble/__init__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/ensemble/_forest.py +17 -2
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/ensemble/tests/test_forest.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/glob/__main__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/glob/dispatcher.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/linear_model/__init__.py +1 -3
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/linear_model/coordinate_descent.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/linear_model/linear.py +9 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/linear_model/logistic_path.py +0 -1
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/linear_model/logistic_regression.py +333 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/linear_model/ridge.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/linear_model/tests/test_linear.py +8 -3
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/linear_model/tests/test_logreg.py +93 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/manifold/__init__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/manifold/t_sne.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/manifold/tests/test_tsne.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/metrics/__init__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/metrics/pairwise.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/metrics/ranking.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/metrics/tests/test_metrics.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/model_selection/__init__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/model_selection/split.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/model_selection/tests/test_model_selection.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/neighbors/__init__.py +1 -2
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/neighbors/_lof.py +167 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/neighbors/common.py +1 -2
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_classification.py +5 -4
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_regression.py +5 -4
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/neighbors/knn_unsupervised.py +4 -3
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/neighbors/tests/test_neighbors.py +12 -12
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/preview/__init__.py +1 -2
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/__init__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/k_means.py +2 -1
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/preview/covariance/__init__.py +19 -0
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/preview/covariance/covariance.py +132 -0
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/preview/covariance/tests/test_covariance.py +53 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/preview/decomposition/__init__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/preview/decomposition/pca.py +43 -45
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/preview/decomposition/tests/test_preview_pca.py +7 -3
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/__init__.py +1 -0
- {scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex → scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/spmd}/basic_statistics/__init__.py +0 -1
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/spmd/covariance/__init__.py +19 -0
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/spmd/covariance/covariance.py +21 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/linear_model/__init__.py +2 -1
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/spmd/linear_model/logistic_regression.py +21 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/svm/__init__.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/svm/nusvc.py +4 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/svm/nusvr.py +2 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/svm/svc.py +5 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/svm/svr.py +2 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/svm/tests/test_svm.py +0 -1
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/tests/test_memory_usage.py +1 -4
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/tests/test_monkeypatch.py +46 -16
- scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/tests/test_n_jobs_support.py +93 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/tests/test_patching.py +19 -5
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/utils/validation.py +0 -1
- {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.2.0.dist-info}/METADATA +2 -2
- scikit_learn_intelex-2024.2.0.dist-info/RECORD +101 -0
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/linear_model/tests/test_logreg.py +0 -29
- scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/neighbors/lof.py +0 -437
- scikit_learn_intelex-2024.0.1.dist-info/RECORD +0 -90
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/_config.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/_device_offload.py +0 -0
- {scikit_learn_intelex-2024.0.1.data/data/Lib/site-packages/sklearnex/spmd → scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex}/basic_statistics/__init__.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/basic_statistics/basic_statistics.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/doc/third-party-programs.txt +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/preview/cluster/_common.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/basic_statistics/basic_statistics.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/__init__.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/dbscan.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/cluster/kmeans.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/decomposition/__init__.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/decomposition/pca.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/ensemble/__init__.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/ensemble/forest.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/linear_model/linear_model.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/neighbors/__init__.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/spmd/neighbors/neighbors.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/svm/_common.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/tests/_models_info.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/tests/test_config.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/tests/test_parallel.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/tests/test_run_to_run_stability_tests.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/tests/utils/_launch_algorithms.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/utils/__init__.py +0 -0
- {scikit_learn_intelex-2024.0.1.data → scikit_learn_intelex-2024.2.0.data}/data/Lib/site-packages/sklearnex/utils/parallel.py +0 -0
- {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.2.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.2.0.dist-info}/WHEEL +0 -0
- {scikit_learn_intelex-2024.0.1.dist-info → scikit_learn_intelex-2024.2.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
return self.fit(X)._predict()
|
|
141
|
+
|
|
142
|
+
@available_if(sklearn_LocalOutlierFactor._check_novelty_predict)
|
|
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):
|
|
149
|
+
check_is_fitted(self)
|
|
150
|
+
if sklearn_check_version("1.0") and X is not None:
|
|
151
|
+
self._check_feature_names(X, reset=False)
|
|
152
|
+
return dispatch(
|
|
153
|
+
self,
|
|
154
|
+
"kneighbors",
|
|
155
|
+
{
|
|
156
|
+
"onedal": self.__class__._onedal_kneighbors,
|
|
157
|
+
"sklearn": sklearn_LocalOutlierFactor.kneighbors,
|
|
158
|
+
},
|
|
159
|
+
X,
|
|
160
|
+
n_neighbors=n_neighbors,
|
|
161
|
+
return_distance=return_distance,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
fit.__doc__ = sklearn_LocalOutlierFactor.fit.__doc__
|
|
165
|
+
fit_predict.__doc__ = sklearn_LocalOutlierFactor.fit_predict.__doc__
|
|
166
|
+
predict.__doc__ = sklearn_LocalOutlierFactor.predict.__doc__
|
|
167
|
+
kneighbors.__doc__ = sklearn_LocalOutlierFactor.kneighbors.__doc__
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
1
|
# ==============================================================================
|
|
3
2
|
# Copyright 2023 Intel Corporation
|
|
4
3
|
#
|
|
@@ -177,7 +176,7 @@ class KNeighborsDispatchingBase:
|
|
|
177
176
|
return patching_status
|
|
178
177
|
|
|
179
178
|
if not patching_status.and_condition(
|
|
180
|
-
not sp.
|
|
179
|
+
not sp.issparse(data[0]), "Sparse input is not supported."
|
|
181
180
|
):
|
|
182
181
|
return patching_status
|
|
183
182
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
1
|
# ===============================================================================
|
|
3
2
|
# Copyright 2021 Intel Corporation
|
|
4
3
|
#
|
|
@@ -21,6 +20,7 @@ from sklearn.neighbors._ball_tree import BallTree
|
|
|
21
20
|
from sklearn.neighbors._base import NeighborsBase as sklearn_NeighborsBase
|
|
22
21
|
from sklearn.neighbors._kd_tree import KDTree
|
|
23
22
|
|
|
23
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
24
24
|
from daal4py.sklearn._utils import sklearn_check_version
|
|
25
25
|
|
|
26
26
|
if not sklearn_check_version("1.2"):
|
|
@@ -141,6 +141,7 @@ else:
|
|
|
141
141
|
self.weights = _check_weights(weights)
|
|
142
142
|
|
|
143
143
|
|
|
144
|
+
@control_n_jobs(decorated_methods=["fit", "predict", "predict_proba", "kneighbors"])
|
|
144
145
|
class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
145
146
|
if sklearn_check_version("1.2"):
|
|
146
147
|
_parameter_constraints: dict = {**KNeighborsClassifier_._parameter_constraints}
|
|
@@ -245,7 +246,7 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
245
246
|
@wrap_output_data
|
|
246
247
|
def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
|
|
247
248
|
check_is_fitted(self)
|
|
248
|
-
if sklearn_check_version("1.0"):
|
|
249
|
+
if sklearn_check_version("1.0") and X is not None:
|
|
249
250
|
self._check_feature_names(X, reset=False)
|
|
250
251
|
return dispatch(
|
|
251
252
|
self,
|
|
@@ -255,8 +256,8 @@ class KNeighborsClassifier(KNeighborsClassifier_, KNeighborsDispatchingBase):
|
|
|
255
256
|
"sklearn": sklearn_KNeighborsClassifier.kneighbors,
|
|
256
257
|
},
|
|
257
258
|
X,
|
|
258
|
-
n_neighbors,
|
|
259
|
-
return_distance,
|
|
259
|
+
n_neighbors=n_neighbors,
|
|
260
|
+
return_distance=return_distance,
|
|
260
261
|
)
|
|
261
262
|
|
|
262
263
|
@wrap_output_data
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
1
|
# ==============================================================================
|
|
3
2
|
# Copyright 2021 Intel Corporation
|
|
4
3
|
#
|
|
@@ -21,6 +20,7 @@ from sklearn.neighbors._ball_tree import BallTree
|
|
|
21
20
|
from sklearn.neighbors._base import NeighborsBase as sklearn_NeighborsBase
|
|
22
21
|
from sklearn.neighbors._kd_tree import KDTree
|
|
23
22
|
|
|
23
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
24
24
|
from daal4py.sklearn._utils import sklearn_check_version
|
|
25
25
|
|
|
26
26
|
if not sklearn_check_version("1.2"):
|
|
@@ -137,6 +137,7 @@ else:
|
|
|
137
137
|
self.weights = _check_weights(weights)
|
|
138
138
|
|
|
139
139
|
|
|
140
|
+
@control_n_jobs(decorated_methods=["fit", "predict", "kneighbors"])
|
|
140
141
|
class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
|
|
141
142
|
if sklearn_check_version("1.2"):
|
|
142
143
|
_parameter_constraints: dict = {**KNeighborsRegressor_._parameter_constraints}
|
|
@@ -226,7 +227,7 @@ class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
|
|
|
226
227
|
@wrap_output_data
|
|
227
228
|
def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
|
|
228
229
|
check_is_fitted(self)
|
|
229
|
-
if sklearn_check_version("1.0"):
|
|
230
|
+
if sklearn_check_version("1.0") and X is not None:
|
|
230
231
|
self._check_feature_names(X, reset=False)
|
|
231
232
|
return dispatch(
|
|
232
233
|
self,
|
|
@@ -236,8 +237,8 @@ class KNeighborsRegressor(KNeighborsRegressor_, KNeighborsDispatchingBase):
|
|
|
236
237
|
"sklearn": sklearn_KNeighborsRegressor.kneighbors,
|
|
237
238
|
},
|
|
238
239
|
X,
|
|
239
|
-
n_neighbors,
|
|
240
|
-
return_distance,
|
|
240
|
+
n_neighbors=n_neighbors,
|
|
241
|
+
return_distance=return_distance,
|
|
241
242
|
)
|
|
242
243
|
|
|
243
244
|
@wrap_output_data
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
1
|
# ===============================================================================
|
|
3
2
|
# Copyright 2021 Intel Corporation
|
|
4
3
|
#
|
|
@@ -31,6 +30,7 @@ from sklearn.neighbors._kd_tree import KDTree
|
|
|
31
30
|
from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestNeighbors
|
|
32
31
|
from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted
|
|
33
32
|
|
|
33
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
34
34
|
from daal4py.sklearn._utils import sklearn_check_version
|
|
35
35
|
from onedal.neighbors import NearestNeighbors as onedal_NearestNeighbors
|
|
36
36
|
from onedal.utils import _check_array, _num_features, _num_samples
|
|
@@ -96,6 +96,7 @@ else:
|
|
|
96
96
|
)
|
|
97
97
|
|
|
98
98
|
|
|
99
|
+
@control_n_jobs(decorated_methods=["fit", "kneighbors"])
|
|
99
100
|
class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
|
|
100
101
|
if sklearn_check_version("1.2"):
|
|
101
102
|
_parameter_constraints: dict = {**NearestNeighbors_._parameter_constraints}
|
|
@@ -150,8 +151,8 @@ class NearestNeighbors(NearestNeighbors_, KNeighborsDispatchingBase):
|
|
|
150
151
|
"sklearn": sklearn_NearestNeighbors.kneighbors,
|
|
151
152
|
},
|
|
152
153
|
X,
|
|
153
|
-
n_neighbors,
|
|
154
|
-
return_distance,
|
|
154
|
+
n_neighbors=n_neighbors,
|
|
155
|
+
return_distance=return_distance,
|
|
155
156
|
)
|
|
156
157
|
|
|
157
158
|
@wrap_output_data
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
1
|
# ===============================================================================
|
|
3
2
|
# Copyright 2021 Intel Corporation
|
|
4
3
|
#
|
|
@@ -24,11 +23,16 @@ from onedal.tests.utils._dataframes_support import (
|
|
|
24
23
|
_convert_to_dataframe,
|
|
25
24
|
get_dataframes_and_queues,
|
|
26
25
|
)
|
|
26
|
+
from sklearnex.neighbors import (
|
|
27
|
+
KNeighborsClassifier,
|
|
28
|
+
KNeighborsRegressor,
|
|
29
|
+
LocalOutlierFactor,
|
|
30
|
+
NearestNeighbors,
|
|
31
|
+
)
|
|
27
32
|
|
|
28
33
|
|
|
29
34
|
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
30
35
|
def test_sklearnex_import_knn_classifier(dataframe, queue):
|
|
31
|
-
from sklearnex.neighbors import KNeighborsClassifier
|
|
32
36
|
|
|
33
37
|
X = _convert_to_dataframe([[0], [1], [2], [3]], sycl_queue=queue, target_df=dataframe)
|
|
34
38
|
y = _convert_to_dataframe([0, 0, 1, 1], sycl_queue=queue, target_df=dataframe)
|
|
@@ -41,7 +45,6 @@ def test_sklearnex_import_knn_classifier(dataframe, queue):
|
|
|
41
45
|
|
|
42
46
|
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
43
47
|
def test_sklearnex_import_knn_regression(dataframe, queue):
|
|
44
|
-
from sklearnex.neighbors import KNeighborsRegressor
|
|
45
48
|
|
|
46
49
|
X = _convert_to_dataframe([[0], [1], [2], [3]], sycl_queue=queue, target_df=dataframe)
|
|
47
50
|
y = _convert_to_dataframe([0, 0, 1, 1], sycl_queue=queue, target_df=dataframe)
|
|
@@ -52,18 +55,17 @@ def test_sklearnex_import_knn_regression(dataframe, queue):
|
|
|
52
55
|
assert_allclose(pred, [0.5])
|
|
53
56
|
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
# investigate failure for `dpnp.ndarrays` and `dpctl.tensors`.
|
|
58
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
57
59
|
@pytest.mark.parametrize(
|
|
58
|
-
"
|
|
60
|
+
"estimator",
|
|
61
|
+
[LocalOutlierFactor, NearestNeighbors],
|
|
59
62
|
)
|
|
60
|
-
def
|
|
61
|
-
from sklearnex.neighbors import NearestNeighbors
|
|
63
|
+
def test_sklearnex_kneighbors(estimator, dataframe, queue):
|
|
62
64
|
|
|
63
65
|
X = [[0, 0, 2], [1, 0, 0], [0, 0, 1]]
|
|
64
66
|
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
65
67
|
test = _convert_to_dataframe([[0, 0, 1.3]], sycl_queue=queue, target_df=dataframe)
|
|
66
|
-
neigh =
|
|
68
|
+
neigh = estimator(n_neighbors=2).fit(X)
|
|
67
69
|
result = neigh.kneighbors(test, 2, return_distance=False)
|
|
68
70
|
result = _as_numpy(result)
|
|
69
71
|
assert "sklearnex" in neigh.__module__
|
|
@@ -72,14 +74,12 @@ def test_sklearnex_import_nn(dataframe, queue):
|
|
|
72
74
|
|
|
73
75
|
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
74
76
|
def test_sklearnex_import_lof(dataframe, queue):
|
|
75
|
-
from sklearnex.neighbors import LocalOutlierFactor
|
|
76
77
|
|
|
77
78
|
X = [[7, 7, 7], [1, 0, 0], [0, 0, 1], [0, 0, 1]]
|
|
78
79
|
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
79
80
|
lof = LocalOutlierFactor(n_neighbors=2)
|
|
80
81
|
result = lof.fit_predict(X)
|
|
81
82
|
result = _as_numpy(result)
|
|
82
|
-
assert hasattr(lof, "
|
|
83
|
+
assert hasattr(lof, "_onedal_estimator")
|
|
83
84
|
assert "sklearnex" in lof.__module__
|
|
84
|
-
assert "sklearnex" in lof._knn.__module__
|
|
85
85
|
assert_allclose(result, [-1, 1, 1, 1])
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
1
|
# ==============================================================================
|
|
3
2
|
# Copyright 2023 Intel Corporation
|
|
4
3
|
#
|
|
@@ -15,4 +14,4 @@
|
|
|
15
14
|
# limitations under the License.
|
|
16
15
|
# ==============================================================================
|
|
17
16
|
|
|
18
|
-
__all__ = ["cluster", "decomposition"]
|
|
17
|
+
__all__ = ["cluster", "covariance", "decomposition"]
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
1
|
# ==============================================================================
|
|
3
2
|
# Copyright 2023 Intel Corporation
|
|
4
3
|
#
|
|
@@ -30,6 +29,7 @@ if daal_check_version((2023, "P", 200)):
|
|
|
30
29
|
check_is_fitted,
|
|
31
30
|
)
|
|
32
31
|
|
|
32
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
33
33
|
from daal4py.sklearn._utils import sklearn_check_version
|
|
34
34
|
from onedal.cluster import KMeans as onedal_KMeans
|
|
35
35
|
|
|
@@ -37,6 +37,7 @@ if daal_check_version((2023, "P", 200)):
|
|
|
37
37
|
from ..._utils import PatchingConditionsChain
|
|
38
38
|
from ._common import BaseKMeans
|
|
39
39
|
|
|
40
|
+
@control_n_jobs(decorated_methods=["fit", "predict"])
|
|
40
41
|
class KMeans(sklearn_KMeans, BaseKMeans):
|
|
41
42
|
__doc__ = sklearn_KMeans.__doc__
|
|
42
43
|
n_iter_, inertia_ = None, None
|
scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/preview/covariance/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# ===============================================================================
|
|
2
|
+
# Copyright 2023 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
|
+
from .covariance import EmpiricalCovariance
|
|
18
|
+
|
|
19
|
+
__all__ = ["EmpiricalCovariance"]
|
scikit_learn_intelex-2024.2.0.data/data/Lib/site-packages/sklearnex/preview/covariance/covariance.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# ===============================================================================
|
|
2
|
+
# Copyright 2023 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 scipy import sparse as sp
|
|
21
|
+
from sklearn.covariance import EmpiricalCovariance as sklearn_EmpiricalCovariance
|
|
22
|
+
from sklearn.utils import check_array
|
|
23
|
+
|
|
24
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
25
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
26
|
+
from onedal.common.hyperparameters import get_hyperparameters
|
|
27
|
+
from onedal.covariance import EmpiricalCovariance as onedal_EmpiricalCovariance
|
|
28
|
+
from sklearnex import config_context
|
|
29
|
+
from sklearnex.metrics import pairwise_distances
|
|
30
|
+
|
|
31
|
+
from ..._device_offload import dispatch, wrap_output_data
|
|
32
|
+
from ..._utils import PatchingConditionsChain, register_hyperparameters
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@register_hyperparameters({"fit": get_hyperparameters("covariance", "compute")})
|
|
36
|
+
@control_n_jobs(decorated_methods=["fit", "mahalanobis"])
|
|
37
|
+
class EmpiricalCovariance(sklearn_EmpiricalCovariance):
|
|
38
|
+
__doc__ = sklearn_EmpiricalCovariance.__doc__
|
|
39
|
+
|
|
40
|
+
if sklearn_check_version("1.2"):
|
|
41
|
+
_parameter_constraints: dict = {
|
|
42
|
+
**sklearn_EmpiricalCovariance._parameter_constraints,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
def _save_attributes(self):
|
|
46
|
+
assert hasattr(self, "_onedal_estimator")
|
|
47
|
+
self._set_covariance(self._onedal_estimator.covariance_)
|
|
48
|
+
self.location_ = self._onedal_estimator.location_
|
|
49
|
+
|
|
50
|
+
_onedal_covariance = staticmethod(onedal_EmpiricalCovariance)
|
|
51
|
+
|
|
52
|
+
def _onedal_fit(self, X, queue=None):
|
|
53
|
+
if X.shape[0] == 1:
|
|
54
|
+
warnings.warn(
|
|
55
|
+
"Only one sample available. You may want to reshape your data array"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
onedal_params = {
|
|
59
|
+
"method": "dense",
|
|
60
|
+
"bias": True,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
self._onedal_estimator = self._onedal_covariance(**onedal_params)
|
|
64
|
+
self._onedal_estimator.fit(X, queue=queue)
|
|
65
|
+
self._save_attributes()
|
|
66
|
+
|
|
67
|
+
def _onedal_supported(self, method_name, *data):
|
|
68
|
+
class_name = self.__class__.__name__
|
|
69
|
+
patching_status = PatchingConditionsChain(
|
|
70
|
+
f"sklearn.covariance.{class_name}.{method_name}"
|
|
71
|
+
)
|
|
72
|
+
if method_name in ["fit", "mahalanobis"]:
|
|
73
|
+
(X,) = data
|
|
74
|
+
patching_status.and_conditions(
|
|
75
|
+
[
|
|
76
|
+
(
|
|
77
|
+
self.assume_centered == False,
|
|
78
|
+
"assume_centered parameter is not supported on oneDAL side",
|
|
79
|
+
),
|
|
80
|
+
(not sp.issparse(X), "X is sparse. Sparse input is not supported."),
|
|
81
|
+
]
|
|
82
|
+
)
|
|
83
|
+
return patching_status
|
|
84
|
+
raise RuntimeError(f"Unknown method {method_name} in {self.__class__.__name__}")
|
|
85
|
+
|
|
86
|
+
_onedal_cpu_supported = _onedal_supported
|
|
87
|
+
_onedal_gpu_supported = _onedal_supported
|
|
88
|
+
|
|
89
|
+
def fit(self, X, y=None):
|
|
90
|
+
if sklearn_check_version("1.2"):
|
|
91
|
+
self._validate_params()
|
|
92
|
+
if sklearn_check_version("0.23"):
|
|
93
|
+
X = self._validate_data(X, force_all_finite=False)
|
|
94
|
+
else:
|
|
95
|
+
X = check_array(X, force_all_finite=False)
|
|
96
|
+
|
|
97
|
+
dispatch(
|
|
98
|
+
self,
|
|
99
|
+
"fit",
|
|
100
|
+
{
|
|
101
|
+
"onedal": self.__class__._onedal_fit,
|
|
102
|
+
"sklearn": sklearn_EmpiricalCovariance.fit,
|
|
103
|
+
},
|
|
104
|
+
X,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
return self
|
|
108
|
+
|
|
109
|
+
# expose sklearnex pairwise_distances if mahalanobis distance eventually supported
|
|
110
|
+
@wrap_output_data
|
|
111
|
+
def mahalanobis(self, X):
|
|
112
|
+
if sklearn_check_version("1.0"):
|
|
113
|
+
X = self._validate_data(X, reset=False)
|
|
114
|
+
else:
|
|
115
|
+
X = check_array(X)
|
|
116
|
+
|
|
117
|
+
precision = self.get_precision()
|
|
118
|
+
with config_context(assume_finite=True):
|
|
119
|
+
# compute mahalanobis distances
|
|
120
|
+
dist = pairwise_distances(
|
|
121
|
+
X, self.location_[np.newaxis, :], metric="mahalanobis", VI=precision
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
return np.reshape(dist, (len(X),)) ** 2
|
|
125
|
+
|
|
126
|
+
error_norm = wrap_output_data(sklearn_EmpiricalCovariance.error_norm)
|
|
127
|
+
score = wrap_output_data(sklearn_EmpiricalCovariance.score)
|
|
128
|
+
|
|
129
|
+
fit.__doc__ = sklearn_EmpiricalCovariance.fit.__doc__
|
|
130
|
+
mahalanobis.__doc__ = sklearn_EmpiricalCovariance.mahalanobis
|
|
131
|
+
error_norm.__doc__ = sklearn_EmpiricalCovariance.error_norm.__doc__
|
|
132
|
+
score.__doc__ = sklearn_EmpiricalCovariance.score.__doc__
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# ===============================================================================
|
|
2
|
+
# Copyright 2023 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 daal4py.sklearn._utils import daal_check_version
|
|
22
|
+
from onedal.tests.utils._dataframes_support import (
|
|
23
|
+
_convert_to_dataframe,
|
|
24
|
+
get_dataframes_and_queues,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
|
|
29
|
+
@pytest.mark.parametrize("macro_block", [None, 1024])
|
|
30
|
+
def test_sklearnex_import_covariance(dataframe, queue, macro_block):
|
|
31
|
+
from sklearnex.preview.covariance import EmpiricalCovariance
|
|
32
|
+
|
|
33
|
+
X = np.array([[0, 1], [0, 1]])
|
|
34
|
+
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
35
|
+
empcov = EmpiricalCovariance()
|
|
36
|
+
if daal_check_version((2024, "P", 0)) and macro_block is not None:
|
|
37
|
+
hparams = empcov.get_hyperparameters("fit")
|
|
38
|
+
hparams.cpu_macro_block = macro_block
|
|
39
|
+
result = empcov.fit(X)
|
|
40
|
+
expected_covariance = np.array([[0, 0], [0, 0]])
|
|
41
|
+
expected_means = np.array([0, 1])
|
|
42
|
+
|
|
43
|
+
assert_allclose(expected_covariance, result.covariance_)
|
|
44
|
+
assert_allclose(expected_means, result.location_)
|
|
45
|
+
|
|
46
|
+
X = np.array([[1, 2], [3, 6]])
|
|
47
|
+
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
|
|
48
|
+
result = empcov.fit(X)
|
|
49
|
+
expected_covariance = np.array([[1, 2], [2, 4]])
|
|
50
|
+
expected_means = np.array([2, 4])
|
|
51
|
+
|
|
52
|
+
assert_allclose(expected_covariance, result.covariance_)
|
|
53
|
+
assert_allclose(expected_means, result.location_)
|