8000 GH-102670: Use sumprod() to simplify, speed up, and improve accuracy of statistics functions by rhettinger · Pull Request #102649 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 14, 2023
Prev Previous commit
Next Next commit
Coerce result to a float
  • Loading branch information
rhettinger committed Mar 13, 2023
commit c9a4e4d39acb2dd607b3ddffa3d539f772f5ab86
2 changes: 1 addition & 1 deletion Lib/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ def linear_regression(x, y, /, *, proportional=False):
ybar = fsum(y) / n
x = [xi - xbar for xi in x] # List because used three times below
y = (yi - ybar for yi in y) # Generator because only used once below
sxy = sumprod(x, y)
sxy = sumprod(x, y) + 0.0 # Add zero to coerce result to a float
sxx = sumprod(x, x)
try:
slope = sxy / sxx # equivalent to: covariance(x, y) / variance(x)
Expand Down
0