liveBook · Manning

Linregress

As explained in Grokking Statistics

linregress is a SciPy statistical function that fits a simple linear regression and returns its estimated statistics.

linregress fits a simple straight line to paired x and y data. It estimates the slope and intercept, then returns related statistics for judging the relationship. section 7.7

Temperature and sports-drink sales

Pass temperature and sales arrays to scipy.stats.linregress, then unpack its results. For the example data, the slope is 9.74: sales increase by about 9.74 units per Fahrenheit degree. The intercept is -405.26, while Pearson correlation is 0.9889, the p-value is 0.0000000654, and the slope standard error is 0.5173. A strong fit can still mislead: ten observations are few, and predictions beyond the observed temperature range may generalize poorly. section 7.7

How Grokking Statistics covers it

How deep it goes
Explains outputs and interpretation, but stops short of deriving the regression algorithm.
Examples
Uses Fahrenheit temperatures and sports-drink sales, with printed statistics and a plotted regression line.
What it assumes
Builds from the line equation and scatterplot relationship while assuming basic Python array use.
What you can do after
Apply it via SciPy, interpret its estimates, and recognize limits on prediction from small or narrow datasets.
How it connects
Connects simple linear regression with slope, intercept, Pearson correlation, p-value, overfitting, and generalization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Statistics. The section links point to the parts of the book it draws on.