Statistics Functions

statistics.linear_regression()

Fit a least-squares straight line y = slope*x + intercept to paired data. proportional=True forces the intercept to zero. Default fit requires varying x values.

Formal Syntax & Structure

python syntaxpython
statistics.linear_regression(x, y, /, *, proportional=False)

Parameters & Attributes

NameTypeDescription
xsequence of real numbersPaired observations, same length as the other sequence.
ysequence of real numbersPaired observations, same length as the other sequence.
proportionalboolForce the regression intercept to zero when true.

Return Value

LinearRegression

Named tuple containing slope and intercept.

Working Example

Example Snippetpython
import statisticsprint(statistics.linear_regression([1, 2, 3], [3, 5, 7]))
Python Reference