美文网首页
【机器学习】-Week1 3. 成本函数

【机器学习】-Week1 3. 成本函数

作者: Kitty_风花 | 来源:发表于2019-11-30 10:45 被阅读0次

    Cost Function

    We can measure the accuracy of our hypothesis function by using a cost function. This takes an average difference (actually a fancier version of an average) of all the results of the hypothesis with inputs from x's and the actual output y's.

    To break it apart, it is  1/2 x¯ where x¯ is the mean of the squares of 

     or the difference between the predicted value and the actual value.

    This function is otherwise called the "Squared error function", or "Mean squared error". The mean is halved  1/2 as a convenience for the computation of the gradient descent, as the derivative term of the square function will cancel out the 1/2 ​term. The following image summarizes what the cost function does:

    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 by hθ​(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 of J(θ0​,θ1​) will be 0. The following example shows the ideal situation where we have a cost function of 0.

    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.

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

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

    成本函数 - 直觉II

    等高线图是包含许多等高线的图形。双变量函数的等高线在同一行的所有点处具有恒定值。这种图表的一个例子是下面的图表。

    采用任何颜色并沿着'圆',人们可以期望得到相同的成本函数值。例如,上面绿线上的三个绿点具有相同的值J (θ0​, θ1​)并且作为结果,它们沿同一条线中。带圆圈的x显示左侧图形的成本函数的值theta_0​ = 800和 theta_1= -0.15。取另一个h(x)并绘制其等高线图,可得到以下图表:

    什么时候  theta_0 = 360和 theta_1 = 0,值为 Ĵ(θ0​,θ1​)在等高线图中靠近中心,从而减少了成本函数误差。现在给出我们的假设函数略微正斜率可以更好地拟合数据。

    上图最大限度地降低了成本函数,从而最终使结果最小化  theta_1和 \ theta_0 ,​往往分别约为0.12和250。在我们的图表右侧绘制这些值似乎将我们的观点置于最内圈“圆圈”的中心。

    来源:coursera 斯坦福 吴恩达 机器学习

    相关文章

      网友评论

          本文标题:【机器学习】-Week1 3. 成本函数

          本文链接:https://www.haomeiwen.com/subject/gtmrjctx.html