Package website: release | dev
Integration of Hugging Face datasets with the mlr3 ecosystem.
What is mlr3hf?
Hugging Face provides a large collection of datasets for machine learning and data science. mlr3hf connects these datasets with the mlr3 ecosystem.
Datasets can be downloaded from Hugging Face and converted into mlr3 data backends and tasks.
mlr3hf supports both Parquet datasets generated by Hugging Face and the original dataset files stored in a repository.
Installation
Install the last release from CRAN:
install.packages("mlr3hf")Install the development version from GitHub:
pak::pak("mlr-org/mlr3hf")Example
Loading a Hugging Face dataset
hfdt() creates an HFData object representing a Hugging Face dataset. The object provides access to the dataset and its metadata and can be converted into an mlr3::Task.
hf_data = hfdt(
repo_id = "scikit-learn/iris",
config = "default",
target = "Species",
task_type = "classif"
)
hf_data
#> <HFData:scikit-learn/iris> (150x7)
#> * Storage: 5.06 MB - This storage is for the whole repository, not for a single file or configCreating an mlr3 Task
The HFData object can be converted into an mlr3::Task.
task = as_task(hf_data)
task
#>
#> ── <TaskClassif> (150x6) ───────────────────────────────────────────────────────────────────────────────────────────────
#> • Target: Species
#> • Target classes: Iris-setosa (33%), Iris-versicolor (33%), Iris-virginica (33%)
#> • Properties: multiclass
#> • Features (5):
#> • dbl (5): Id, PetalLengthCm, PetalWidthCm, SepalLengthCm, SepalWidthCmBasic train + predict
The resulting task can be used with the mlr3 ecosystem in the same way as other mlr3 tasks.
learner = lrn("classif.rpart")
split = partition(task, ratio = 0.67)
learner$train(task, split$train_set)
prediction = learner$predict(task, split$test_set)
prediction$score(msr("classif.acc"))
#> classif.acc
#> 1Resample
The task can also be used directly with mlr3 resampling strategies.
resampling = rsmp("cv", folds = 3L)
rr = resample(task, learner, resampling)
rr$aggregate()
#> classif.ce
#> 0Direct task construction
For workflows where the intermediate HFData object is not required, tsk() can be used to construct an mlr3::Task directly.
task = tsk(
"hf",
repo_id = "scikit-learn/iris",
config = "default",
target = "Species",
task_type = "classif"
)
task
#>
#> ── <TaskClassif> (150x6) ───────────────────────────────────────────────────────────────────────────────────────────────
#> • Target: Species
#> • Target classes: Iris-setosa (33%), Iris-versicolor (33%), Iris-virginica (33%)
#> • Properties: multiclass
#> • Features (5):
#> • dbl (5): Id, PetalLengthCm, PetalWidthCm, SepalLengthCm, SepalWidthCmDocumentation
The package documentation contains the complete documentation and examples for mlr3hf.
For more information about the mlr3 ecosystem, see the mlr3 book.
Extension Packages
mlr3hf is part of the mlr3 ecosystem and can be used together with the many extension packages available for mlr3.
For example, mlr3learners provides learners that can be used with tasks created by mlr3hf.
See the mlr3 ecosystem for a complete list of extension packages.
Contributing to mlr3hf
mlr3hf is a free and open source software.
If you encounter problems using the package, find missing or misleading documentation, or want to suggest a feature, please open an issue in the issue tracker.
Pull requests are welcome and will be included at the discretion of the maintainers.
Please consult the mlr3 wiki for development and contribution guidelines.
