{"id":37759457,"url":"https://github.com/senavs/knn-from-scratch","last_synced_at":"2026-01-16T14:34:47.361Z","repository":{"id":37615194,"uuid":"228252963","full_name":"senavs/knn-from-scratch","owner":"senavs","description":":heavy_check_mark: A Python implementation of KNN machine learning algorithm.","archived":false,"fork":false,"pushed_at":"2022-06-21T23:49:49.000Z","size":15,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-05T11:18:36.271Z","etag":null,"topics":["iris-dataset","knn","knn-classification","machine-learning","machine-learning-algorithms","object-oriented-programming","python3","scracth"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/senavs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-15T21:09:48.000Z","updated_at":"2022-11-08T22:00:39.000Z","dependencies_parsed_at":"2022-08-19T02:01:38.468Z","dependency_job_id":null,"html_url":"https://github.com/senavs/knn-from-scratch","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/senavs/knn-from-scratch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/senavs%2Fknn-from-scratch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/senavs%2Fknn-from-scratch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/senavs%2Fknn-from-scratch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/senavs%2Fknn-from-scratch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/senavs","download_url":"https://codeload.github.com/senavs/knn-from-scratch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/senavs%2Fknn-from-scratch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iris-dataset","knn","knn-classification","machine-learning","machine-learning-algorithms","object-oriented-programming","python3","scracth"],"created_at":"2026-01-16T14:34:46.585Z","updated_at":"2026-01-16T14:34:47.354Z","avatar_url":"https://github.com/senavs.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KNN from scratch\nA Python implementation of KNN machine learning algorithm.\n\n## Algorithm\n[K nearest neighbors](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) is a supervised learning algorithm to classification or regression. Considering _n_ points in the cartesian plane, if a new point is placed, its label will be the label of the _k_ nearest neighbors, in other words, the neighbors with least distance. To calculate the distance [euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance) algorithm is used.\n\n## Euclidean distance\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcT-BNnXJs2WFM-hvledmFTsECBmQ1ssxkLnucrp3sG8yrXA8VAN\" width=250\u003e\n\u003c/p\u003e\n\n## Implementation\n[Point](https://github.com/senavs/knn-from-scratch/blob/master/model/point.py) is a class to represent a point in cartesian plane. You are able to sum, subtract, multiply, divide and calculate distance between two points.\n``` python\nfrom model.point import Point\n\np1 = Point([7, 4, 3])\np2 = Point([17, 6, 2])\n```\n[KNearestNeighbors](https://github.com/senavs/knn-from-scratch/blob/master/model/knn.py) is the model class. Only the methods are allowed: `fit` and `predict`. Look into `help(KNearestNeighbors)` for more infomraiton.\n```python\nfrom model.knn import KNearestNeighbors\n\nknn = KNearestNeighbors(k=3)\nknn.fit(x_train, y_train)\n\npredict = knn.predict(x_predict)\n```\n\n## Apply KNearestNeighbors from scratch in dataset\nTo show the package working, I created a jupyter notebook with [iris dataset](https://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html). Take a look into [here](https://github.com/senavs/knn-from-scratch/blob/master/notebook/knn-iris_dataset.ipynb).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsenavs%2Fknn-from-scratch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsenavs%2Fknn-from-scratch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsenavs%2Fknn-from-scratch/lists"}