TheAlgorithms / Rust

All Algorithms implemented in Rust
MIT License
21.51k stars 2.1k forks source link

K nearest neighbors Algorithm #723

Open haswanth10 opened 1 month ago

haswanth10 commented 1 month ago

This commit adds K-nearest neighbors Algorithm.

Important points regarding Commit:

  1. Euclidean distance is used to compute the distance between 2 points.
  2. Only classification has been implemented by using majority vote amongst k nearest neighbors for an input point
  3. An Enum has been created for distance computation so that it can be extended to other distance computation techniques/formulae like Manhattan Distance, etc.
  4. Classification Label is of type 'String'.

Pull Request Template

Description

Please include a summary of the change and which issue (if any) is fixed. A brief description of the algorithm and your implementation method can be helpful too. If the implemented method/algorithm is not so well-known, it would be helpful to add a link to an article explaining it with more details.

Type of change

Please delete options that are not relevant.

Checklist:

Please make sure that if there is a test that takes too long to run ( > 300ms), you #[ignore] that or try to optimize your code or make the test easier to run. We have this rule because we have hundreds of tests to run; If each one of them took 300ms, we would have to wait for a long time.

codecov-commenter commented 1 month ago

Codecov Report

Attention: Patch coverage is 99.56897% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.07%. Comparing base (0b8ba06) to head (56bd101).

Files Patch % Lines
...chine_learning/optimization/k_nearest_neighbors.rs 99.56% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #723 +/- ## ========================================== + Coverage 95.02% 95.07% +0.04% ========================================== Files 303 304 +1 Lines 22577 22809 +232 ========================================== + Hits 21454 21685 +231 - Misses 1123 1124 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

haswanth10 commented 4 weeks ago

Hi , i made the changes suggested. Let me know if there is anything else that's needed :)