Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

basic_knn-0.0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

basic_knn-0.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file basic_knn-0.0.1.tar.gz.

File metadata

  • Download URL: basic_knn-0.0.1.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

Hashes for basic_knn-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ac65d0b7ab276410bfa65e4b522f7c23e690428f7d211d018680447e76925561
MD5 cfce31a56f73db5d836f438f62f72c4a
BLAKE2b-256 a03ae70233d3a511c5387c0cfaaea70ae8b7141ff7a8a0276043b9b3b66ac823

See more details on using hashes here.

File details

Details for the file basic_knn-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: basic_knn-0.0.1-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

Hashes for basic_knn-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 023961a859ef8b392ab0d1c8788db97f6105e84c5ba33ff4cc72a3585760ad3e
MD5 c1c9d03c02dc46d7f1355f29d7c97b16
BLAKE2b-256 3e1232ea7a21a224dba1f6497d0f204fe9f1033d0b18b096585ec57c69e99d99

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page