bpo-45766: Add direct proportion option to linear_regression(). (#29490)

* bpo-45766: Add direct proportion option to linear_regression().

* Update 2021-11-09-09-18-06.bpo-45766.dvbcMf.rst

* Use ellipsis to avoid round-off issues.

* Update Misc/NEWS.d/next/Library/2021-11-09-09-18-06.bpo-45766.dvbcMf.rst

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>

* Update signature in main docs

* Fix missing comma

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
Raymond Hettinger 2021-11-21 08:39:26 -06:00 committed by GitHub
parent 2afa1a1266
commit d2b55b07d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 8 deletions

View file

@ -2527,6 +2527,12 @@ class TestLinearRegression(unittest.TestCase):
self.assertAlmostEqual(intercept, true_intercept)
self.assertAlmostEqual(slope, true_slope)
def test_proportional(self):
x = [10, 20, 30, 40]
y = [180, 398, 610, 799]
slope, intercept = statistics.linear_regression(x, y, proportional=True)
self.assertAlmostEqual(slope, 20 + 1/150)
self.assertEqual(intercept, 0.0)
class TestNormalDist: