How to do a Simple Linear Regression in Python
Wednesday, June 21st, 2006Have you ever wanted to fit a line to a set of data points using Python? Well, if you ever do, here’s how do to it:
Method 1:
The NumPy/SciPy package has a built in function; stats.linregress you can use. I didn’t choose this method because I didn’t want to fool with installing a package for my simple one-off need. There’s an example of using SciPy’s linear regression function here.
Method 2:
I found and modified the linreg function on this helpful website: Simple Recipes in Python by William Park.
(more…)
