ml_knn 1.0.1 copy "ml_knn: ^1.0.1" to clipboard
ml_knn: ^1.0.1 copied to clipboard

A simple K-Nearest Neighbors (KNN) algorithm implemented in Dart for educational and small-scale ML use.

๐Ÿ“ฆ ml_knn #

A production-ready K-Nearest Neighbors (KNN) classifier implemented in pure Dart.
Supports Euclidean, Manhattan, and Cosine distances, with optional weighting and normalization.
Perfect for lightweight ML tasks on mobile, web, or server-side Dart.


โœจ Features #

  • ๐Ÿง  Distance metrics: Euclidean, Manhattan, Cosine
  • โš–๏ธ Optional weighted voting
  • ๐Ÿ“Š Built-in normalization support
  • ๐Ÿ” Batch predictions
  • ๐Ÿ’พ Model serialization/deserialization
  • ๐Ÿงช Full test coverage

๐Ÿš€ Quick Start #

import 'package:ml_knn/ml_knn.dart';

void main() {
  final features = [
    [1.0, 0.0],
    [0.0, 1.0],
    [1.0, 1.0],
  ];
  final labels = ['A', 'B', 'A'];

  final knn = KNN(k: 3, normalize: true);
  knn.fit(features, labels);

  final prediction = knn.predict([1.2, 0.1]);
  print('Prediction: $prediction');

  final probs = knn.classProbabilities([1.2, 0.1]);
  print('Probabilities: $probs');
}
0
likes
125
points
19
downloads

Publisher

unverified uploader

Weekly Downloads

A simple K-Nearest Neighbors (KNN) algorithm implemented in Dart for educational and small-scale ML use.

Documentation

API reference

License

MIT (license)

Dependencies

collection

More

Packages that depend on ml_knn