From a11965a46e4313640b542a99e01afc5594c6e87e Mon Sep 17 00:00:00 2001 From: Aiden Frank Date: Wed, 30 Apr 2025 14:36:08 -0400 Subject: [PATCH 1/2] What does this implement/fix? This is intended to add a link to the Non-negative least squares example in the LimearRegression API page. It is towards #30621. The following example is used: `plot_nnls.py` This example is linked in the User Guide for Linear Regression, but not anywhere on the API page. --- sklearn/linear_model/_base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sklearn/linear_model/_base.py b/sklearn/linear_model/_base.py index 78c118168e122..7388174676704 100644 --- a/sklearn/linear_model/_base.py +++ b/sklearn/linear_model/_base.py @@ -558,6 +558,9 @@ class LinearRegression(MultiOutputMixin, RegressorMixin, LinearModel): np.float64(3.0...) >>> reg.predict(np.array([[3, 5]])) array([16.]) + + For an example of using Non-negative least squares in linear regression see + :ref:`sphx_glr_auto_examples_linear_model_plot_nnls.py`. """ _parameter_constraints: dict = { From d0295e12f0bf18cf3b313ca04495a0b257bce7c6 Mon Sep 17 00:00:00 2001 From: Aiden Frank Date: Wed, 30 Apr 2025 23:35:43 -0400 Subject: [PATCH 2/2] Update sklearn/linear_model/_base.py --- sklearn/linear_model/_base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sklearn/linear_model/_base.py b/sklearn/linear_model/_base.py index 7388174676704..1c9ab10531177 100644 --- a/sklearn/linear_model/_base.py +++ b/sklearn/linear_model/_base.py @@ -494,6 +494,10 @@ class LinearRegression(MultiOutputMixin, RegressorMixin, LinearModel): When set to ``True``, forces the coefficients to be positive. This option is only supported for dense arrays. + For a comparison between a linear regression model with positive constraints + on the regression coefficients and a linear regression without such constraints, + see :ref:`sphx_glr_auto_examples_linear_model_plot_nnls.py`. + .. versionadded:: 0.24 Attributes @@ -558,9 +562,6 @@ class LinearRegression(MultiOutputMixin, RegressorMixin, LinearModel): np.float64(3.0...) >>> reg.predict(np.array([[3, 5]])) array([16.]) - - For an example of using Non-negative least squares in linear regression see - :ref:`sphx_glr_auto_examples_linear_model_plot_nnls.py`. """ _parameter_constraints: dict = {