mirror of
https://github.com/python/cpython.git
synced 2025-12-09 18:48:05 +00:00
Apply edits from Allen Downey's review of the linear_regression docs. (GH-26176)
This commit is contained in:
parent
fdc7e52f5f
commit
b3f65e819f
2 changed files with 15 additions and 23 deletions
|
|
@ -631,25 +631,25 @@ However, for reading convenience, most of the examples show sorted sequences.
|
||||||
Return the intercept and slope of `simple linear regression
|
Return the intercept and slope of `simple linear regression
|
||||||
<https://en.wikipedia.org/wiki/Simple_linear_regression>`_
|
<https://en.wikipedia.org/wiki/Simple_linear_regression>`_
|
||||||
parameters estimated using ordinary least squares. Simple linear
|
parameters estimated using ordinary least squares. Simple linear
|
||||||
regression describes relationship between *regressor* and
|
regression describes the relationship between *regressor* and
|
||||||
*dependent variable* in terms of linear function:
|
*dependent variable* in terms of this linear function:
|
||||||
|
|
||||||
*dependent_variable = intercept + slope \* regressor + noise*
|
*dependent_variable = intercept + slope \* regressor + noise*
|
||||||
|
|
||||||
where ``intercept`` and ``slope`` are the regression parameters that are
|
where ``intercept`` and ``slope`` are the regression parameters that are
|
||||||
estimated, and noise term is an unobserved random variable, for the
|
estimated, and noise represents the
|
||||||
variability of the data that was not explained by the linear regression
|
variability of the data that was not explained by the linear regression
|
||||||
(it is equal to the difference between prediction and the actual values
|
(it is equal to the difference between predicted and actual values
|
||||||
of dependent variable).
|
of dependent variable).
|
||||||
|
|
||||||
Both inputs must be of the same length (no less than two), and regressor
|
Both inputs must be of the same length (no less than two), and regressor
|
||||||
needs not to be constant, otherwise :exc:`StatisticsError` is raised.
|
needs not to be constant; otherwise :exc:`StatisticsError` is raised.
|
||||||
|
|
||||||
For example, if we took the data on the data on `release dates of the Monty
|
For example, we can use the `release dates of the Monty
|
||||||
Python films <https://en.wikipedia.org/wiki/Monty_Python#Films>`_, and used
|
Python films <https://en.wikipedia.org/wiki/Monty_Python#Films>`_, and used
|
||||||
it to predict the cumulative number of Monty Python films produced, we could
|
it to predict the cumulative number of Monty Python films
|
||||||
predict what would be the number of films they could have made till year
|
that would have been produced by 2019
|
||||||
2019, assuming that they kept the pace.
|
assuming that they kept the pace.
|
||||||
|
|
||||||
.. doctest::
|
.. doctest::
|
||||||
|
|
||||||
|
|
@ -659,14 +659,6 @@ However, for reading convenience, most of the examples show sorted sequences.
|
||||||
>>> round(intercept + slope * 2019)
|
>>> round(intercept + slope * 2019)
|
||||||
16
|
16
|
||||||
|
|
||||||
We could also use it to "predict" how many Monty Python films existed when
|
|
||||||
Brian Cohen was born.
|
|
||||||
|
|
||||||
.. doctest::
|
|
||||||
|
|
||||||
>>> round(intercept + slope * 1)
|
|
||||||
-610
|
|
||||||
|
|
||||||
.. versionadded:: 3.10
|
.. versionadded:: 3.10
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -930,15 +930,15 @@ def linear_regression(regressor, dependent_variable, /):
|
||||||
Return the intercept and slope of simple linear regression
|
Return the intercept and slope of simple linear regression
|
||||||
parameters estimated using ordinary least squares. Simple linear
|
parameters estimated using ordinary least squares. Simple linear
|
||||||
regression describes relationship between *regressor* and
|
regression describes relationship between *regressor* and
|
||||||
*dependent variable* in terms of linear function::
|
*dependent variable* in terms of linear function:
|
||||||
|
|
||||||
dependent_variable = intercept + slope * regressor + noise
|
dependent_variable = intercept + slope * regressor + noise
|
||||||
|
|
||||||
where ``intercept`` and ``slope`` are the regression parameters that are
|
where *intercept* and *slope* are the regression parameters that are
|
||||||
estimated, and noise term is an unobserved random variable, for the
|
estimated, and noise represents the variability of the data that was
|
||||||
variability of the data that was not explained by the linear regression
|
not explained by the linear regression (it is equal to the
|
||||||
(it is equal to the difference between prediction and the actual values
|
difference between predicted and actual values of dependent
|
||||||
of dependent variable).
|
variable).
|
||||||
|
|
||||||
The parameters are returned as a named tuple.
|
The parameters are returned as a named tuple.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue