多元统计回归分析
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e23a30524659dfc697b49b15b17d0294.png#pic_center)
function [COEFF,DIST,CLASS] = dclass(X1,X2,X)
% dclass作为两个模式类的距离判别分析
% 语法[COFEE,DIST,CLASS]=dclass(X1,X2,X)
% x1,x2——分别为类1、类2的训练样本“样品×变量”矩阵
% x——为待判样品的“样品×变量”矩阵
% COEFF——判别函数的系数向量
% CLASS——待判样品的分类
[N1,~]=size(X1);
[N2,~]=size(X2);
[N,~]=size(X);
MEANX1=mean(X1);
MEANX2=mean(X2);
COVX1=(N1-1)*cov(X1);
COVX2=(N2-1)*cov(X2);
MEAN=(MEANX1+MEANX2)./2;
COV=(COVX1+COVX2)./(N1+N2-2);
COEFF=inv(COV)*(MEANX1-MEANX2)';
DIST=[];
CLASS=[];
for byk=1:N
w=(X(byk,:)-MEAN)*COEFF;
if w>0
r=1;
else
r=2;
end
DIST=[DIST,w];
CLASS=[CLASS,r];
end
COEFF=COEFF';
end
实验结果
> clear all; clc; X1=[21.3 124.89 35.43 73.98 93.01 20.58 43.97 433.73
> 21.13 168.69 40.81 70.12 74.32 15.46 50.9 422.74
> 19.96 142.24 43.33 50.74 101.77 12.92 53.44 394.55]; X2=[21.5 122.39 29.08 51.64 55.04 11.3