当前位置:网站首页>Fisher linear discriminant analysis
Fisher linear discriminant analysis
2022-07-19 03:39:00 【elkluh】
Fisher Linear discriminant analysis is a linear classification method , Its main idea is : Is that the variance within the class is small , There is a large difference between the class mean .( Large between classes , Small in class )
Take the classification of two classes as an example :
Set the two classes from x1,x2 Project onto vector u On , In this way, from two-dimensional to one-dimensional , Then separate the two categories from the middle of the two groups .
If you want to make the difference between classes large , Then the average of each class will also differ greatly , set up Are the average values of plus and minus points respectively , So after projection , The square of their distance , That is to say
As big as possible .
If you want to make the intra class variance small , Then the two classes are projected onto a straight line ( vector ) After the , Their points are , Represents the projection of two covariances .
So their sum should be as small as possible
So take the big ones as molecules , The small is the denominator , The whole of their division is that the bigger the better ,
set up
be
Yes J(u) To find the derivative , Then there are
Let the derivative be equal to 0, obtain
The in brackets can be replaced by a scaling value
be
because and
It becomes constant after multiplication
So the final
Is the vector we want to project .
import matplotlib.pyplot as plt
import numpy as np
def gauss2D(x, m, C):
Ci = np.linalg.inv(C) # Find the inverse of a matrix
dC = np.linalg.det(C) # Find the determinant of the matrix
num = np.exp(-0.5 * np.dot((x-m).T, np.dot(Ci,(x-m))))
den = 2 * np.pi * (dC**0.5) # Calculate the density function of the matrix
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')
边栏推荐
- About 1000base-t1 1000Base-TX and 100base-t1
- Installing PWA application in Google Chrome browser will display more description information
- 如何将Excel中的数据粘贴到cxGrid中
- Chapter II linear table
- The third day of the three questions of Luogu daily (make up on the fourth day)
- Number of supported question banks and examination question banks of swiftui examination question bank project (tutorial includes source code)
- Es6 notes d'étude - station B Xiao Ma Ge
- Neural network learning notes 2.2 -- write a simple convolution neural network image classifier with MATLAB
- Unity解决同材质物体重叠产生Z-Fighting的问题
- Reptile learning (5): teach you reptile requests practice hand in hand
猜你喜欢
leetcode 222. Number of nodes of a complete binary tree (required)
laravel的问题
Thinkphp5.0模型操作使用page进行分页
MySQL optimized index
Chengxin University envi_ IDL second week homework: extract aerosol thickness at n points + detailed analysis
Installing PWA application in Google Chrome browser will display more description information
基于Matlab的男女声音信号分析与处理
Configure high availability using virtual ip+kept
机器学习库Scikit-Learn(线性模型、岭回归、插入一列数据(insert)、提取所需列、向量机(SVM)、聚类)
Theoretical basis of doubledqn and its code implementation [pytoch + pendulum-v0]
随机推荐
Machine learning library scikit learn (linear model, ridge regression, insert a column of data, extract the required column, vector machine (SVM), clustering)
如何将Excel中的数据粘贴到cxGrid中
通过Dao投票STI的销毁,SeekTiger真正做到由社区驱动
Chapter I Introduction
模块(block、module)的介绍
Agent mode - power node of station B
Work fishing clock simulator wechat applet source code
Latest installation tutorial of VMware Tools (rhel8)
374. 猜数字大小(入门 必会)
ES6学习笔记——B站小马哥
Note: light source selection and Application
10. Redis interview FAQ
Paper reading: u-net++: redesigning skip connections to exploit multiscale features in image segmentation
Le cinquième jour de trois questions par jour à luogu
MYSQL主从搭建
Oracle closes the recycle bin
Theoretical basis of double Q-learning and its code implementation [pendulum-v0]
Wechat applet
Vs code problem: launch:program '... \ vscode\launch. exe‘ dose not exist
[MySQL] MHA high availability