10000 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
Use generator for y array in linear_regression()
  • Loading branch information
rhettinger committed Mar 13, 2023
commit a4486157c189a61d67cec6a25463bb60cb8f26d8
4 changes: 2 additions & 2 deletions Lib/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,8 @@ def linear_regression(x, y, /, *, proportional=False):
if not proportional:
xbar = fsum(x) / n
ybar = fsum(y) / n
x = [xi - xbar for xi in x]
y = [yi - ybar for yi in y]
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)
sxx = sumprod(x, x)
try:
Expand Down
0