diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2021-05-04 18:27:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-04 18:27:28 (GMT) |
commit | 1add719516f49aacd260c44f9dcbd6af269fdb21 (patch) | |
tree | 799aafd244a2ca4ddf3b329abaef5f5f15ffdf71 | |
parent | 9ee8448243e776d2a07a9868e9795bbb2c828f9c (diff) | |
download | cpython-1add719516f49aacd260c44f9dcbd6af269fdb21.zip cpython-1add719516f49aacd260c44f9dcbd6af269fdb21.tar.gz cpython-1add719516f49aacd260c44f9dcbd6af269fdb21.tar.bz2 |
Fix inconsistent fsum vs sum and fmean vs mean (GH-25898)
-rw-r--r-- | Lib/statistics.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/statistics.py b/Lib/statistics.py index 673a162..edb11c8 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) |