Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions algorithms/linfa-lars/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "linfa-lars"
version = "0.8.0"
authors = ["Aswin <[email protected]>"]
description = "Least Angle Regression methods"
edition = "2024"
license = "MIT OR Apache-2.0"

repository = "https://github.com/rust-ml/linfa"
readme = "README.md"

keywords = ["machine-learning", "linfa", "ai", "ml", "linear"]
categories = ["algorithms", "mathematics", "science"]

[features]
default = []
serde = ["serde_crate", "ndarray/serde", "linfa/serde"]
blas = ["ndarray-linalg", "linfa/ndarray-linalg"]

[dependencies.serde_crate]
package = "serde"
optional = true
version = "1.0"
default-features = false
features = ["std", "derive"]

[dependencies]
linfa = { version = "0.8.0", path = "../.." }
linfa-linalg = { version = "0.2", default-features = false }
linfa-preprocessing = { version = "0.8.0" , path = "../linfa-preprocessing"}
ndarray = { version = "0.16", features = ["approx"] }
ndarray-linalg = { version = "0.17", optional = true }
ndarray-stats = "0.6"
thiserror = "2.0"

[dev-dependencies]
linfa-datasets = { version = "0.8.0", path = "../../datasets", features = [
"diabetes",
] }
approx = "0.5"
ndarray-rand = "0.15"
rand_xoshiro = "0.6"
32 changes: 32 additions & 0 deletions algorithms/linfa-lars/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Least Angle Regression

`linfa-lars` aims to provide pure Rust implementation of least-angle regression algorithm.

## The Big Picture

`linfa-lars` is a crate in the [`linfa`](https://crates.io/crates/linfa) ecosystem, an effort to create a toolkit for classical Machine Learning implemented in pure Rust, akin to Python's `scikit-learn`.

## Current state

The `linfa-lars` crate currently provides an implementation of the Least-angle regression (LARS) algorithm

See also:
* [Wikipedia on Least Angle Regression](https://en.wikipedia.org/wiki/Least-angle_regression)


## BLAS/Lapack backend

See [this section](../../README.md#blaslapack-backend) to enable an external BLAS/LAPACK backend.

## Examples

There is an usage example in the `examples/` directory. To run, use:

```bash
$ cargo run --example lars
```

## License
Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <http://opensource.org/licenses/MIT>, at your option. This file may not be copied, modified, or distributed except according to those terms.
20 changes: 20 additions & 0 deletions algorithms/linfa-lars/examples/lars.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use linfa::prelude::*;
use linfa_lars::Lars;

fn main() {
// load Diabetes dataset
let (train, valid) = linfa_datasets::diabetes().split_with_ratio(0.90);

let model = Lars::params()
.fit_intercept(true)
.verbose(true)
.fit(&train)
.unwrap();

println!("hyperplane: {}", model.hyperplane());
println!("intercept: {}", model.intercept());

// validate
let y_est = model.predict(&valid);
println!("predicted variance: {}", valid.r2(&y_est).unwrap());
}
Loading
Loading