Classification:不能用线性回归
Logistic Regression:0hθ(x)1{\leq}h_{\theta}(x){\leq}1
(a classification algortihm)

hθ(x)=g(θTx)h_{\theta}(x)=g({\theta}^Tx)
g(z)=11+ez\frac{1}{1+e^{-z}}

hθ(x)=P(y=1x;θ)h_{\theta}(x)=P(y=1|x;{\theta})
x,θ\theta已知条件下y=1的概率

Suppose predict “y=1” if hθ(x)0.5h_{\theta}(x)\geq0.5
predict “y=0” if hθ(x)<0.5h_{\theta}(x)<0.5

Decision Boundary
hθ(x)=g(θ0+θ1x1+θ2x2)h_{\theta}(x)=g(\theta_0+\theta_1x_1+\theta_2x_2) θ\theta=[311]\begin{bmatrix} -3 \\ 1 \\ 1 \end{bmatrix}\quad
Predict “y=1” if -3+x1x_1+x2x_2\geq 0
机器学习第三课

Non-linear decision boundaries
机器学习第三课

Logistic regression cost function
cost(hθ(x),yh_{\theta}(x),y)={log(hθ(x))ify=1log(1hθ(x))ify=0=\left\{\begin{aligned}-log(h_{\theta}(x)) \qquad if \quad y=1\\-log(1-h_{\theta}(x)) \qquad if \quad y=0 \end{aligned} \right.

J(θ)=1mi=1mcost(hθ(x(i)),y(i))J(\theta)=\frac{1}{m}\sum_{i=1}^{m} cost(h_{\theta}(x^{(i)}),y^{(i)})
cost(hθ(x),y)h_{\theta}(x),y)=-ylog(hθ(x)h_{\theta}(x))-(1-y)log(1-hθ(x)h_{\theta}(x))

J(θ)=1m[i=1my(i)loghθ(x(i))+(1y(i))log(1hθ(x(i)))]J(\theta)=-\frac{1}{m}[\sum_{i=1}^{m}y^{(i)}logh_\theta(x^{(i)})+(1-y^{(i)})log(1-h_\theta(x^{(i)}))]

Want mine (J(θ)J(\theta))
Repeat
{
θj=θjαθjJ(θ)\theta_j=\theta_j-\alpha\frac{\partial}{\partial\theta_j}J(\theta) \quad
}simultaneously update all θj\theta_j

θjJ(θ)=1m(hθ(x(i))y(i))xj(i)\frac{\partial}{\partial\theta_j}J(\theta)=\frac{1}{m}(h_{\theta}(x^{(i)})-y^{(i)})x^{(i)}_j

Optimization algorithms(没有细看)

多元分类
机器学习第三课
Train a logistic regression classier hθ(i)(x)forh_\theta^{(i)}(x) for \quad \qquad each class i to predict the possibility that y=i
On a new input x,to make a prediction,pick the class i that maximizes Z maxi\mathop{max}\limits_{i} hθ(i)(x)h_\theta^{(i)}(x)

最后说一句,写博客真的好费时间(不是)
祝能有一个不错的五一

相关文章: