K-Nearest Neighbors algorithm for classification problems.
Project description
KNN Algorithm Module
What is KNN?
In k-NN classification, the output is a class membership. An object is classified by a plurality vote of its neighbors, with the object being assigned to the class most common among its k nearest neighbors (k is a positive integer, typically small). If k = 1, then the object is simply assigned to the class of that single nearest neighbor.
k-NN is a type of instance-based learning, or lazy learning, where the function is only approximated locally and all computation is deferred until function evaluation. Since this algorithm relies on distance for classification, normalizing the training data can improve its accuracy dramatically.
(Wikipedia Article about KNN, https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm)
How to Install?
It is always better to use "pip" (Package manager for Python).
pip install basic_knn
Sample Usage
Create Model
# import knn classifier
from basic_knn import KNNClassifier
# sample data
data_x = [...]
data_y = [...]
labels = [...]
# create model
model = KNNClassifier(xs = xs, ys = ys, labels = labels)
Make Predictions
# sample input for predictions
sample_input = (..., ...)
# make prediction
model.predict(sample_input)
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 basic_knn-0.0.2.tar.gz
.
File metadata
- Download URL: basic_knn-0.0.2.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6f79b79da202047973da621114d666840bc0182a75a6378369462afc851726c |
|
MD5 | f47b1a75f46f1443640442c10f26e836 |
|
BLAKE2b-256 | 5300c968d73a900ef16aa108a4fb917197cace5fd46df7f64effc5b220a07065 |
File details
Details for the file basic_knn-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: basic_knn-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c56c094275ff123d78e0dc2480b08dd312c484fe56e8c8f6a6e94a252eb851d |
|
MD5 | 6741407886f96353cf9a04d34c7d774c |
|
BLAKE2b-256 | 6deed491190dc3a4f6e04554b58919e743d0c38553ac04d150a6a511617e5ab5 |