成本函数-Intuition l

Cost Function - Intuition I

If we try to think of it in visual terms, our training data set is scattered on the x-y plane. We are trying to make a straight line (defined byhθ(x)) which passes through these scattered data points.

Our objective is to get the best possible line. The best possible line will be such so that the average squared vertical distances of the scattered points from the line will be the least. Ideally, the line should pass through all the points of our training data set. In such a case, the value ofJ(θ0,θ1)will be 0. The following example shows the ideal situation where we have a cost function of 0.


成本函数-Intuition l_第1张图片

Whenθ1=1, we get a slope of 1 which goes through every single data point in our model. Conversely, whenθ1=0.5, we see the vertical distance from our fit to the data points increase.


成本函数-Intuition l_第2张图片

This increases our cost function to 0.58. Plotting several other points yields to the following graph:


成本函数-Intuition l_第3张图片

Thus as a goal, we should try to minimize the cost function. In this case,θ1=1is our global minimum.

你可能感兴趣的:(成本函数-Intuition l)