美文网首页
Andrew Ng ML(3)——Logistic回归

Andrew Ng ML(3)——Logistic回归

作者: tmax | 来源:发表于2018-12-19 17:01 被阅读0次

    Logistic回归(0<=h_\theta(x)<=1)——分类算法

    • h_\theta(x)=g(\theta^Tx),g(z)=\frac{1}{1+e^{-z}}(Logistic function/sigmoid function)
      h_\theta(x)=\frac{1}{1+e^{-\theta^Tx}}=P(y=1|x:\theta)

      由图可知,当\theta^Tx>=0h_\theta(x)>=0.5,y的预测结果为1;\theta^Tx<0h_\theta(x)<0.5,y的预测结果为0
    • Decision boundary(决策边界)

    h_\theta(x)=g(\theta^Tx)=g(\theta_0 x_0,\theta_1 x_1... \theta_n x_n),确定\theta的值,就可以确定一个决策边界(\theta^Tx=0即为决策边界,决策边界与数据集无关,但是\theta是通过数据集拟合得到的)
    e.g.

    线性决策边界 非线性决策边界
    • cost function(Logistic regressing)
    in linear regressing: J(\Theta)=\frac {1} {2m}\sum_1^m (h_{\Theta}(x^{(i)})-y^{(i)})^2=\frac{1}{m}\sum_1^m Cost(h_\theta(x),y)

    其中Cost(h_\theta(x),y)=\frac{1}{2}(h_{\Theta}(x^{(i)})-y^{(i)})^2,h_\theta(x)=\theta^Tx

    in logistic regressing

    h_\theta(x)=\frac{1}{1+e^{-\theta^Tx}},若过不改变Cost(h_\theta(x),y),J(\theta)图像含有大量局部最小值\Downarrow

    适用于logistic regressingCost(h_\theta(x),y)=\begin{cases}-log(h_\theta(x)) --if:y=1\\-log(1-h_\theta(x))--if:y =0\end{cases}

    当y=1,并且假设函数h趋于0,Cost会趋于无穷(即:结果应该为1,但是预测值却为0,这时候Cost很大用来惩罚算法) 与上图类似
    • cost fcuntion 的简化以及\theta最优解的求法(梯度下降)

    Cost(h_\theta(x),y)=\begin{cases}-log(h_\theta(x)) --if:y=1\\-log(1-h_\theta(x))--if:y =0\end{cases}
    =-ylog(h_\theta(x))-(1-y)log(1-h_\theta(x))
    因此
    J(\theta)=\frac{1}{m}\sum_1^mCost(h_\theta(x^{(i)}),y^{(i)})
    =\frac{1}{m}\sum_1^m[-ylog(h_\theta(x^{(i)}))-(1-y^{(i)})log(1-h_\theta(x^{(i)}))]
    =-\frac{1}{m}\sum_1^m[ylog(h_\theta(x^{(i)}))+(1-y^{(i)})log(1-h_\theta(x^{(i)}))]

    Q:如何求解J(\theta)\theta的偏导?
    【via:https://www.cnblogs.com/HolyShine/p/6403116.html
    故,\frac{\partial J(\theta)}{\partial \theta_j}=\frac{1}{m}\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)}).x_j^{(i)}
    logistic regressing gradient descent
    线性回归对应的式子是相同的!!!因此,也可以用线性回归中的方法来监测是否收敛,也可以使用特征收缩来使得梯度下降的更快
    • Advanced optimization (高级优化)——使得最小化logistic regressing中的cost functionJ(\theta)更快(相对于Gradient descent)
    高级优化算法以及优缺点(主要是速度更快,并且不需要选择α)
    • Multi-class classification

    方法:将一个N分类问题分成N个二元分类问题

    e.g.

    将样本输入N个分类器,输出概率最高的分类器对应的类别,即为预测的结果

    相关文章

      网友评论

          本文标题:Andrew Ng ML(3)——Logistic回归

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