当前位置:网站首页>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')


边栏推荐
- 欢迎进入Hensen_的博客目录(全站式导航)
- Xcode11新建项目后的一些问题
- The platform of digital collection NFT is good
- L1,L2范数
- 网络安全新架构:零信任安全
- Rivaliser pour la guerre clé des utilisateurs de stock, aider les entreprises à construire un système d'étiquetage parfait 丨 01 examen en direct
- typeorm mysql upsert操作
- [go language] detailed explanation of dynamic library and static library
- Activity的启动模式
- Handling Conditional Discrimination(可解释歧视和确切的歧视)
猜你喜欢

温州大学X袋鼠云:高等人才教育建设,如何做到“心中有数”

The interviewer asked: how to check if redis suddenly slows down?

ChunJun支持异构数据源DDL转换与自动执行 丨DTMO 02期回顾(内含课程回放+课件)

iFair: Learning Individually Fair Data Representations for Algorithmic Decision Making

Why is opensea the absolute monopolist of NFT trading market?

One vs One Mitigation of Intersectional Bias

开源项目丨 Taier 1.1 版本正式发布,新增功能一览为快

【文献阅读】VAQF: Fully Automatic Software-Hardware Co-Design Framework for Low-Bit Vision Transformer

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

玩转集群配置中心,一文带你了解Taier控制台
随机推荐
Fairness in Deep Learning: A Computational Perspective
iPhone 各大机型设备号
golang编译的常见错误
README.md添加目录
【pycharm】Cannot find reference ‘XXX‘ in ‘__ init__. Py 'solution
[literature reading] counting integer points in parametric polymers using barvinok's rational functions
Cocos Creator 3.0 基础——事件系统
phthon3 安装 MySQLdb 报错问题解决 Reason: image not found
Why is opensea the absolute monopolist of NFT trading market?
2章 性能平台GodEye源码分析-数据模块
通感一体去蜂窝超大规模MIMO与高频段无线接入技术
MapReduce
数据指标体系如何搭建才最有效,从0到1带你快速入门丨02期直播回顾
3章 性能平台GodEye源码分析-内存模块
深度伪造对国家安全的挑战及应对
Why do you spend 1.16 million to buy an NFT avatar in the library of NFT digital collections? The answer may be found by reviewing the "rise history" of NFT avatars
IPFs mount to local disk
基于移动互联网应用的儿童网络保护产业实践与完善
touchID 和 FaceID~1
mysql innodb 事务相关记录