#knn #nearest-neighbor #distance #dendritic #metrics #regressor #algorithm

dendritic-knn

Package for algorithms related to K Nearest Neighbors

5 stable releases

1.5.0 Nov 1, 2024
1.4.0 Nov 1, 2024
1.3.0 Nov 1, 2024
1.2.0 Nov 1, 2024
1.1.0 Oct 28, 2024

#1322 in Algorithms

Download history 82/week @ 2024-10-25 373/week @ 2024-11-01 12/week @ 2024-11-08 7/week @ 2024-11-15 2/week @ 2024-11-22

401 downloads per month
Used in 2 crates

MIT license

12KB
178 lines

Dendritic K Nearest Neighbors Crate

This crate contains functionality for performing K nearest neighbors for classification and regression. Package also contains all distance metrics that can be used across dendritic.

Features

  • KNN: KNN regressor and classifier.
  • Distance: Module with various distance metrics

Disclaimer

The dendritic project is a toy machine learning library built for learning and research purposes. It is not advised by the maintainer to use this library as a production ready machine learning library. This is a project that is still very much a work in progress.

Example Usage

This is an example of using the KNN classifier

use dendritic_datasets::iris::*;
use dendritic_knn::knn::*;
use dendritic_knn::distance::*; 

fn main() {

   // Load iris flowers dataset
   let (x, y) = load_iris("../dendritic-datasets/data/iris.parquet").unwrap();
   let (x_train, x_test) = x.split(0, 0.80).unwrap(); // split rows with 80/20 split
   let (y_train, y_test) = y.split(0, 0.80).unwrap();

   let clf = KNN::fit(
       &x_train, 
       &y_train, 
       4, 
       euclidean
   ).unwrap();

   let predictions = clf.predict(&x_test);
   println!("Actual: {:?}", predictions.values());
   println!("Prediction: {:?}", y_test.values()); 

}

Dependencies

~36MB
~714K SLoC