Expand description
§automl with smartcore
Train, compare, and predict with machine-learning models in Rust, using SmartCore estimators and configurable preprocessing.
§Install
automl = "0.3.1"§Quickstart
Compare classifiers with cross-validation, inspect their scores, and predict with the best model:
use automl::{ClassificationModel, ClassificationSettings, DenseMatrix};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rows: Vec<Vec<f64>> = (0..24).map(|i| vec![f64::from(i)]).collect();
let features = DenseMatrix::from_2d_vec(&rows)?;
let labels: Vec<u32> = (0..24).map(|i| u32::from(i >= 12)).collect();
let settings = ClassificationSettings::default().with_number_of_folds(3);
let mut classifier = ClassificationModel::new(features, labels, settings);
classifier.train()?;
println!("{classifier}");
let predictions = classifier.predict(DenseMatrix::from_2d_array(&[&[2.0], &[20.0]])?)?;
println!("Predictions: {predictions:?}");
Ok(())
}A successful train() replaces the previous results. A failed retraining attempt
preserves the last successful model and fitted preprocessing; settings edits are
retained so you can correct them and retry.
§Models and preprocessing
- Regression: linear, ridge, lasso, elastic net, decision trees, random forests,
extra trees, KNN, support vector regression, and
XGBoost. - Classification: decision trees, random forests, logistic regression, KNN, support vector classifiers, and naive Bayes variants.
- Clustering: K-means, DBSCAN, and agglomerative clustering.
- Preprocessing: scaling, imputation, categorical encoding, power transforms, column selection, PCA/SVD, interactions, and polynomial features.
Configure algorithms and pipelines through
settings.
Fitted preprocessing is reused for inference. See the
cookbook for pipeline
recipes and complete workflows.
§Examples and CSV input
cargo run --example breast_cancer_csv
cargo run --example diabetes_regressionCSV loading is available without feature flags through
load_csv_features
and load_labeled_csv.
Re-exports§
pub use settings::ClassificationSettings;pub use settings::ClusteringSettings;pub use settings::RegressionSettings;pub use algorithms::ClassificationAlgorithm;pub use algorithms::ClusteringAlgorithm;pub use algorithms::RegressionAlgorithm;pub use model::ClassificationModel;pub use model::ClusteringModel;pub use model::ModelError;pub use model::ModelResult;pub use model::RegressionModel;pub use model::SupervisedModel;
Modules§
- algorithms
- Algorithm enumerations and helpers. Algorithm enumerations and helpers for model training.
- cookbook
- A cookbook of common
AutoMLtasks - metrics
- Metric re-exports. Re-exported clustering metrics.
- model
- Model definitions and implementations. Types and implementations for machine learning models.
- settings
- Settings customization
- utils
- Utility functions for the crate.
Structs§
- Dense
Matrix - Dense matrix