逻辑回归Loss function推导

2018-09-27  本文已影响0人  DeepMine

逻辑回归

\hat{y} = \sigma(z)

\sigma(z) = \frac{1}{{1+e^{-z}}}

z = w^Tx+b

\hat{y} = p(y=1|x)

神经网络表示

预测概率

if y = 1:    p(y|x)=\hat{y}

if y = 0:    p(y|x)=1-\hat{y}

=>
p(y|x) = \hat{y}^{y}.(1-\hat{y})^{(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})

L(y, \hat{y}) = - log(p(y|x))


最大似然

P=\prod_{i=1}^N p(y^{(i)}|x^{(i)})

LP = \sum_{k=1}^N log(p(y^{(i)}|x^{(i)}))

LP = -\sum_{k=1}^N L(y^{(i)},\hat{y}^{(i)})


求导

\frac{dL} {d\hat{y}} = -\frac{y} {\hat{y}} +\frac{(1-y)}{(1-\hat{y})}

\frac{d\hat{y}} {dz} = \hat{y} . (1-\hat{y})

\frac{dL} {dz} = \frac{dL} {d\hat{y}} . \frac{d\hat{y}} {dz} =-y(1-\hat{y}) + (1-y)\hat{y} = -y + \hat{y}

\frac{d\hat{z}} {dw} = x

上一篇 下一篇

猜你喜欢

热点阅读