K-Nearest Neighbors of Neighbors - for Anomaly Detection
pip install knnnThis package provides a simple implementation of the K-Nearest Neighbors of Neighbors algorithm. The algorithm is a simple extension of the K-Nearest Neighbors algorithm, which is used for anomaly detection. The algorithm is based on the idea that the neighbors of the neighbors of a point gives more information than its neighbors. The algorithm can be used to improve the accuracy of the KNN algorithm.
from knnn import KNNN
import numpy as np
# Random data
x_normal = np.random.rand(100, 5)
x_test = np.random.rand(20, 5) + 1
# Create a KNNN object
knnn = KNNN(number_of_neighbors=3, number_of_neighbors_of_neighbors=25)
# Fit the model
knnn.fit(x_normal)
# Predict the labels of the test data
y_pred = knnn.predict(x_test)The simplest way to install the package is to run:
pip install knnnIf you want to install the latest version from the master branch:
(-e option will allow you to change the code without reinstalling the package)
git clone https:\\github.com\knnn
cd knnn
python3 -m pip install -e . If you want to build the package from source, run:
python3 -m buildand to install the built package, run:
python3 -m pip install --force-reinstall dist/*.whlTo run the tests, run:
pytest@inproceedings{nizan2024k,
title={k-NNN: Nearest Neighbors of Neighbors for Anomaly Detection},
author={Nizan, Ori and Tal, Ayellet},
booktitle={Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision},
pages={1005--1014},
year={2024}
}
