ml_dataset_loader

ml_dataset_loader is a lightweight Dart library for loading structured datasets from CSV files. It is designed with performance and flexibility in mind, offering support for type inference, quoted fields, and stream-based reading for large files.

โœจ Features

  • ๐Ÿš€ Efficient stream-based reading (memory-friendly for large datasets)
  • ๐Ÿ“Š Automatic type inference (int, double, bool, DateTime, String)
  • ๐Ÿ“ Optional header support
  • ๐Ÿงฉ Customizable delimiter and quote character
  • โ— Detailed error reporting via CsvFormatException

๐Ÿ“ฆ Installation

Add the following to your pubspec.yaml:

dependencies:
  ml_dataset_loader:
    git:
      url: https://github.com/CelkMehmett/ml_dataset_loader.git

Replace the URL with your own repository link if hosted privately or publicly.

๐Ÿ“š Usage

import 'package:ml_dataset_loader/ml_dataset_loader.dart';

void main() async {
  final dataset = await loadCsvDataset(
    'assets/iris.csv',
    options: const CsvOptions(
      delimiter: ',',
      hasHeader: true,
      quote: '"',
    ),
  );

  print('Row count: ${dataset.rowCount}');
  print('First row: ${dataset.rows.first}');
}

๐Ÿง  Dataset Model

The Dataset class holds structured data as:

class Dataset {
  final List<String>? headers;
  final List<List<dynamic>> rows;
}

โš™๏ธ CsvOptions

Customize how your CSV is parsed:

class CsvOptions {
  final String delimiter; // e.g., ',', ';', '\t'
  final bool hasHeader;   // true if the first row is a header
  final String quote;     // e.g., '"'
}

๐Ÿงช Testing

Sample test with test/assets/sample.csv:

import 'package:test/test.dart';
import 'package:ml_dataset_loader/ml_dataset_loader.dart';

void main() {
  test('Load sample CSV dataset', () async {
    final dataset = await loadCsvDataset(
      'test/assets/sample.csv',
      options: const CsvOptions(hasHeader: true),
    );

    expect(dataset.headers, containsAll(['city', 'population']));
    expect(dataset.rows.length, equals(3));
  });
}

๐Ÿ“ File Format Example

assets/iris.csv

sepal_length,sepal_width,petal_length,petal_width,species
5.1,3.5,1.4,0.2,Iris-setosa
...

๐Ÿ“„ License

MIT ยฉ 2025 Your Name