ml_metrics 0.1.0

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

A lightweight and easy-to-use Dart library for evaluating machine learning models. Includes accuracy, precision, recall, F1 score, and confusion matrix for binary classification.

📊 ml_metrics

A lightweight and efficient Dart library for evaluating machine learning models.
Supports binary classification metrics such as Accuracy, Precision, Recall, F1 Score, and Confusion Matrix.


✨ Features

  • ✅ Accuracy score
  • ✅ Precision & Recall (binary classification)
  • ✅ F1 Score
  • ✅ Confusion Matrix
  • ✅ Fully tested & null-safe

📦 Installation

Add the following to your pubspec.yaml:

dependencies:
  ml_metrics: ^0.1.0

Then run:

dart pub get

🚀 Quick Example

import 'package:ml_metrics/ml_metrics.dart';

void main() {
  final yTrue = [1, 0, 1, 1, 0];
  final yPred = [1, 0, 0, 1, 1];

  print('Accuracy: ${accuracy(yTrue, yPred)}');
  print('Precision: ${precision(yTrue, yPred)}');
  print('Recall: ${recall(yTrue, yPred)}');
  print('F1 Score: ${f1Score(yTrue, yPred)}');
  print('Confusion Matrix: ${binaryConfusionMatrix(yTrue, yPred)}');
}

📚 Metrics Reference

MetricDescription
accuracyRatio of correct predictions
precisionTP / (TP + FP)
recallTP / (TP + FN)
f1ScoreHarmonic mean of precision and recall
binaryConfusionMatrixReturns [TP, FP, FN, TN] as a list

🧪 Run Tests

dart test


📄 License

This project is licensed under the MIT License. See the LICENSE file for details.