linregress(x, y, full=False, **kwargs)[source]#

Simple linear regression returning the line of best fit and R value. Similar to scipy.stats.linregress`() but simpler.

  • x (array) – the x coordinates

  • y (array) – the y coordinates

  • full (bool) – whether to return a full data structure

  • kwargs (dict) – passed to numpy.polyfit()


x = range(10)
y = sorted(2*np.random.rand(10) + 1)
m,b = sc.linregress(x, y) # Simple usage
out = sc.linregress(x, y, full=True) # Has out.m, out.b, out.x, out.y, out.corr, etc.
pl.scatter(x, y)
pl.plot(x, m*x+b), out.residuals)
pl.title(f'R² = {out.r2}')