[Python-checkins] Fix inconsistent fsum vs sum and fmean vs mean (GH-25898) (GH-25899)
rhettinger
webhook-mailer at python.org
Tue May 4 14:55:40 EDT 2021
https://github.com/python/cpython/commit/af14e1df373c0a619c8ed3b02ebe44c1a90fd468
commit: af14e1df373c0a619c8ed3b02ebe44c1a90fd468
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2021-05-04T11:55:33-07:00
summary:
Fix inconsistent fsum vs sum and fmean vs mean (GH-25898) (GH-25899)
files:
M Lib/statistics.py
diff --git a/Lib/statistics.py b/Lib/statistics.py
index 673a162b3a79f..edb11c868c1c8 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -882,8 +882,8 @@ def covariance(x, y, /):
raise StatisticsError('covariance requires that both inputs have same number of data points')
if n < 2:
raise StatisticsError('covariance requires at least two data points')
- xbar = mean(x)
- ybar = mean(y)
+ xbar = fmean(x)
+ ybar = fmean(y)
total = fsum((xi - xbar) * (yi - ybar) for xi, yi in zip(x, y))
return total / (n - 1)
@@ -956,7 +956,7 @@ def linear_regression(regressor, dependent_variable, /):
slope = covariance(regressor, dependent_variable) / variance(regressor)
except ZeroDivisionError:
raise StatisticsError('regressor is constant')
- intercept = mean(dependent_variable) - slope * mean(regressor)
+ intercept = fmean(dependent_variable) - slope * fmean(regressor)
return LinearRegression(intercept=intercept, slope=slope)
More information about the Python-checkins
mailing list