For the complete documentation index, see llms.txt. This page is also available as Markdown.

2.7 (选修)logistic 损失函数的解释(Explanation of logistic regression cost function )

y^\hat y可以看成是预测输出为正类(+1)的概率:

y^=P(y=1∣x)\hat y=P(y=1|x)

当y=1时:

p(y∣x)=y^p(y|x)=\hat y

当y=0时:

p(y∣x)=1−y^p(y|x)=1-\hat y

整合到一个式子:

P(y∣x)=y^y(1−y^)(1−y)P(y|x)=\hat y^y(1-\hat y)^{(1-y)}

进行log处理:

log P(y∣x)=log y^y(1−y^)(1−y)=y log y^+(1−y)log(1−y^)log\ P(y|x)=log\ \hat y^y(1-\hat y)^{(1-y)}=y\ log\ \hat y+(1-y)log(1-\hat y)

上述概率P(y|x)越大越好,加上负号,则转化成了单个样本的Loss function,越小越好:

L=−(y log y^+(1−y)log(1−y^))L=-(y\ log\ \hat y+(1-y)log(1-\hat y))

对于所有m个训练样本,假设样本之间是独立同分布的,总的概率越大越好:

max ∏i=1m P(y(i)∣x(i))max\ \prod_{i=1}^m\ P(y^{(i)}|x^{(i)})

引入log函数,加上负号,将上式转化为Cost function:

J(w,b)=−1m∑i=1mL(y^(i),y(i))=−1m∑i=1m[y(i) log y^(i)+(1−y(i))log(1−y^(i))]J(w,b)=-\frac1m\sum_{i=1}^mL(\hat y^{(i)},y^{(i)})=-\frac 1m\sum_{i=1}^m[y^{(i)}\ log\ \hat y^{(i)}+(1-y^{(i)})log(1-\hat y^{(i)})]

Last updated

Was this helpful?