Skip to content

feat(linfa-linear): support sample weights in LinearRegression - #461

Open
divakantpandey wants to merge 1 commit into
rust-ml:masterfrom
divakantpandey:feature/linear-regression-weights
Open

divakantpandey wants to merge 1 commit into
rust-ml:masterfrom
divakantpandey:feature/linear-regression-weights

Conversation

@divakantpandey

Copy link
Copy Markdown

Resolves #328.

DatasetBase supports sample weights via .with_weights(), but LinearRegression::fit previously ignored them and performed unweighted ordinary least squares.

This PR adds Weighted Least Squares (WLS) support:

  • When dataset.weights() is present, design matrix rows and targets are scaled by sqrt(w_i) prior to the least squares solve.
  • Non-negative weights are validated, returning LinearError::InvalidWeights for negative values and linfa::Error::MismatchedShapes for length mismatches.
  • Retains the unweighted execution path with zero overhead when dataset.weights() is None.
  • Adds unit tests verifying outlier rejection, unweighted equivalence with uniform weights, multivariate weighting, f32 precision, dataset views, and first-order optimality conditions.

Support Weighted Least Squares (WLS) when sample weights are attached to DatasetBase. Scale design matrix rows and targets by the square root of sample weights prior to solving least squares, validate non-negative weights, and add unit tests covering outlier filtering and uniform weight equivalence.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let linfa_linear::LinearRegression support weights from a dataset

1 participant