Reputation: 113
I have a very simple data of
x=[3,8,12,22,36,25,46,52]
y=[3,9,11,25,36,27,48,55]
pylab.plot(x,y)
how can I find the slope and the intercept of this graph
Upvotes: 0
Views: 431
Reputation: 8144
use scipy.stats.linregress
ref scipy.stats
import numpy as np
from scipy import stats
X = np.array([3,8,12,22,36,25,46,52])
Y = np.array([3,9,11,25,36,27,48,55])
slope, intercept , r_value, p_value, std_err = stats.linregress(X,Y)
print(slope,intercept)
using numpy
import numpy as np
X = np.array([3,8,12,22,36,25,46,52])
Y = np.array([3,9,11,25,36,27,48,55])
slope, intercept = np.polyfit(X, Y, 1)
print(slope,intercept)
o/p:
1.046875 0.0546875
Upvotes: 1