]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix inconsistent fsum vs sum and fmean vs mean (GH-25898) (GH-25899)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 4 May 2021 18:55:33 +0000 (11:55 -0700)
committerGitHub <noreply@github.com>
Tue, 4 May 2021 18:55:33 +0000 (11:55 -0700)
Lib/statistics.py

index 673a162b3a79fc047c8423642006d705e06b0099..edb11c868c1c8794569630229e2f44be76574d24 100644 (file)
@@ -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)