Simple Linear Regression

By | November 29, 2016
Share the joy
  •  
  •  
  •  
  •  
  •  
  •  

I’m learning machine learning these days. Here let me write down the note for this.
Suppose we have m training points training_set in x-y coordination, and we want to find the best line fit for these points .
sample_points

Since it is the simplest line, we can define the line function, and call it hypothesis:
hypothesis.

A way to measure how well a line fit these points is least square mean. And we call it loss function:

loss_function

Now, the problem turns to find the pair which the loss function has the minimum value. As said by Andrew NG, the fortunate thing is that the loss function of linear regression are all bowl shape, which mean it always has a extreme value.
bowl_shape

One way to minimize the loss function is to use gradient descent algorithm. The basic idea is to let the point on the surface go through gradient direction, in this way, it will finally reach the extreme value. Partial derivative functions for loss function:
derivative

After we got the partial derivative function, we do below until loss function is less than boudary
iteration

When the loss function is getting close the extreme value, we can see the pair is moving to the extreme value from the gradient direction.

change_of_loss