linregress#
- 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.- Parameters:
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()
Examples:
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. plt.scatter(x, y) plt.plot(x, m*x+b) plt.bar(x, out.residuals) plt.title(f'R² = {out.r2}')