From bce2e59cd57373d2f127bcf3e6f1eae50229850d Mon Sep 17 00:00:00 2001 From: Miguel Silva Date: Mon, 1 Apr 2024 14:57:23 +0100 Subject: [PATCH 1/3] Enhance docstring LinearRegression.fit --- sklearn/linear_model/_base.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sklearn/linear_model/_base.py b/sklearn/linear_model/_base.py index be8c9097332eb..3dcddf1b72d69 100644 --- a/sklearn/linear_model/_base.py +++ b/sklearn/linear_model/_base.py @@ -560,8 +560,15 @@ def fit(self, X, y, sample_weight=None): y : array-like of shape (n_samples,) or (n_samples, n_targets) Target values. Will be cast to X's dtype if necessary. - sample_weight : array-like of shape (n_samples,), default=None - Individual weights for each sample. + sample_weight : array-like of shape (n_samples,), int, float or None (default) + + The options are: + + - `array-like`: should contain the individual weight of each sample. + - `None`: all samples have a weight equal to 1. + - `int` or `float`: all samples have a weight equal to the value \ +provided. Since there is no difference in the relative weight between samples, it is \ +equal to the case where `sample_weight=None`. .. versionadded:: 0.17 parameter *sample_weight* support to LinearRegression. From 58b1bd77f58bc59747a7a9fcae35ec3756b23bbb Mon Sep 17 00:00:00 2001 From: Miguel Silva Date: Mon, 1 Apr 2024 15:00:18 +0100 Subject: [PATCH 2/3] Reword docstring --- sklearn/linear_model/_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/linear_model/_base.py b/sklearn/linear_model/_base.py index 3dcddf1b72d69..dce65c3d9a2e2 100644 --- a/sklearn/linear_model/_base.py +++ b/sklearn/linear_model/_base.py @@ -567,8 +567,8 @@ def fit(self, X, y, sample_weight=None): - `array-like`: should contain the individual weight of each sample. - `None`: all samples have a weight equal to 1. - `int` or `float`: all samples have a weight equal to the value \ -provided. Since there is no difference in the relative weight between samples, it is \ -equal to the case where `sample_weight=None`. +provided. Since there is no difference in the relative weight between samples, \ +results in the same fitted model as when `sample_weight=None`. .. versionadded:: 0.17 parameter *sample_weight* support to LinearRegression. From 54c32de361e11be429c16c2c1f7bcf667ea9724f Mon Sep 17 00:00:00 2001 From: Miguel Silva Date: Sun, 7 Apr 2024 13:25:05 +0100 Subject: [PATCH 3/3] Address PR comments --- sklearn/linear_model/_base.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sklearn/linear_model/_base.py b/sklearn/linear_model/_base.py index dce65c3d9a2e2..77da5de294fe4 100644 --- a/sklearn/linear_model/_base.py +++ b/sklearn/linear_model/_base.py @@ -560,15 +560,13 @@ def fit(self, X, y, sample_weight=None): y : array-like of shape (n_samples,) or (n_samples, n_targets) Target values. Will be cast to X's dtype if necessary. - sample_weight : array-like of shape (n_samples,), int, float or None (default) + sample_weight : float or array-like of shape (n_samples,), default=None The options are: + - `float`: all samples have a weight equal to the value provided. - `array-like`: should contain the individual weight of each sample. - `None`: all samples have a weight equal to 1. - - `int` or `float`: all samples have a weight equal to the value \ -provided. Since there is no difference in the relative weight between samples, \ -results in the same fitted model as when `sample_weight=None`. .. versionadded:: 0.17 parameter *sample_weight* support to LinearRegression.