Open
Description
Describe the bug
I am attempting to use cuML with PyOD to use KNN for outlier detection, following the code in this example script.
When I try to fit the KNN model, I get an attribute error for an attribute that does not exist in the cuML implementation:
%load_ext cuml.accel
from pyod.models.knn import KNN
from pyod.utils.data import generate_data
from pyod.utils.data import evaluate_print
from pyod.utils.example import visualize
contamination = 0.1 # percentage of outliers
n_train = 200000 # number of training points
n_test = 100000 # number of testing points
X_train, X_test, y_train, y_test = generate_data(
n_train=n_train, n_test=n_test, contamination=contamination)
clf_name = 'KNN'
clf = KNN()
clf.fit(X_train)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[1], line 17
15 clf_name = 'KNN'
16 clf = KNN()
---> 17 clf.fit(X_train)
File [/raid/btepera/miniforge3/envs/rapids-25.04/lib/python3.12/site-packages/pyod/models/knn.py:197](http://127.0.0.1:8890/raid/btepera/miniforge3/envs/rapids-25.04/lib/python3.12/site-packages/pyod/models/knn.py#line=196), in KNN.fit(self, X, y)
192 self.neigh_.fit(X)
194 # In certain cases, _tree does not exist for NearestNeighbors
195 # See Issue #158 (https://github.com/yzhao062/pyod/issues/158)
196 # n_neighbors = 100
--> 197 if self.neigh_._tree is not None:
198 self.tree_ = self.neigh_._tree
200 else:
File base.pyx:865, in cuml.internals.base.UniversalBase.__getattr__()
File base.pyx:833, in cuml.internals.base.UniversalBase.__getattr__()
File base.pyx:388, in cuml.internals.base.Base.__getattr__()
AttributeError: _tree
Using these package versions:
cuml 25.4.0a168
scikit-learn 1.6.1
pyod 2.0.4