Skip to content

Commit 7ae0171

Browse files
lordoz234Vladislav NazarovAlexsandruss
authored
LocalOutlierFactor implementation (#990)
* add LocalOutlierFactor wrapper * Tests for LocalOutlierFactor --------- Co-authored-by: Vladislav Nazarov <[email protected]> Co-authored-by: Alexander Andreev <[email protected]>
1 parent 94744b2 commit 7ae0171

File tree

9 files changed

+432
-5
lines changed

9 files changed

+432
-5
lines changed

deselected_tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ deselected_tests:
3939
- linear_model/tests/test_logistic.py::test_logistic_regression_multinomial
4040
- neighbors/tests/test_neighbors.py::test_neigh_predictions_algorithm_agnosticity[float64-KNeighborsClassifier-1-100-minkowski-1000-5-100]
4141
- cluster/tests/test_k_means.py::test_k_means_fit_predict >=0.23,<0.24
42+
- neighbors/tests/test_lof.py::test_lof_dtype_equivalence[0.5-True-brute]
43+
- neighbors/tests/test_lof.py::test_lof_dtype_equivalence[auto-True-brute]
4244

4345
# cache directory is not accessible on some systems
4446
- utils/tests/test_validation.py::test_check_memory

sklearnex/dispatcher.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# ===============================================================================
2+
#===============================================================================
33
# Copyright 2021 Intel Corporation
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -51,6 +51,7 @@ def get_patch_map():
5151
from .neighbors import KNeighborsClassifier as KNeighborsClassifier_sklearnex
5252
from .neighbors import KNeighborsRegressor as KNeighborsRegressor_sklearnex
5353
from .neighbors import NearestNeighbors as NearestNeighbors_sklearnex
54+
from .neighbors import LocalOutlierFactor as LocalOutlierFactor_sklearnex
5455

5556
# Preview classes for patching
5657

@@ -130,6 +131,12 @@ def get_patch_map():
130131
mapping['kneighborsregressor'] = mapping['knn_regressor']
131132
mapping['nearestneighbors'] = mapping['nearest_neighbors']
132133

134+
# LocalOutlierFactor
135+
mapping['lof'] = [[(neighbors_module,
136+
'LocalOutlierFactor',
137+
LocalOutlierFactor_sklearnex), None]]
138+
mapping['localoutlierfactor'] = mapping['lof']
139+
133140
# Configs
134141
mapping['set_config'] = [[(base_module,
135142
'set_config',

sklearnex/neighbors/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@
1818
from .knn_classification import KNeighborsClassifier
1919
from .knn_unsupervised import NearestNeighbors
2020
from .knn_regression import KNeighborsRegressor
21+
from .lof import LocalOutlierFactor
2122

22-
__all__ = ['KNeighborsClassifier', 'KNeighborsRegressor', 'NearestNeighbors']
23+
__all__ = ['KNeighborsClassifier', 'KNeighborsRegressor', 'LocalOutlierFactor',
24+
'NearestNeighbors']

sklearnex/neighbors/knn_unsupervised.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def fit(self, X, y=None):
199199
@wrap_output_data
200200
def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
201201
check_is_fitted(self)
202-
if sklearn_check_version("1.0"):
202+
if sklearn_check_version("1.0") and X is not None:
203203
self._check_feature_names(X, reset=False)
204204
return dispatch(self, 'neighbors.NearestNeighbors.kneighbors', {
205205
'onedal': self.__class__._onedal_kneighbors,

0 commit comments

Comments
 (0)