statistics.linear_regression()
statistics.linear_regression() is a Python function in the Statistics Module category. Returns a LinearRegression result with slope and intercept. The syntax is statistics.linear_regression(x, y, /). Parameters: x, y — paired datasets. Returns: LinearRegression named tuple. A typical example: reg = statistics.linear_regression([1,2,3], [2,4,6])
reg.slope # 2.0
reg.intercept # 0.0. A close sibling is statistics.mean(), which returns the arithmetic mean (average) of numeric data. A close sibling is statistics.median(), which returns the median (middle value) of numeric data. A close sibling is statistics.median_low(), which returns the low median of numeric data (for when there are an even number of values). A close sibling is statistics.median_high(), which returns the high median of numeric data. More about this category: Statistical functions — mean, median, mode, stdev, correlation. For a broader walkthrough, read the Statistics Module guide. Related Statistics Module entries: statistics.mean(), statistics.median(), statistics.median_low(), statistics.median_high(), statistics.mode(), statistics.multimode().