15

Logistic Regression

 4 years ago
source link: https://www.wmathor.com/index.php/archives/1365/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

本文简单介绍一下Logistic Regression的定义和原理。对于(Linear Regression)线性回归模型,输入$x$,网络参数为$w$和$b$,输出值为$y$,是个连续值。但是分类问题最终的输出值应该为离散的,那么如何转化为分类问题呢?

可以考虑增加一个$\sigma$函数,变为$y=\sigma(wx+b)$,这个$\sigma$也叫sigmoid函数或logistic函数

这样输出的值就能压缩到$[0,1]$,我们可以将这个值等效为probability

对于Regression问题,其目标是使pred(预测值)近似于输出的$y$值,即$minimize\ dist(pred,y)$

对于Classification问题,其目标是$maximize\ accuracy$,或者说$minimize\ dist(p_\theta(y|x), p_r(y|x))$

两者最主要的区别是traning的目标不同

这里可能会有疑问,why not maximize accuracy?

因为一般acc的计算公式为:$\frac{预测对的数量}{总的数量}$

$$ acc = \frac{\sum I(pred = y_i)}{len(Y)} $$

对于一个二分类问题,我们假设阈值为0.5,即$pred>0.5$,我们认为是第一类,$pred<0.5$,我们认为是第二类。一开始肯定会有分类不正确的,假设真实类别为1,预测值为0.4,则网络将其归为0这一类,在网络更新后,预测值变大为0.45,虽然更加靠近1,更加接近真实值,但是由于没有发生本质的变化,即没有大于0.5

再比方说,假如一开始一个预测值为0.499,真实类别为1,网络更新后,预测值变为0.501,预测正确了,但是计算梯度时,可能会导致梯度非常非常大,甚至不连续

上面两个问题总结起来就是:

  • issues 1. gradient = 0 if accuracy unchanged but weights changed
  • issues 2. gradient not continuous since the number of correct is not continuous

最后一个问题,why call logistic regression?

logistic好理解,因为使用了$\sigma$函数,但是为什么叫regression,而不是classification呢?这个问题的解答网上有很多争议,其中一个解释是说,因为一开始做classification的时候,用的就是MSE,所以叫做regression(解决regression问题常用的loss就是MSE),但是现在解决classification问题用的是Cross Entropy,只不过叫法以及被大家习惯了,所以没改

  • MSE => regression
  • Cross Entropy => classification

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK