线性判别分析(Linear Discriminant Analysis,简称LDA)是一种经典的有监督数据降维方法。LDA的主要思想是将一个高维空间中的数据投影到一个较低维的空间中,且投影后要保证各个类别的类内方差小而类间均值差别大,这意味着同一类的高维数据投影到低维空间后相同类别的聚在一起,而不同类别之间相距较远。如下图将二维数据投影到一维直线上:

上图提供了两种方式,哪一种投影方式更好呢?从图上可以直观的看出右边的比左边的投影后分类的效果好,因此右边的投影方式是一种更好地降维方式。
上图直观的给出了LDA分类的主要思想,下图通过数学公式来推导如何得到这个最佳的投影方式。
二类LDA原理
为了方便解释LDA的原理,我们以二分类为例。
假设现有数据集 D = {(x1, y1), (x1, y1), ... ,(xm, ym)},其中任意样本xi为n维向量。定义Nj为第j类样本的个数,Xj为第j类样本的集合,而μj为第j类样本的均值向量,Σ𝑗(𝑗=0,1)为第j类样本的"方差"。
因此,原始均值μj和投影后的均值μ'j的表达式为分别为:

而"方差"则为:

根据上面LDA主要思想的描述我们的目标就是要投影后最大化类间均值差同时最小化类内方差大小。因此目标函数如下:

上式中,分子表示不同类别均值之差,分母表示不同类别方差之和,因此我们的目标就是最大化J(w)即可。
其中,对于分母:

对于分子:

最后目标函数可转化为:

对J(w)的求解过程如下:


一个简单的例子









总结下LDA算法流程
输入:数据集 D = {(x1, y1), (x1, y1), ... ,(xm, ym)},任意样本xi为n维向量,yi∈{C1, C2, ... , Ck},共k个类别。现在要将其降维到d维;
输出:降维后的数据集D'。
- (1)计算类内散度矩阵 SB;
- (2)计算类间散度矩阵 SW;
- (3)将 SB 和 SW 代入上面公式计算得到特征值 λ 和特征向量 w,取前面几个最大的特征值向量λ'与特征向量相乘得到降维转换矩阵 λ'w;
- (4)将原来的数据与转换矩阵相乘得到降维后的数据 (λ'w)Tx ;
网友评论