Logistic Regression
regression一般指连续的。
interpret network as
f
:
x
→
p
(
y
∣
x
;
θ
)
f:x\to p(y|x;\theta)
f:x→p(y∣x;θ)其中,
y
=
1
y=1
y=1,
θ
=
[
w
,
b
]
\theta=[w,b]
θ=[w,b]
使用sigmoid函数
output
∈
[
0
,
1
]
\in[0,1]
∈[0,1]
which is exactly what logistic function comes in!
For regression:
Goal:
p
r
e
d
=
y
pred=y
pred=y
Approach:minimize
d
i
s
t
(
p
r
e
d
,
y
)
dist(pred,y)
dist(pred,y)最小距离,使用一范数或者二范数的平方。
For classification:
Goal:maximize benchmark,e.g.accuracy
p
θ
(
y
∣
x
)
p_{\theta}(y|x)
pθ(y∣x)为
θ
\theta
θ参数上的分布,
p
r
(
y
∣
x
)
)
p_{r}(y|x))
pr(y∣x))为真实的分布,希望两个数越近越好。
Approach1:minimize
d
i
s
t
(
C
,
p
r
(
y
∣
x
)
)
dist(C,p_{r}(y|x))
dist(C,pr(y∣x))
Approach2:minimize
d
i
v
e
r
g
e
n
c
e
(
p
θ
(
y
∣
x
)
,
p
r
(
y
∣
x
)
)
divergence(p_{\theta}(y|x),p_{r}(y|x))
divergence(pθ(y∣x),pr(y∣x))
Q1.why not maximize accuracy?
为什么classification中train的目标和最终test的目标不一样?也就是为什么不能直接maximize accuracy?
a
c
c
.
=
∑
I
(
p
r
e
d
i
=
=
y
i
)
l
e
n
(
Y
)
acc.=\frac{\sum I(pred_{i}==y_{i})}{len(Y)}
acc.=len(Y)∑I(predi==yi)
直接的maximize accuracy会有两个问题:
issues 1.gradient=0 if accuracy unchanged but weights changed
结果是非0即1的,概率大于0.5为1,小于0.5为0,若一个本该划为1的情况,w在计算中为0.4,w可能会发生由0.4到0.45的改变而并没有改变最终结果,结果仍为0,分类错误。
issues 2.gradient not continuous since the number of correct is not continuous
也有可能会出现从0.499到0.501的改变,w只改变了0.002,但结果发生了很大的变化,变得不连续。
Q2.why call logistic regression?
1.logistic,use sigmoid
2.controversial!
MSE=>regression
Cross Entropy=>classifiication
Multi-class classification
f
:
x
→
p
(
y
∣
x
)
f:x\to p(y|x)
f:x→p(y∣x)
[
p
(
y
=
0
∣
x
)
,
p
(
y
=
1
∣
x
)
,
.
.
.
,
p
(
y
=
9
∣
x
)
]
[p(y=0|x),p(y=1|x),...,p(y=9|x)]
[p(y=0∣x),p(y=1∣x),...,p(y=9∣x)]
p
(
y
∣
x
)
∈
[
0
,
1
]
p(y|x)\in[0,1]
p(y∣x)∈[0,1]
∑
i
=
0
9
p
(
y
=
i
∣
x
)
=
1
\sum^{9}_{i=0}p(y=i|x)=1
∑i=09p(y=i∣x)=1使用softmax