Created
March 17, 2014 09:57
-
-
Save oldcai/9596711 to your computer and use it in GitHub Desktop.
linear regression using python scipy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import pylab | |
from scipy import stats | |
xi = numpy.arange(0, 9) | |
A = numpy.array([xi, numpy.ones(9)]) | |
# linearly generated sequence | |
y = [19, 20, 20.5, 21.5, 22, 23, 23, 25.5, 24] | |
slope, intercept, r_value, p_value, std_err = stats.linregress(xi, y) | |
print 'slope', slope | |
print 'intercept', intercept | |
print 'r value', r_value | |
print 'p_value', p_value | |
print 'standard deviation', std_err | |
line = slope * xi + intercept | |
pylab.plot(xi, line, 'r-', xi, y, 'o') | |
pylab.savefig('fig.png') | |
pylab.show() | |
pylab.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numpy | |
matplotlib | |
scipy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment