In [1]:
from sympy import *
init_printing()
In [2]:
X = Matrix([[1, 10],
            [1, 8],
            [1, 13],
            [1, 9],
            [1, 11],
            [1, 14],
            [1, 6],
            [1, 4],
            [1, 12],
            [1, 7],
            [1, 5]])

y = Matrix([[8.04],
            [6.95],
            [7.58],
            [8.81],
            [8.33],
            [9.96],
            [7.24],
            [4.26],
            [10.84],
            [4.82],
            [5.68]])
In [3]:
X
Out[3]:
$$\left[\begin{matrix}1 & 10\\1 & 8\\1 & 13\\1 & 9\\1 & 11\\1 & 14\\1 & 6\\1 & 4\\1 & 12\\1 & 7\\1 & 5\end{matrix}\right]$$
In [4]:
y
Out[4]:
$$\left[\begin{matrix}8.04\\6.95\\7.58\\8.81\\8.33\\9.96\\7.24\\4.26\\10.84\\4.82\\5.68\end{matrix}\right]$$
In [5]:
v = Inverse(X.T * X) * X.T * y
In [6]:
v
Out[6]:
$$\left[\begin{matrix}3.00009090909091\\0.500090909090909\end{matrix}\right]$$
In [7]:
#v = (b, m), or (intercept, slope)
#So, the best fit line is given by (approximately) y = 0.5x + 3