Understanding fisher discriminant analysis

principle

fisher discriminant method is to find a straight line through the origin, the straight line in FIG effect to be achieved:
Here Insert Picture Description
the specific method:
Here Insert Picture Description
Note: Here is the deviation Sw array, also called covariance matrix.
w is the direction of this line

Straight line Y = wX

The critical point y0 = (n0 * u0 + n1 * u1) / (n0 + n1)

When calculating the projection is determined on the data line, this projection center of the projection compared with the results of clustering the data should belong to which category.

Real

Example: In order to understand a river As, Pb Pollution, provided in A, B two monitoring, sampling the measured concentration of these two elements in the water and sediment (see below table). Identification of unknown samples based on the data from which the area mined.
Here Insert Picture Description
Note: The two belong behavior needs to determine what kind of sample.


clc
clear
X=load("fisher_values.txt");
x1=X(1:5,:);%甲地的已知数据
x2=X(6:10,:);%乙地的已知数据
r1=size(x1,1);%相当于求甲地的样本数
r2=size(x2,1);%相当于求乙地的样本数
sample=X(11:12,:);%待分类的数据
r3=size(sample,1);
%求各类别的均值
ave1=mean(x1);
avel=ave1';
ave2=mean(x2);
ave2=ave2';
%离差矩阵即协方差矩阵。
s1=cov(x1)*(r1-1);
s2=cov(x2)*(r2-1);
sw=s1+s2;%求出协方差矩阵 
w=inv(sw)*(ave1-ave2)*(r1+r2-2);%求出w
y1=mean(w'.*ave1);
y2=mean(w'.*ave2);
y0=(r1*y1+r2*y2)/(r1+r2);
y0=y0';
%利用0,1来区分类别
for i=1:r3
  y(i,:)=w'*sample(1,:)';
   if y(i,:)>y0
      m(i)=0;
   else
      m(i)=1;
   end
end
m %m表示判断结果
Published 23 original articles · won praise 17 · views 4180

Guess you like

Origin blog.csdn.net/qq_43786066/article/details/104254843
Recommended