二分类逻辑回归
我们定义
p
p
p为类别为1(二分类0,1)的概率,
ln
?
p
1
?
p
\ln\frac{p}{1-p}
ln1?pp?表示类别为1的概率与类别为0的概率比的对数,当
ln
?
p
1
?
p
>
0
\ln\frac{p}{1-p}>0
ln1?pp?>0,则为类别1。
ln
?
p
1
?
p
=
w
0
+
∑
i
w
i
x
i
p
1
?
p
=
exp
?
w
0
+
∑
i
w
i
x
i
p
=
exp
?
w
0
+
∑
i
w
i
x
i
1
+
exp
?
w
0
+
∑
i
w
i
x
i
=
1
1
+
exp
?
?
(
w
0
+
∑
i
w
i
x
i
)
\ln\frac{p}{1-p}=w_0+\sum_iw_ix_i\\ \frac{p}{1-p}=\exp^{w_0+\sum_iw_ix_i}\\ p=\frac{\exp^{w_0+\sum_iw_ix_i}}{1+\exp^{w_0+\sum_iw_ix_i}}\\ =\frac{1}{1+\exp^-({w_0+\sum_iw_ix_i})}
ln1?pp?=w0?+i∑?wi?xi?1?pp?=expw0?+∑i?wi?xi?p=1+expw0?+∑i?wi?xi?expw0?+∑i?wi?xi??=1+exp?(w0?+∑i?wi?xi?)1? 可以看到最后的standard logistic function是sigmoid function。
多分类逻辑回归
以一个三分类(0,1,2)为例,定义三组二分类逻辑回归的权重
w
0
,
w
1
,
w
2
w^0, w^1, w^2
w0,w1,w2,则定义每个类别概率
p
(
y
=
0
)
=
exp
?
∑
i
w
i
0
x
i
0
∑
j
=
0
2
exp
?
w
i
j
x
i
j
p
(
y
=
1
)
=
exp
?
∑
i
w
i
1
x
i
1
∑
j
=
0
2
exp
?
w
i
j
x
i
j
p
(
y
=
2
)
=
exp
?
∑
i
w
i
2
x
i
2
∑
j
=
0
2
exp
?
w
i
j
x
i
j
p(y=0)=\frac{\exp^{\sum_iw_i^0x_i^0}}{\sum_{j=0}^2\exp^{w_i^jx_i^j}}\\ p(y=1)=\frac{\exp^{\sum_iw_i^1x_i^1}}{\sum_{j=0}^2\exp^{w_i^jx_i^j}}\\ p(y=2)=\frac{\exp^{\sum_iw_i^2x_i^2}}{\sum_{j=0}^2\exp^{w_i^jx_i^j}}
p(y=0)=∑j=02?expwij?xij?exp∑i?wi0?xi0??p(y=1)=∑j=02?expwij?xij?exp∑i?wi1?xi1??p(y=2)=∑j=02?expwij?xij?exp∑i?wi2?xi2?? 可以看到最后的standard logistic function是softmax function。
|