简体中文 | English
dataset-ml
Ready-to-use loaders for classic machine learning datasets, built on dataset-core.
Overview
dataset-ml ships with loaders for ten classic ML datasets. Each loader:
- Downloads the source file on first access (with
ureq). - Verifies a pinned SHA-256 hash to detect corruption or upstream changes.
- Parses the CSV into
ndarrayArray1/Array2. - Caches the parsed result in memory via
dataset_core::Dataset<T, E>— subsequent accesses return a&reference with zero I/O.
Each module is also a complete reference implementation of the pattern for wrapping Dataset<T, E> for a concrete data source.
Installation
[]
= "0.2"
Datasets
| Struct | Module path | Samples | Features | Task Type | Source |
|---|---|---|---|---|---|
Iris |
dataset_ml::iris |
150 | 4 | Classification | UCI ML Repository |
BreastCancer |
dataset_ml::breast_cancer |
569 | 30 | Classification | UCI ML Repository |
BostonHousing |
dataset_ml::boston_housing |
506 | 13 | Regression | UCI ML Repository |
CaliforniaHousing |
dataset_ml::california_housing |
20,640 | 8 | Regression | StatLib (1990 census) |
Diabetes |
dataset_ml::diabetes |
768 | 8 | Classification | Kaggle |
Titanic |
dataset_ml::titanic |
891 | 11 | Classification | Kaggle |
PalmerPenguins |
dataset_ml::palmer_penguins |
344 | 7 | Classification | palmerpenguins |
WineRecognition |
dataset_ml::wine_recognition |
178 | 13 | Classification | UCI ML Repository |
RedWineQuality |
dataset_ml::wine_quality::red_wine_quality |
1,599 | 11 | Regression | UCI ML Repository |
WhiteWineQuality |
dataset_ml::wine_quality::white_wine_quality |
4,898 | 11 | Regression | UCI ML Repository |
All structs are also re-exported at the crate root, so dataset_ml::Iris, dataset_ml::RedWineQuality, etc. work too.
Usage
use Iris;
Each dataset struct follows the same pattern:
new(storage_dir)— create instance (no I/O)features()— reference to feature matrixlabels()/targets()— reference to label/target vectordata()— all references at once
Note: Titanic and Palmer Penguins are mixed-type:
features()returns(&Array2<String>, &Array2<f64>)(string + numeric features), anddata()returns a triple. Palmer Penguins also represents missing values asNaN(numeric) or""(string).Note: California Housing reproduces scikit-learn's
fetch_california_housingfeatures by deriving them from the raw census columns (e.g.AveRooms = total_rooms / households) and scaling the target by1/100000. Its 207 missingtotal_bedroomsvalues surface asNaNinAveBedrms.
Migration from dataset-core 0.1.x
If you used the datasets feature of dataset-core 0.1.x, switch to this crate:
- dataset-core = { version = "0.1", features = ["datasets"] }
+ dataset-ml = "0.2"
| Old path | New path |
|---|---|
dataset_core::datasets::iris::Iris |
dataset_ml::iris::Iris |
dataset_core::datasets::boston_housing::BostonHousing |
dataset_ml::boston_housing::BostonHousing |
dataset_core::datasets::diabetes::Diabetes |
dataset_ml::diabetes::Diabetes |
dataset_core::datasets::titanic::Titanic |
dataset_ml::titanic::Titanic |
dataset_core::datasets::wine_quality::red_wine_quality::RedWineQuality |
dataset_ml::wine_quality::red_wine_quality::RedWineQuality |
dataset_core::datasets::wine_quality::white_wine_quality::WhiteWineQuality |
dataset_ml::wine_quality::white_wine_quality::WhiteWineQuality |
dataset_core::utils::* and dataset_core::DatasetError are unchanged — they remain in dataset-core under the utils feature.
Performance Considerations
- First access: downloads the file (if not on disk), validates SHA-256, parses, caches in memory.
- Subsequent accesses: return a reference to the cached data — zero allocation, zero I/O.
.to_owned(): clones cached data into a new owned value — use only when mutation is needed.- Offline: once downloaded, datasets stay on disk; no network needed on subsequent runs.
License
This project is licensed under the MIT License — see LICENSE for details.
Datasets Attribution
The bundled datasets are classic machine learning datasets widely used for educational and research purposes:
- Iris: Fisher's Iris dataset (1936)
- Breast Cancer Wisconsin (Diagnostic): Wolberg, Mangasarian, Street & Street (1995)
- Boston Housing: Harrison & Rubinfeld (1978)
- California Housing: Pace & Barry (1997), from the 1990 U.S. census
- Diabetes: Pima Indians Diabetes Database
- Titanic: Kaggle Titanic dataset
- Palmer Penguins: Horst, Hill & Gorman (2020); data by Gorman, Williams & Fraser (2014)
- Wine Recognition: Aeberhard & Forina (1991), UCI Machine Learning Repository
- Wine Quality: UCI Machine Learning Repository
Author
SomeB1oody — stanyin64@gmail.com