{"id":20408203,"url":"https://github.com/hashlag/neighbours","last_synced_at":"2026-05-28T01:31:45.149Z","repository":{"id":220560071,"uuid":"749365474","full_name":"hashlag/neighbours","owner":"hashlag","description":"Weighted kNN classifier and Nadaraya-Watson kernel regressor implementation based on random projection forest","archived":false,"fork":false,"pushed_at":"2024-02-06T18:19:25.000Z","size":79,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T02:32:43.589Z","etag":null,"topics":["knn","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/hashlag.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":"2024-01-28T11:23:55.000Z","updated_at":"2024-02-04T19:01:18.000Z","dependencies_parsed_at":"2024-02-06T18:52:12.988Z","dependency_job_id":null,"html_url":"https://github.com/hashlag/neighbours","commit_stats":null,"previous_names":["hashlag/neighbours"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hashlag/neighbours","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashlag%2Fneighbours","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashlag%2Fneighbours/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashlag%2Fneighbours/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashlag%2Fneighbours/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hashlag","download_url":"https://codeload.github.com/hashlag/neighbours/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashlag%2Fneighbours/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33590884,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["knn","machine-learning"],"created_at":"2024-11-15T05:29:21.568Z","updated_at":"2026-05-28T01:31:45.135Z","avatar_url":"https://github.com/hashlag.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Neighbours\n\nWeighted kNN classifier and Nadaraya-Watson kernel regressor implementation based on random projection forest.\n\n### Classifier description\n\nThis project implements weighted kNN classifier with kernel smoothing.\n\nBuilt-in smoothing kernels:\n\n* rectangular\n* gaussian\n* epanechnikov\n\nBuilt-in distance metrics:\n\n* euclidean\n* manhattan\n\nCustom distance metrics and smoothing kernels are supported.\n\nDemo: `demo/classifier_demo.py`\n\n### Regressor description\n\nNadaraya-Watson kernel regressor is implemented.\n\nDemo: `demo/regressor_demo.py`\n\n![regressor demo screenshot](https://raw.githubusercontent.com/hashlag/neighbours/main/demo/regressor_demo_output.png)\n\n### Neighbors search algorithm\n\nRandom projection forest is used to search for neighbours.\n\nRP trees are built by recursive binary splits of space by selected hyperplanes.\n\nOn each step algorithm chooses two random objects from the train set\nand calculates a hyperplane symmetrically separating these two objects in feature space.\nSuch hyperplanes become splitting nodes of an RP tree.\n\nEach resulting subset is split again if it contains more than `m` (hyperparameter) objects. \n\nHyperplane in each splitting node is represented with an equation of the form\nw · x + b = 0, where w is a vector normal to the hyperplane and b is an offset.\n\nFor simplicity, we assume what points may be located either \"to the right\"\nor \"to the left\" of the hyperplane.\n\nWe also define points belonging to a hyperplane as located \"to the left.\"\n\nSo for any point x we can clearly determine its location:\n\n```\nw · x + b \u003e 0 point x is located \"to the right\"\nw · x + b ≤ 0 point x is located \"to the left\"\n```\n\nSince nodes are organized into a tree, we can perform search by evaluating the expression and proceeding to the corresponding child node.\n\n### Installation\n\n```shell\npip install git+https://github.com/hashlag/neighbours.git\n```\n\n### Usage\n\nImport the package, for example, as\n\n```python\n\nimport neighbours as ns\n```\n\nNow you can use the classifier\n\n```python\nimport numpy as np\n\n# KNNClassifier(features, classes_count, trees_count, maximum number of samples in one leaf of an RP tree)\nclassifier = ns.KNNClassifier(2, 3, 10, 7)\n\ntrain = np.array([[2, 1], [10, 15], [1, 3] ...])\nclass_labels = np.array([0, 1, 0 ...])\n\n# load samples into classifier and build an RP forest\nclassifier.load(train, class_labels)\n\n# target object representation\nsample = np.array([1, 1])\n\n# specify distance metric, smoothing kernel, window width and obtain a prediction\nprediction = classifier.predict(sample, ns.distance.euclidean, ns.kernel.gaussian, 1)\n\nprint(prediction)\n```\n\n### Dependencies\n\nThe only third-party dependency is `numpy`.\n\n### License\n\nThis project is licensed under [the MIT License](https://raw.githubusercontent.com/hashlag/neighbours/main/LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashlag%2Fneighbours","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhashlag%2Fneighbours","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashlag%2Fneighbours/lists"}