GH-102670: Use sumprod() to simplify, speed up, and improve accuracy of statistics functions (GH-102649)

This commit is contained in:
Raymond Hettinger 2023-03-13 20:06:43 -05:00 committed by GitHub
parent 61479d4684
commit 457e4d1a51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 13 deletions

View file

@ -1,4 +1,4 @@
"""Test suite for statistics module, including helper NumericTestCase and
x = """Test suite for statistics module, including helper NumericTestCase and
approx_equal function.
"""
@ -2610,6 +2610,16 @@ class TestLinearRegression(unittest.TestCase):
self.assertAlmostEqual(slope, 20 + 1/150)
self.assertEqual(intercept, 0.0)
def test_float_output(self):
x = [Fraction(2, 3), Fraction(3, 4)]
y = [Fraction(4, 5), Fraction(5, 6)]
slope, intercept = statistics.linear_regression(x, y)
self.assertTrue(isinstance(slope, float))
self.assertTrue(isinstance(intercept, float))
slope, intercept = statistics.linear_regression(x, y, proportional=True)
self.assertTrue(isinstance(slope, float))
self.assertTrue(isinstance(intercept, float))
class TestNormalDist:
# General note on precision: The pdf(), cdf(), and overlap() methods