逻辑回归的模型:
h
θ
(
x
)
=
1
1
+
e
−
θ
T
x
h_\theta(x)=\frac{1}{1+e^{-\theta^Tx}}
hθ(x)=1+e−θTx1
损失函数(目标方程):
J
(
θ
)
=
1
m
∑
i
=
1
m
C
o
s
t
(
h
θ
(
x
(
i
)
)
,
y
(
i
)
)
J(\theta)=\frac{1}{m}\sum_{i=1}^{m}Cost(h_\theta(x^{(i)}),y^{(i)})
J(θ)=m1i=1∑mCost(hθ(x(i)),y(i))
C
o
s
t
(
h
θ
(
x
)
,
y
)
=
{
−
l
o
g
(
h
θ
(
x
)
)
i
f
y
=
1
−
l
o
g
(
1
−
h
θ
(
x
)
)
i
f
y
=
0
Cost(h_\theta(x),y)=\left\{\begin{matrix} -log(h_\theta(x)) & i f\quad y=1\\ -log(1-h_\theta(x)) & if \quad y=0 \end{matrix}\right.
Cost(hθ(x),y)={−log(hθ(x))−log(1−hθ(x))ify=1ify=00
可以简写为:
C
o
s
t
(
h
θ
(
x
)
,
y
)
=
−
y
l
o
g
(
h
θ
(
x
)
)
−
(
1
−
y
)
l
o
g
(
1
−
h
θ
(
x
)
)
Cost(h_\theta(x),y)=-ylog(h_\theta(x))-(1-y)log(1-h_\theta(x))
Cost(hθ(x),y)=−ylog(hθ(x))−(1−y)log(1−hθ(x))
迭代求最优参数
O
b
j
:
m
i
n
θ
J
(
θ
)
Obj:min_\theta J(\theta)
Obj:minθJ(θ):
θ
j
=
θ
j
−
α
∂
J
(
θ
)
∂
θ
j
=
θ
j
−
α
∑
i
=
1
m
(
h
θ
(
x
(
i
)
)
−
y
(
i
)
)
x
j
(
i
)
\theta_j=\theta_j-\alpha \frac{\partial J(\theta)}{\partial \theta _j}=\theta_j-\alpha \sum_{i=1}^{m}(h_\theta (x^{(i)})-y^{(i)})x_j^{(i)}
θj=θj−α∂θj∂J(θ)=θj−αi=1∑m(hθ(x(i))−y(i))xj(i)