Q:

How to determine the regression line for the data points(Theory)?

Determine the regression line for the below data points:
(x1, y1) = (1, 4), (x2, y2) = (2, 3), (x3, y3) = (3, 9)

i.e. the function h(x) = w + hx that minimizes the squared error loss on this data.

A:

This question just boils down to math.
First, we write our error function

The derivative of the error function tells us how the error changes as we change variables.  Because there are two variables (m and b), it is a partial derivative.  When the derivative is equal to zero we know we have reached a minimum (and because we're taking the derivative of a quadratic we know there is a single global minimum).

Writing out each term in the sum gives us

Two variables, two equations means we can solve for both!

In your case we have h=m and w=b
As a double check, Desmos is a great tool https://www.desmos.com/calculator

