机器学习-Week 3

分类算法-逻辑回归

  • Logistic (sigmoid) function:

        P(y=1|x;\theta)=h_\theta(x)=\frac{1}{1+e^{-\theta^Tx}} \in[0,1]

        P(y=0|x;\theta)+P(y=1|x;\theta)=1

  • Cost function

        J(\theta)=\frac{1}{m}\sum_{i=1}^m\textrm{Cost}(h_\theta(x)^{(i)},y^{(i)})

        \textrm{Cost}(h_\theta(x),y)=\left\{\begin{matrix} -\log (h_\theta(x)) & y=1\\ -\log (1-h_\theta(x)) & y=0 \end{matrix}\right.
  \Rightarrow J(\theta)=-\frac{1}{m}\sum_{i=1}^m[y^{(i)}\log(h_\theta(x^{(i)}))+ (1-y^{(i)})\log(1-h_\theta(x^{(i)}))]

  • Iteration: the form is the same as linear regression

        \theta_j=\theta_j-\frac{\alpha}{m}\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})x_j^{(i)}

  • Decision boundary:

    That's a property of the hypothesis and of the parameters of the hypothesis and not a property of the data set.

  • Predict y=1 when \theta^Tx\ge 0(h_\theta(x)\ge0.5); predict y=0 when \theta^Tx\le0(h_\theta(x)<0.5).
  • Multiclass Classification: one-vs-all method

注意事项:

  1. {0(negative class),1(positive class)} 
  2. 不适用线性回归

 

欠拟合与过拟合

Two main options to address the issue of overfitting:

  1. Reduce the number of features:
  • Manually select which features to keep.
  • Use a model selection algorithm (studied later in the course).

     2. Regularization

  • Keep all the features, but reduce the magnitude of parameters \theta_j
  • Regularization works well when we have a lot of slightly useful features.
  •  

       \min_\theta\frac{1}{2m}\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})^2+\lambda\sum_{j=1}^n\theta_j^2

      where \lambda (palarization parameter) should be adequately large.

  • Gradient descent

       \theta_j=\theta_j(1-\alpha\frac{\lambda}{m})-\frac{\alpha}{m}\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})x_j^{(i)}

  • Cost function

       J(\theta)=-\frac{1}{m}\sum_{i=1}^m[y^{(i)}\log(h_\theta(x^{(i)}))+ (1-y^{(i)})\log(1-h_\theta(x^{(i)}))]+\frac{\lambda}{2m}\sum_{j=1}^n\theta_j^2

       notice that \theta_0 is excluded!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值