ml_knn 1.0.1
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');
}