Crates.io | linfa-elasticnet |
lib.rs | linfa-elasticnet |
version | 0.7.0 |
source | src |
created_at | 2021-01-20 19:00:47.517048 |
updated_at | 2023-10-16 04:45:26.865518 |
description | A Machine Learning framework for Rust |
homepage | |
repository | https://github.com/rust-ml/linfa |
max_upload_size | |
id | 344543 |
size | 83,179 |
linfa-elasticnet
provides a pure Rust implementations of elastic net linear regression.
linfa-elasticnet
is a crate in the linfa
ecosystem, an effort to create a toolkit for classical Machine Learning implemented in pure Rust, akin to Python's scikit-learn
.
The linfa-elasticnet
crate provides linear regression with ridge and LASSO constraints. The solver uses coordinate descent to find an optimal solution.
This library contains an elastic net implementation for linear regression models. It combines l1 and l2 penalties of the LASSO and ridge methods and offers therefore a greater flexibility for feature selection. With increasing penalization certain parameters become zero, their corresponding variables are dropped from the model.
See also:
See this section to enable an external BLAS/LAPACK backend.
There is an usage example in the examples/
directory. To run, use:
$ cargo run --example elasticnet
use linfa::prelude::*;
use linfa_elasticnet::{ElasticNet, Result};
// load Diabetes dataset
let (train, valid) = linfa_datasets::diabetes().split_with_ratio(0.90);
// train pure LASSO model with 0.1 penalty
let model = ElasticNet::params()
.penalty(0.3)
.l1_ratio(1.0)
.fit(&train)?;
println!("intercept: {}", model.intercept());
println!("params: {}", model.hyperplane());
println!("z score: {:?}", model.z_score());
// validate
let y_est = model.predict(&valid);
println!("predicted variance: {}", valid.r2(&y_est)?);
# Result::Ok(())