【LDA】为什么 w^T Σ w 代表类内散度?
时间:2022-10-30 23:00:01
为什么 w T Σ w w^T\Sigma w wTΣw 代表类内散度?
在 LDA 在推导中,说 w T Σ w w^T\Sigma w wTΣw 代表类内散度,但为什么呢?
画图观察
import numpy as np import pandas as pd import matplotlib.pyplot as plt
S = np.array([[1,0], [0,1]]) mu = np.array([0,0]) s3 = np.random.multivariate_normal(mu,S,500) # generate 1000 samples from the distribution
# plot the scatter plt.figure(figsize=(10,10)) plt.scatter(s3[:,0],s3[:,1]
)
# set xlim and ylim plt
.xlim
(
-
10
,
10
) plt
.ylim
(
-
10
,
10
)
# add grid plt
.grid
(
True
)
# display the scatter matrix in latex in title plt
.title
(
str
(S
[
0
,
0
]
)
+
' '
+
str
(S
[
0
,
1
]
)
+
'\n'
+
str
(S
[
1
,
0
]
)
+
' '
+
str
(S
[
1
,
1
]
)
,fontsize
=
20
)
结论
Σ = [ σ 11 σ 12 σ 21 σ 22 ] \Sigma =\begin{bmatrix} \sigma_{11} & \sigma_{12} \\ \sigma_{21} & \sigma_{22} \end{bmatrix} Σ=[σ11σ21σ12σ22]
w T Σ w = σ 11 w 1 2 + σ 12 w 1 w 2 + σ 21 w 1 w 2 + σ 22 w 2 2 w^T\Sigma w = \sigma_{11}w_{1}^2+\sigma_{12}w_1w_2+\sigma_{21}w_1w_2+\sigma_{22}w_2^2 wTΣw=σ11w12+σ12w1w2+σ21w1w2+σ22w22
怎么样可以让散度减小呢?观察展开式,其实就是让协方差矩阵的这几个数都尽量小即可。