MLUtils.jl defines interfaces and implements common utilities for Machine Learning pipelines.
- An extensible dataset interface (
- Data iteration and dataloaders (
- Lazy data views (
- Resampling procedures (
- Train/test splits (
- Data partitioning and aggregation tools (
- Folds for cross-validation (
- Datasets lazy tranformations (
- Toy datasets for demonstration purpose.
- Other data handling utilities (
Let us take a look at a hello world example to get a feeling for how to use this package in a typical ML scenario.
using MLUtils # X is a matrix of floats # Y is a vector of strings X, Y = load_iris() # The iris dataset is ordered according to their labels, # which means that we should shuffle the dataset before # partitioning it into training- and test-set. Xs, Ys = shuffleobs((X, Y)) # We leave out 15 % of the data for testing cv_data, test_data = splitobs((Xs, Ys); at=0.85) # Next we partition the data using a 10-fold scheme. for (train_data, val_data) in kfolds(cv_data; k=10) # We apply a lazy transform for data augmentation train_data = mapobs(xy -> (xy .+ 0.1 .* randn.(), xy), train_data) for epoch = 1:10 # Iterate over the data using mini-batches of 5 observations each for (x, y) in eachobs(train_data, batchsize=5) # ... train supervised model on minibatches here end end end
In the above code snippet, the inner loop for
eachobs is the
only place where data other than indices is actually being
copied. In fact, while
y are materialized arrays,
all the rest are data views.
Other features were ported from the deep learning library Flux.jl, as they are of general use.
MLJ.jl is a more complete package for managing the whole machine learning pipeline if you are looking for a sklearn replacement.