summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2023-09-30 04:18:12 (GMT)
committerGitHub <noreply@github.com>2023-09-30 04:18:12 (GMT)
commit613c0d4e866341e15a66704643a6392ce49058ba (patch)
tree4fbf09b835c1fb4cc93304d0d95ed7fea1c4331a /Doc
parent14098b78f7453adbd40c53e32c29588611b7c87b (diff)
downloadcpython-613c0d4e866341e15a66704643a6392ce49058ba.zip
cpython-613c0d4e866341e15a66704643a6392ce49058ba.tar.gz
cpython-613c0d4e866341e15a66704643a6392ce49058ba.tar.bz2
Add example for linear_regression() with proportional=True. (gh-110133)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/statistics.rst19
1 files changed, 19 insertions, 0 deletions
diff --git a/Doc/library/statistics.rst b/Doc/library/statistics.rst
index a8a7901..f3c1bf2 100644
--- a/Doc/library/statistics.rst
+++ b/Doc/library/statistics.rst
@@ -14,6 +14,7 @@
.. testsetup:: *
from statistics import *
+ import math
__name__ = '<doctest>'
--------------
@@ -741,6 +742,24 @@ However, for reading convenience, most of the examples show sorted sequences.
*y = slope \* x + noise*
+ Continuing the example from :func:`correlation`, we look to see
+ how well a model based on major planets can predict the orbital
+ distances for dwarf planets:
+
+ .. doctest::
+
+ >>> model = linear_regression(period_squared, dist_cubed, proportional=True)
+ >>> slope = model.slope
+
+ >>> # Dwarf planets: Pluto, Eris, Makemake, Haumea, Ceres
+ >>> orbital_periods = [90_560, 204_199, 111_845, 103_410, 1_680] # days
+ >>> predicted_dist = [math.cbrt(slope * (p * p)) for p in orbital_periods]
+ >>> list(map(round, predicted_dist))
+ [5912, 10166, 6806, 6459, 414]
+
+ >>> [5_906, 10_152, 6_796, 6_450, 414] # actual distance in million km
+ [5906, 10152, 6796, 6450, 414]
+
.. versionadded:: 3.10
.. versionchanged:: 3.11