{"id":16170439,"url":"https://github.com/corentinth/ml-myknearestneighbors","last_synced_at":"2025-07-15T19:43:58.744Z","repository":{"id":95926745,"uuid":"90301212","full_name":"CorentinTh/ML-MyKNearestNeighbors","owner":"CorentinTh","description":"[Machine Learning] My own version of the K-Nearest-Neighbors classifier.","archived":false,"fork":false,"pushed_at":"2017-10-04T08:41:57.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-13T11:35:23.118Z","etag":null,"topics":["classifier","knearest-neighbors-classifier","machine-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","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/CorentinTh.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-04T19:18:22.000Z","updated_at":"2023-09-08T17:24:29.000Z","dependencies_parsed_at":"2023-04-21T19:08:02.574Z","dependency_job_id":null,"html_url":"https://github.com/CorentinTh/ML-MyKNearestNeighbors","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2FML-MyKNearestNeighbors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2FML-MyKNearestNeighbors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2FML-MyKNearestNeighbors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2FML-MyKNearestNeighbors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CorentinTh","download_url":"https://codeload.github.com/CorentinTh/ML-MyKNearestNeighbors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247611171,"owners_count":20966487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["classifier","knearest-neighbors-classifier","machine-learning"],"created_at":"2024-10-10T03:18:47.813Z","updated_at":"2025-04-07T07:29:11.309Z","avatar_url":"https://github.com/CorentinTh.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ML-MyKNearestNeighbors\n## Overview\nThe `MyKNN.py` file contain my home-made version of the k-Nearest-Neighbors classifier.\n\nBy default `k = 5`, it means that the classifier will checks for the closest 5 neightbors of the data you want to test.\n\n## Dependencies\nThe classifier only uses basic library (`math`, `sys` and `operator`), so you don't need dependencies to use it.\n\nThe main file (`main.py`) uses sklearn to get datasets, but you don't need it if you want to use just the classifier. Run this command to get **sklearn** :\n```\npip install scikit-learn\n```\n## Run the script\nYou can run this script in terminal with this command line :\n```\npython main.py\n```\n## Use the classifier\nFirst create the classifier.\n```python\nfrom MyKNN import *\nclassifier = MyKNN()\n\n# You can change the value of k by this\nclassifier.k = 5\n```\nThen, train it.\n```python\n# x_train is an array of features (like [[1, 2], [5, 9], [6, 8], [2, 3]])\n# y_train is an array of labels   (like [  'a' ,  'b'  ,  'b'  ,  'a'  ])\n# Labels index must match the corresponding feature index\nclassifier.train(x_train, y_train)\n```\nAnd now, you can predict some output.\n```python\n# x_test is an array of features you want to get the label (like [[6, 8], [0, 2]])\npredictions = classifier.predict(x_test)\nprint(predictions)\n# Display : ['b', 'a']\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorentinth%2Fml-myknearestneighbors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorentinth%2Fml-myknearestneighbors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorentinth%2Fml-myknearestneighbors/lists"}