逻辑回归——分类算法
逻辑回归模型
如何定义hθ(x),使得0≤hθ(x)≤1
令
\[{h_\theta }(x) = g\left( {{\theta ^T}x} \right)\]
其中g(x)称为Sigmoid function或logistic function
\[g\left( z \right) = \frac{1}{{1 + {e^{ - z}}}}\]
将两个函数合并
\[{h_\theta }(x) = \frac{1}{{1 + {e^{ - {\theta ^T}x}}}}\]
Sigmoid function 的示意图如下
Interpretation of Hypothesis Output
关于Hypothesis输出的解释
hθ(x)=estimated probability that y=1 on input x
hθ(x)是评估输入为x,输出y=1的可能性
Example: if
\[x = \left[ {\begin{array}{*{20}{c}}
{{x_0}}\\
{{x_1}}
\end{array}} \right] = \left[ {\begin{array}{*{20}{c}}
1\\
{tumorSize}
\end{array}} \right]\]
hθ(x)=0.7 Tell patient that 70% chance of tumor being malignant
hθ(x)=0.7 表示患者的肿瘤有70%的可能是恶性的
可以用 \[{h_\theta }(x) = P\left( {y = 1|x;\theta } \right)\]
表示:在给定x和参数θ情况下y=1的可能性是hθ(x)
Decision Boundary
观察 \[{h_\theta }(x) = g\left( {{\theta ^T}x} \right)\]
和Sigmoid函数会发现,hθ(x)≥0.5等价于 \[{\theta ^T}x \ge 0\]
假设 \[{h_\theta }(x) = g\left( {{\theta _0} + {\theta _1}{x_1} + {\theta _2}{x_2}} \right)\]
且假设 θ=[-3 1 1]
这时,如果 \[ - 3 + {x_1} + {x_2} \ge 0\] 则预测结果是 y=1
变换公式后 \[{x_1} + {x_2} \ge 3\]
画出 \[{x_1} + {x_2} = 3\] 后如图
在线的右上方是y=1的点,在线的左下角是y=0的点
这条线就叫做Decision Boundary
它对应的是 \[{h_\theta }(x) = 0.5\]
需要搞清楚的一点是:一旦θ确定,Decision Boundary 也就确定了;数据不能决定 Decision Boundary,数据是用来寻找参数θ的。