-
-
Notifications
You must be signed in to change notification settings - Fork 305
[Feature] Add Least Angle Regression #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+965
−0
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6943196
Implement Least Angle Regression
aswin-1111 44ea45d
cargo fmt
aswin-1111 58d6b8b
cargo clippy
aswin-1111 85c28ca
cargo clippy 2
aswin-1111 57078d0
improve documentation
aswin-1111 1dfc75c
remove linnerud dependency
aswin-1111 09e56eb
add example
aswin-1111 a8e485e
cargo clippy in doc test
aswin-1111 206ab98
Apply suggestions from code review
aswin-1111 1f6b34f
close bracket
aswin-1111 9817335
remove unwanted stride handling
aswin-1111 2abbe1a
Merge branch 'master' into master
relf b28824b
correct doc example
aswin-1111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.