Skip to content

Commit 1add719

Browse files
authored
Fix inconsistent fsum vs sum and fmean vs mean (GH-25898)
1 parent 9ee8448 commit 1add719

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Lib/statistics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,8 @@ def covariance(x, y, /):
882882
raise StatisticsError('covariance requires that both inputs have same number of data points')
883883
if n < 2:
884884
raise StatisticsError('covariance requires at least two data points')
885-
xbar = mean(x)
886-
ybar = mean(y)
885+
xbar = fmean(x)
886+
ybar = fmean(y)
887887
total = fsum((xi - xbar) * (yi - ybar) for xi, yi in zip(x, y))
888888
return total / (n - 1)
889889

@@ -956,7 +956,7 @@ def linear_regression(regressor, dependent_variable, /):
956956
slope = covariance(regressor, dependent_variable) / variance(regressor)
957957
except ZeroDivisionError:
958958
raise StatisticsError('regressor is constant')
959-
intercept = mean(dependent_variable) - slope * mean(regressor)
959+
intercept = fmean(dependent_variable) - slope * fmean(regressor)
960960
return LinearRegression(intercept=intercept, slope=slope)
961961

962962

0 commit comments

Comments
 (0)