逻辑回归模型的代价函数对参数的偏导数--推导过程

本文详细解释了如何通过数学变换简化逻辑回归的成本函数,并给出了偏导数的具体计算过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. https://math.stackexchange.com/questions/477207/derivative-of-cost-function-for-logistic-regression/477261#477261
  2. https://www.cnblogs.com/Belter/p/6653773.html

The reason is the following. We use the notation

θxi:=θ0+θ1xi1++θpxip.θxi:=θ0+θ1x1i+⋯+θpxpi.

Then

loghθ(xi)=log11+eθxi=log(1+eθxi),log⁡hθ(xi)=log⁡11+e−θxi=−log⁡(1+e−θxi),
log(1hθ(xi))=log(111+eθxi)=log(eθxi)log(1+eθxi)=θxilog(1+eθxi),log⁡(1−hθ(xi))=log⁡(1−11+e−θxi)=log⁡(e−θxi)−log⁡(1+e−θxi)=−θxi−log⁡(1+e−θxi),
[ this used: 1=(1+eθxi)(1+eθxi),1=(1+e−θxi)(1+e−θxi), the 1's in numerator cancel, then we used: log(x/y)=log(x)log(y)log⁡(x/y)=log⁡(x)−log⁡(y) ]

Since our original cost function is the form of:

J(θ)=1mi=1myilog(hθ(xi))+(1yi)log(1hθ(xi))J(θ)=−1m∑i=1myilog⁡(hθ(xi))+(1−yi)log⁡(1−hθ(xi))

Plugging in the two simplified expressions above, we obtain

J(θ)=1mi=1m[yi(log(1+eθxi))+(1yi)(θxilog(1+eθxi))]J(θ)=−1m∑i=1m[−yi(log⁡(1+e−θxi))+(1−yi)(−θxi−log⁡(1+e−θxi))]
, which can be simplified to:
J(θ)=1mi=1m[yiθxiθxilog(1+eθxi)]=1mi=1m[yiθxilog(1+eθxi)],  ()J(θ)=−1m∑i=1m[yiθxi−θxi−log⁡(1+e−θxi)]=−1m∑i=1m[yiθxi−log⁡(1+eθxi)],  (∗)

where the second equality follows from

θxilog(1+eθxi)=[logeθxi+log(1+eθxi)]=log(1+eθxi).−θxi−log⁡(1+e−θxi)=−[log⁡eθxi+log⁡(1+e−θxi)]=−log⁡(1+eθxi).
[ we used log(x)+log(y)=log(xy)log⁡(x)+log⁡(y)=log(xy) ]

All you need now is to compute the partial derivatives of ()(∗) w.r.t. θjθj. As

θjyiθxi=yixij,∂∂θjyiθxi=yixji,
θjlog(1+eθxi)=xijeθxi1+eθxi=xijhθ(xi),∂∂θjlog⁡(1+eθxi)=xjieθxi1+eθxi=xjihθ(xi),

the thesis follows.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值