您的位置:首页 > 其它

Coursera-Machine Learning 之 Logistic Regression (逻辑回归)-0x01

2015-02-11 17:53 453 查看

Hypothesis Representation (假设函数表达式)

Logistic Regression Model

Want 0≤hθ(x)≤10\leq h_{\theta}(x) \leq 1

hθ(x)=g(θTx)g(z)=11+e−z⎫⎭⎬⎪⎪→hθ(x)=11+e−θTx
\left.
\begin{array}{l}
h_{\theta}(x) = g(\theta^{T}x) \\
g(z) = \dfrac{1}{1+e^{-z}}
\end{array}
\right\}
\to
h_{\theta}(x) = \dfrac{1}{1+e^{-\theta^{T}x}}

Sigmoid function

Logistic function

This two concept are basically synonyms and mean the same things.

这两个函数概念基本是同义词,表示了g(z)g(z)

Sigmoid function wiki pedia

Sigmoid 函数 百度百科

Interpretation of Hypothesis Output

对于一个已存在的数据集,我们需要为假设函数寻找一个θ\theta来拟合这个数据集;

hθ(x)=P(y=1|x;θ)h_{\theta}(x) = P(y=1|x;\theta)

在给定的特征值xx,参数值θ\theta下,y=1y=1的概率。

P(y=0|x;θ)=1−P(y=1|x;θ)P(y=0|x;\theta) = 1 - P(y=1|x;\theta)

Decision Regression(决策边界)

Logistic Regression

假设预测:

如果 hθ(x)≥0.5h_{\theta}(x) \geq 0.5,则 y=1y=1;

如果 hθ(x)<0.5h_{\theta}(x) < 0.5,则 y=0y=0;

在g(z)g(z)函数中

如果 z≥0z \geq 0,则 0.5≤g(z)<10.5\leq g(z)<1;

如果 z<0z<0,则 0<g(z)<0.50< g(z)<0.5;

所以

θTx≥0⇒hθ(x)≥0.5⇒y=1\color{blue}{\theta^{T}x \geq 0} \Rightarrow h_{\theta}(x)\geq0.5 \Rightarrow \color{blue}{y = 1}

θTx<0⇒hθ(x)<0.5⇒y=0\color{navy}{\theta^{T}x < 0} \Rightarrow h_{\theta}(x) < 0.5 \Rightarrow \color{navy}{y = 0}

Decision Boundary

hθ(x)=g(θ0+θ1x1+θ2x2)h_{\theta}(x) = g(\theta_{0}+\theta_{1} x_{1}+\theta_{2} x_{2})

假设: θ0=−3,θ1=1,θ2=1\theta_{0} = -3, \theta_{1} = 1, \theta_{2} = 1

θ=⎡⎣⎢−311⎤⎦⎥
\theta = \begin{bmatrix}
-3\\
1\\
1
\end{bmatrix}

Predict

"y=1""y = 1" if −3+x1+x2≥0 -3 + x_{1} + x_{2} \geq 0

"y=0""y = 0" if −3+x1+x2<0 -3 + x_{1} + x_{2} < 0

这里可以看出 x1+x2=3x_{1} + x_{2} = 3 这条线 是上述两个等式取不同值得分界线,这条分界线就被称为决策边界;

在这里,决策边界是假设函数的一个属性,由参数决定,与数据集无关。

Non-linear decision Boundaries

hθ(x)=g(θ0+θ1x1+θ2x2+θ3x21+θ4x22)h_{\theta}(x) = g(\theta_{0}+\theta_{1} x_{1}+\theta_{2} x_{2}+\theta_{3} x_{1}^{2}+\theta_{4} x_{2}^{2})

support:

θ=⎡⎣⎢⎢⎢⎢⎢⎢−10011⎤⎦⎥⎥⎥⎥⎥⎥
\theta = \begin{bmatrix}
-1\\
0\\
0\\
1\\
1
\end{bmatrix}

Predict

"y=1""y = 1" if −1+x21+x22≥0 -1 + x_{1}^{2} + x_{2}^{2} \geq 0

"y=0""y = 0" if −1+x21+x22<0 -1 + x_{1}^{2} + x_{2}^{2} < 0

此时,决策边界为 x21+x22=1 x_{1}^{2} + x_{2}^{2} = 1

参数 θ\theta 并不是由训练集所决定的,但是可以由训练集拟合出 θ\theta

高阶复杂的假设函数:

hθ(x)=g(θ0+θ1x1+θ2x2+θ3x21+θ4x21x2+θ5x21x22+...)h_{\theta}(x) = g(\theta_{0}+\theta_{1} x_{1}+\theta_{2} x_{2}+\theta_{3} x_{1}^{2}+\theta_{4} x_{1}^{2} x_{2} + \theta_{5} x_{1}^{2} x_{2}^{2}+ ...)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: