Computer Science, asked by sana4218, 1 year ago

The function ``lstsq`` returns the least-squares solution to an equation

Answers

Answered by techtro
1

From the question we can find the line equation as y = Ap, where A = [[x 1]] and p = [[m], [c]].

Therefore now you can use lstsq to solve for p:

A = np.vstack([x, np.ones(len(x))]).T A

array([[ 0.,  1.],

      [ 1.,  1.],

      [ 2.,  1.],

      [ 3.,  1.]])

m, c = np.linalg.lstsq(A, y, rcond=None)[0]

print(m, c)

1.0 -0.95.

So for the function ``lstsq`` returns the least-squares solution from the above equation.

Similar questions