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
| Name | Type | Description |
|---|---|---|
| x | sequence of real numbers | Paired observations, same length as the other sequence. |
| y | sequence of real numbers | Paired observations, same length as the other sequence. |
| proportional | bool | Force 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]))