In [8]:
import matplotlib.pyplot as plt
%pylab inline
x = [0,1,2,3]
y = [0,1,2,3]
A = np.vstack([x, np.ones(len(x))]).T
m, c = np.linalg.lstsq(A, y)[0]
print (m,c)
plt.plot(x, y, 'o', label='Original data', markersize=10)
plt.plot(x, m*x + c, 'r', label='Fitted line')
plt.legend()
plt.show()


Populating the interactive namespace from numpy and matplotlib
1.0 -5.93439168722e-17

In [ ]: