statistics.linear_regression
Prev: statistics.kde_random | Up: statistics | Next: statistics.mean
Rel: statistics.correlation, statistics.covariance, statistics.fmean, statistics.geometric_mean
Ref: docs.python.org — statistics.linear_regression
Tags: #public #python3 #stdlib #statistics
Import
import statistics
from statistics import linear_regression
Signature & Overview
statistics.linear_regression(x, y, /, *, proportional=False)
Slope and intercept for simple linear regression.
Usage
import statistics
if hasattr(statistics, 'linear_regression'):
slope, intercept = statistics.linear_regression([1, 2, 3], [3, 5, 7])
assert round(slope, 6) == 2.0 and round(intercept, 6) == 1.0
Gotchas
- Requires Python 3.10+: Pass
proportional=True(3.11+) to force the line through(0, 0).
REPL Inspect
from statistics import linear_regression
help(linear_regression)
Linked from
Related notes
- tuts/python3/stdlib_module/statistics/kde_random Linked here; links to this page; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/mean Linked here; links to this page; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/statistics/correlation Linked here; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/covariance Linked here; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/fmean Linked here; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/geometric_mean Linked here; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/harmonic_mean shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/kde shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/median shared tags: #statistics, #stdlib