In [7]:
import numpy as np
%matplotlib inline
In [ ]:
x = np.array([0, 1, 2, 3])
In [2]:
y = np.array([-1, 0.2, 0.9, 2.1])
In [12]:
A = np.vstack([x, np.ones(len(x)), np.ones(len(x))]).T
In [13]:
A.shape
Out[13]:
In [14]:
A
Out[14]:
In [16]:
mcc = np.linalg.lstsq(A, y)[0]
In [17]:
mcc
Out[17]:
In [8]:
import matplotlib.pyplot as plt
In [9]:
plt.plot(x, y, 'o', label='Original data', markersize=10)
plt.plot(x, m*x + c, 'r', label='Fitted line')
plt.legend()
plt.show()
In [ ]: