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
The FAISS authors recommend to install faiss
through conda e.g. conda install -c pytorch faiss-gpu
. See FAISS install page for more info.
Once faiss
is installed, faissknn
can be install through pypi:
pip install faissknn
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 = FaissKNNClassifier(
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"
)
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file faissknn-0.0.1.tar.gz
.
File metadata
- Download URL: faissknn-0.0.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d81a34949681c88a4bbce712102078ed8115b8402ca19966116a1a9ea81a2e87 |
|
MD5 | fa5b208f2932c4920345acd0b4608ba7 |
|
BLAKE2b-256 | 72e05b2fd177311d93d259db16dc9b6d7afe32e1b45dd61a3f812c0bfd099530 |
File details
Details for the file faissknn-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: faissknn-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0ffd8aa5a33074d9d98f3cb7eaa6c3732d73bb9986c17ced93a17b157dd0303 |
|
MD5 | dd657e2d765a66434b34c5dc581ab432 |
|
BLAKE2b-256 | 07433aa0fa6cef39134a51fa947dff793ee49402707bbdca0190e9ac728d4b02 |