# LDA(Fisher)线性判别分析

LDA(Linear Discriminant Analysis)是一种经典的线性判别方法，又称Fisher判别分析。该方法思想比较简单:给定训练集样例，设法将样例投影到一维的直线上，使得同类样例的投影点尽可能接近和密集（即希望类内离散度越小越好），异类投影点尽可能远离（即希望两类的均值点之差越小越好）

∂ L ( w , λ ) ∂ w = ( S b + S b T ) w − λ ( S w + S w T ) w = 2 S b w − 2 λ S w w = 0 \frac{\partial L(w,\lambda)}{\partial w}=(S_{b}+S_{b}^{T})w-\lambda(S_{w}+S_{w}^{T})w\\ =2S_{b}w-2\lambda S_{w}w=0

S w − 1 S b w = λ w S_{w}^{-1}S_{b}w=\lambda w
S b w = ( μ 1 − μ 2 ) ( μ 1 − μ 2 ) T w = β ( μ 1 − μ 2 ) S_{b}w=(\mu_{1}-\mu_{2})(\mu_{1}-\mu_{2})^{T}w=\beta(\mu_{1}-\mu_{2}) 表明 S b w S_{b}w 的方向恒为 μ 1 − μ 2 \mu_{1}-\mu_{2} ,带入上式可得：
w = β λ S w − 1 ( μ 1 − μ 2 ) w=\frac{\beta}{\lambda}S_{w}^{-1}(\mu_{1}-\mu_{2})

w = S w − 1 ( μ 1 − μ 2 ) w=S_{w}^{-1}(\mu_{1}-\mu_{2})

sklearn实现LDA线性判别：

import numpy as np
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
y = np.array([1, 1, 1, 2, 2, 2])
clf = LinearDiscriminantAnalysis(solver='svd')
clf.fit(X, y)
print(clf.predict([[-0.8, -1]])) # [1]


12-22
04-23 1万+
05-16 1万+
05-19 1万+
01-18 3万+
05-05 632
12-02 3298
06-18 5090
11-03 3051
01-19 5053
08-15 1013
04-16 2万+
06-28 3055
02-19 909