summaryrefslogtreecommitdiffstats
path: root/Lib/statistics.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2021-06-04 23:28:31 (GMT)
committerGitHub <noreply@github.com>2021-06-04 23:28:31 (GMT)
commit3668e118f77c4e53167b75352c53674e758e1877 (patch)
treeaec2f5a0559cde8aa724e2b8d231a444e5135c47 /Lib/statistics.py
parentdda9ecbfece28aad7b8ba7eaf7951dd9816f78b1 (diff)
downloadcpython-3668e118f77c4e53167b75352c53674e758e1877.zip
cpython-3668e118f77c4e53167b75352c53674e758e1877.tar.gz
cpython-3668e118f77c4e53167b75352c53674e758e1877.tar.bz2
Update nonstandard variable names (GH-26540)
Diffstat (limited to 'Lib/statistics.py')
-rw-r--r--Lib/statistics.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/statistics.py b/Lib/statistics.py
index 26009b0..1314095 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -924,10 +924,10 @@ def correlation(x, y, /):
xbar = fsum(x) / n
ybar = fsum(y) / n
sxy = fsum((xi - xbar) * (yi - ybar) for xi, yi in zip(x, y))
- s2x = fsum((xi - xbar) ** 2.0 for xi in x)
- s2y = fsum((yi - ybar) ** 2.0 for yi in y)
+ sxx = fsum((xi - xbar) ** 2.0 for xi in x)
+ syy = fsum((yi - ybar) ** 2.0 for yi in y)
try:
- return sxy / sqrt(s2x * s2y)
+ return sxy / sqrt(sxx * syy)
except ZeroDivisionError:
raise StatisticsError('at least one of the inputs is constant')
@@ -968,9 +968,9 @@ def linear_regression(x, y, /):
xbar = fsum(x) / n
ybar = fsum(y) / n
sxy = fsum((xi - xbar) * (yi - ybar) for xi, yi in zip(x, y))
- s2x = fsum((xi - xbar) ** 2.0 for xi in x)
+ sxx = fsum((xi - xbar) ** 2.0 for xi in x)
try:
- slope = sxy / s2x # equivalent to: covariance(x, y) / variance(x)
+ slope = sxy / sxx # equivalent to: covariance(x, y) / variance(x)
except ZeroDivisionError:
raise StatisticsError('x is constant')
intercept = ybar - slope * xbar