ml_helper 0.0.2 copy "ml_helper: ^0.0.2" to clipboard
ml_helper: ^0.0.2 copied to clipboard

A lightweight Dart library for machine learning, with linear regression, preprocessing, and metrics.

example/main.dart

import 'package:ml_helper/ml_helper.dart';

void main() {
  final days = [1, 2, 3, 4, 5];
  final sales = [100, 150, 200, 250, 300];

  // 1️⃣ Preprocessing: normalize
  final normalizedSales = Preprocessing.minMaxNormalize(sales);
  print('Normalized Sales: $normalizedSales');

  // 2️⃣ Train/Test Split
  final split = Preprocessing.trainTestSplit(days, sales, 0.8);
  final xTrain = split['xTrain']!;
  final yTrain = split['yTrain']!;
  final xTest = split['xTest']!;
  final yTest = split['yTest']!;

  // 3️⃣ Train the model
  final model = LinearRegression();
  model.fit(xTrain, yTrain);

  // 4️⃣ Predict
  final predictions = xTest.map((x) => model.predict(x)).toList();
  print('Predictions: $predictions');

  // 5️⃣ Evaluate
  final mse = Metrics.meanSquaredError(predictions, yTest);
  final r2 = Metrics.rSquared(predictions, yTest);
  print('MSE: $mse, R²: $r2');
}
3
likes
160
points
12
downloads

Documentation

API reference

Publisher

verified publisherlutherbanze.com

Weekly Downloads

A lightweight Dart library for machine learning, with linear regression, preprocessing, and metrics.

Homepage

License

MIT (license)

Dependencies

flutter

More

Packages that depend on ml_helper