当前位置:网站首页>Fisher线性判别分析Fisher Linear Distrimination
Fisher线性判别分析Fisher Linear Distrimination
2022-07-17 00:10:00 【elkluh】
Fisher线性判别分析是一种线性分类方法,它的主要思想是:是类内的方差小,类均值之间相差比较大。(类间大,类内小)
以两个类的分类为例:
将两个类由在x1,x2上投影到向量u 上,这样由二维转到了一维,然后将两类从两团点的中间分开。

如果要使类间相差大的话,那么每个类的平均数之间也会相差大,设分别为加号点和减号点的平均值,那么投影后,他们距离的平方,也就是
尽可能大。
如果要使类内方差小的话,那么两个类投影到直线(向量)上后,他们的点分别为
,表示两个协方差的投影。


所以他们的和也要尽可能小
因此把大的作为分子,小的作为分母,他们相除的整体就是越大越好,

设

则 
对J(u)进行求导,则有
令导数等于0, 得到 
括号里的可以用一个缩放值来代替
则 
因为
和
在相乘之后变为常数
因此最终 
就是我们要投影的向量。
import matplotlib.pyplot as plt
import numpy as np
def gauss2D(x, m, C):
Ci = np.linalg.inv(C) #求矩阵的逆
dC = np.linalg.det(C) #求矩阵的行列式
num = np.exp(-0.5 * np.dot((x-m).T, np.dot(Ci,(x-m))))
den = 2 * np.pi * (dC**0.5) #计算矩阵的密度函数
return num/den
def twoDGaussianPlot(nx, ny, m, C):
x = np.linspace(-6, 6, nx)
y = np.linspace(-6, 6, ny)
X, Y = np.meshgrid(x, y, indexing='ij')
Z = np.zeros([nx,ny])
for i in range(nx):
for j in range(ny):
xvec = np.array([X[i,j], Y[i,j]])
Z[i,j] = gauss2D(xvec, m, C)
return X, Y, Z
X = np.random.randn(200, 2)
C1 = np.array([[2,1],[1,2]])
C2 = np.array([[2,1],[1,2]])
m1 = np.array([0, 3])
m2 = np.array([3,2.5])
A = np.linalg.cholesky(C1)
Y1 = X @ A.T + m1
Y2 = X @ A.T + m2
plt.figure(1)
plt.scatter(Y1[:,0], Y1[:,1], c='c', s=4)
plt.scatter(Y2[:,0], Y2[:,1], c='m', s=4)
Xp, Yp, Zp = twoDGaussianPlot(40,50,m1,C1)
plt.contour(Xp, Yp, Zp, 5)
Xp2, Yp2, Zp2 = twoDGaussianPlot(40,50,m2,C2)
plt.contour(Xp2, Yp2, Zp2, 5)
uF = np.linalg.inv(C1 + C2)@(m1-m2)
print(uF)
#ax.arrow(0, 0, *(uF*10), color='b', linewidth=2.0, head_width=0.20, head_length=0.25)
plt.arrow(0, 0, *(uF), color='b', linewidth=2.0, head_width=0.30, head_length=0.35)
plt.axis('equal')
plt.grid()
plt.xlim([-6,6])
plt.ylim([-5,8])
plt.savefig('density graph.png')
yp1 = Y1 @ uF
yp2 = Y2 @ uF
plt.figure(2)
plt.rcParams.update({'font.size':16})
plt.hist(yp1, bins=40)
plt.hist(yp2, bins=40)
plt.savefig('histogramprojections.png')


边栏推荐
- [literature reading] counting integer points in parametric polymers using barvinok's rational functions
- Cannot find module ‘process‘ or its corresponding type declarations.
- 通感一体化融合的研究及其挑战
- windwos 下载安装OpenSSH
- cookie、LocalStorage、sessionStorage三者区别以及使用方式
- [踩坑]packets.go:428: busy buffer invalid connection
- README.md添加目录
- 【pycharm】Cannot find reference ‘XXX‘ in ‘__init__.py‘ 解决办法
- 利用因果线性模型监测不公平A Causal Linear Model to Quantify Edge Unfairness for Unfair Edge Prioritization
- 量子计算机带来的全新通信安全风险分析及应对建议
猜你喜欢

Dhfs read / write process

利用因果线性模型监测不公平A Causal Linear Model to Quantify Edge Unfairness for Unfair Edge Prioritization

mysql innodb 事务相关记录
![[literature reading] tenet: a framework for modeling tensor dataflow based on relational centric notation](/img/2a/786d78cee28382a593cd664695e3b9.png)
[literature reading] tenet: a framework for modeling tensor dataflow based on relational centric notation

Xcode11添加引导页(升级后Launch Images Source选项不见了)

Learning Transferable Visual Models From Natural Language Supervision

【文献阅读】Counting Integer Points in Parametric Polytopes Using Barvinok‘s Rational Functions

Punch in 10 interview questions every day - JVM article

Why is opensea the absolute monopolist of NFT trading market?

Fair Multiple Decision Making Through Soft Interventions
随机推荐
CheckPoint and DataNode
Neutralizing Self-Selection Bias in Sampling for Sortition
通信感知一体化应用场景、关键技术和网络架构
6章 性能平台GodEye源码分析-自定义拓展模块
【文献阅读】Counting Integer Points in Parametric Polytopes Using Barvinok‘s Rational Functions
ACE下载地址
袋鼠云数栈基于CBO在Spark SQL优化上的探索
争夺存量用户关键战,助力企业构建完美标签体系丨01期直播回顾
【文献阅读】isl: An Integer Set Library for the Polyhedral Model
Dhfs read / write process
温州大学X袋鼠云:高等人才教育建设,如何做到“心中有数”
The following packages have unmet dependencies: deepin.com.wechat:i386 : Depends: deepin-wine:i386
Punch in 10 interview questions every day - JVM article
typeorm mysql upsert操作
组合键截图分析
[MySQL] windows install MySQL 5.7
Namenode and secondarynamenode
WKWebView 设置自定义UserAgent正确姿势
雷达通信一体化波形设计综述
Boost thread pool