代价函数的意义

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xd15010130025/article/details/88723032

我们来复习上一节的知识:
假设函数: h θ ( x ) = θ 0 + θ 1 x h_\theta(x)=\theta_0+\theta_1x
参数: θ 0 , θ 1 \theta_0,\theta_1
代价函数: J ( θ 0 , θ 1 ) = 1 2 m i = 1 i = m ( h ( x i ) y i ) 2 J(\theta_0,\theta_1)=\frac{1}{2m}\sum_{i=1}^{i=m}(h(x^i)-y^i)^2
目标:求得当 J ( θ 0 , θ 1 ) J(\theta_0,\theta_1) 最小时的 θ 0 , θ 1 \theta_0,\theta_1
在这里插入图片描述
做一个简化,令:
h θ ( x ) = θ 1 x h_\theta(x)=\theta_1x
在这里插入图片描述
我们可以画出假设函数和代价函数的值。可知,当 θ 1 = 1 \theta_1=1 时,有
h θ ( x ) = x h_\theta(x)=x
J ( θ 1 = 1 ) = 1 2 3 [ ( 1 1 ) 2 + ( 2 2 ) 2 + ( 3 3 ) 2 ] = 0 J(\theta_1=1)=\frac{1}{2*3}*[(1-1)^2+(2-2)^2+(3-3)^2]=0
在这里插入图片描述
θ 1 = 0.5 \theta_1=0.5 时,有
h θ ( x ) = 0.5 x h_\theta(x)=0.5x
J ( θ 1 = 0.5 ) = 1 2 3 [ ( 0.5 1 ) 2 + ( 1 2 ) 2 + ( 1.5 3 ) 2 ] = 0.58 J(\theta_1=0.5)=\frac{1}{2*3}*[(0.5-1)^2+(1-2)^2+(1.5-3)^2]=0.58
在这里插入图片描述
θ 1 = 0 \theta_1=0 时,有
h θ ( x ) = 0 h_\theta(x)=0
J ( θ 1 = 0 ) = 1 2 3 [ ( 0 1 ) 2 + ( 0 2 ) 2 + ( 0 3 ) 2 ] = 2.3 J(\theta_1=0)=\frac{1}{2*3}*[(0-1)^2+(0-2)^2+(0-3)^2]=2.3
在这里插入图片描述
据此我们可以作出 h θ ( x ) h_\theta(x) J ( θ 1 ) J(\theta_1) 的图
在这里插入图片描述
下次我们将继续讨论加上 θ 0 \theta_0 的情形
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xd15010130025/article/details/88723032
今日推荐