FAISS implementation of multiclass and multilabel K-Nearest Neighbors Classifiers.
Project description
faissknn
faissknn contains implementations for both multiclass and multilabel K-Nearest Neighbors Classifier implementations. The classifiers follow the scikit-learn: fit, predict, and predict_proba methods.
Install
pip install faissknn
This pulls in faiss-cuda-cu128 (Taylor Geospatial's GPU-enabled FAISS wheels for CUDA 12.x) along with numpy and torch. No system CUDA toolkit required — just an NVIDIA driver new enough for CUDA 12 (R525+).
Usage
Multiclass:
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from faissknn import FaissKNNClassifier
x, y = make_classification()
x_train, x_test, y_train, y_test = train_test_split(x, y)
model = FaissKNNClassifier(
n_neighbors=5,
n_classes=None,
device="cpu"
)
model.fit(x_train, y_train)
y_pred = model.predict(x_test) # (N,)
y_proba = model.predict_proba(x_test) # (N, C)
Multilabel:
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from faissknn import FaissKNNMultilabelClassifier
x, y = make_multilabel_classification()
x_train, x_test, y_train, y_test = train_test_split(x, y)
model = FaissKNNMultilabelClassifier(
n_neighbors=5,
device="cpu"
)
model.fit(x_train, y_train)
y_pred = model.predict(x_test) # (N, C)
y_proba = model.predict_proba(x_test) # (N, C)
GPU/CUDA: faissknn also supports running on the GPU to speed up computation. Simply change the device to cuda or a specific cuda device cuda:0
model = FaissKNNClassifier(
n_neighbors=5,
device="cuda"
)
model = FaissKNNClassifier(
n_neighbors=5,
device="cuda:0"
)
Cite
If you use faissknn in your research, please considering citing!
@software{isaac_corley_2026_18370748,
author = {Isaac Corley},
title = {isaaccorley/faissknn: Zenodo Cite},
month = jan,
year = 2026,
publisher = {Zenodo},
version = {v0.0.3},
doi = {10.5281/zenodo.18370748},
url = {https://doi.org/10.5281/zenodo.18370748},
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file faissknn-0.0.3.tar.gz.
File metadata
- Download URL: faissknn-0.0.3.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71b0c5bcad53877ab78f799f214c91082dd585ffe6900cbd859c4e905648626e
|
|
| MD5 |
3f6818c944a726ca3e820eb5536f82fc
|
|
| BLAKE2b-256 |
69fb1cea98c047d5b1eaee7d619a645c9648d02a8e693b09ee820cb3f07d4df2
|
File details
Details for the file faissknn-0.0.3-py3-none-any.whl.
File metadata
- Download URL: faissknn-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3aea067a2b22e0538471799d31d192c2275f2b51fd499debfc343ceaa191745
|
|
| MD5 |
dead9461bf19add71abc5aa68f1587d2
|
|
| BLAKE2b-256 |
5dd9c558cac306fb480b5acd4ad4341e2690d61e77f7fd758952a34ebf983207
|