rust-ml / rust-ml/linfa

Let linfa_linear::LinearRegression support weights from a dataset

Open
#328 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
4.7k
Forks
334
Avg merge
39m
Merged PRs (30d)
1

Description

I just stumbled that when updating a dataset with weights, that those weights don't get respected when doing linear regression. After looking in the source code for the fit() method, only X and y get extracted from the dataset. Would it be possible to add those weights in the fit()-method?

https://github.com/rust-ml/linfa/blob/d4955622a4546ce4e2ea8ba061f826dcdc11a25d/algorithms/linfa-linear/src/ols.rs#L107C4-L132C6

I am still a newbie in Rust, but I guess an updated version would look somewhat like this:

// snip line 108 and above
let y = dataset.as_single_targets();
let w = dataset.weights().unwrap_or_else(Array::ones(X.ncols()); // Use weights of 1 if no weights are provided

// snip 110-116
    let X = concatenate(Axis(1), &[X.view(), Array2::ones((X.nrows(), 1)).view()]).unwrap();
    let X = X * w;
 // snip 118-124
    let (X, y) = (X.to_owned(), y.to_owned());
    let X = X * w;

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in algorithms/linfa-linear/src/ols.rs at the fit() method linked in the issue, and inspect how the dataset currently provides X and y. Confirm the dataset weights API and the intended weighted-regression behavior; the work is done when supplied weights affect linear regression while datasets without weights continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
machine-learning
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.