{"id":22291726,"url":"https://github.com/kujirahand/rust-knn-classifier","last_synced_at":"2025-03-25T21:44:25.533Z","repository":{"id":224176131,"uuid":"762628551","full_name":"kujirahand/rust-knn-classifier","owner":"kujirahand","description":"The classifier for the k-Nearest Neighbors (k-nn) algorithm.","archived":false,"fork":false,"pushed_at":"2024-02-25T04:43:20.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T09:25:03.399Z","etag":null,"topics":["knn-classification","ml"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kujirahand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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},"funding":{"github":["kujirahand"]}},"created_at":"2024-02-24T08:35:06.000Z","updated_at":"2024-09-09T05:43:21.000Z","dependencies_parsed_at":"2024-12-03T17:18:12.380Z","dependency_job_id":"7437544d-a8a6-4649-a5f6-1187ed3e0b23","html_url":"https://github.com/kujirahand/rust-knn-classifier","commit_stats":null,"previous_names":["kujirahand/rust-knn-classifier"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kujirahand%2Frust-knn-classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kujirahand%2Frust-knn-classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kujirahand%2Frust-knn-classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kujirahand%2Frust-knn-classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kujirahand","download_url":"https://codeload.github.com/kujirahand/rust-knn-classifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245550590,"owners_count":20633871,"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":["knn-classification","ml"],"created_at":"2024-12-03T17:18:08.829Z","updated_at":"2025-03-25T21:44:25.511Z","avatar_url":"https://github.com/kujirahand.png","language":"Rust","funding_links":["https://github.com/sponsors/kujirahand"],"categories":[],"sub_categories":[],"readme":"# k-nn classifier\n\nThis is a library for solving classification problems using the k-nearest neighbor (k-nn) algorithm.\nDue to the simplicity of the algorithm, it is lightweight and well-suited for easily solving classification problems.\n\n## Install\n\n```sh\ncargo add knn_classifier\n```\n\n## Simple Example\n\nThe following sample is a program that determines if a person is of normal weight or fat, based on their height(cm) and weight(kg).\n\n```rs\nuse knn_classifier::KnnClassifier;\nfn main() {\n    // Create the classifier\n    let mut clf = KnnClassifier::new(3);\n    // Learn from data\n    clf.fit(\n        \u0026[\u0026[170., 60.], \u0026[166., 58.], \u0026[152., 99.], \u0026[163., 95.], \u0026[150., 90.]],\n        \u0026[\"Normal\", \"Normal\", \"Obesity\", \"Obesity\", \"Obesity\"]);\n    // Predict\n    let labels = clf.predict(\u0026[vec![159., 85.], vec![165., 55.]]);\n    println!(\"{:?}\", labels); // [\"Fat\", \"Normal\"]\n    assert_eq!(labels, [\"Obesity\", \"Normal\"]);\n}\n```\n\n## Support CSV format\n\nThe classifier can be converted to and from CSV format.\n\n```rs\n// Convert Data to CSV\nlet s = clf.to_csv(',');\nprintln!(\"{}\", s);\n\n// Convert from CSV\nclf.from_csv(\u0026s, ',', 0, false);\n\n// Predict one\nlet label = clf.predict_one(\u0026[150., 80.]);\nassert_eq!(label, \"Obesity\");\n```\n\n## Samples\n\n- [iris](/samples/iris/README.md)\n\n## Repository\n\n- [github \u003e knn_classifier](https://github.com/kujirahand/rust-knn-classifier)\n- [crates.io \u003e knn_classifier](https://crates.io/crates/knn_classifier)\n- [docs.rs \u003e knn_classifier](https://docs.rs/knn_classifier/)\n\n## Reference\n\n- [k-NN algorithm](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm)\n- [k-NN algorithm (ja)](https://ja.wikipedia.org/wiki/K%E8%BF%91%E5%82%8D%E6%B3%95)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkujirahand%2Frust-knn-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkujirahand%2Frust-knn-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkujirahand%2Frust-knn-classifier/lists"}