多元统计回归分析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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 |
实验结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | > 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 54.88 288.13 > 18.25 90.21 24.45 32.44 62.48 7.45 47.5 178.84 > 21.84 66.38 18.05 31.32 74.48 8.19 34.97 177.45 > 21.37 67.08 20.28 35.27 81.07 10.94 39.46 182.2 > 22.74 115.88 28.21 42.44 58.07 9.63 48.65 194.85 > 20.22 88.94 18.54 35.63 65.72 8.81 50.29 186.52 > 21.33 75.5 14 29.56 69.29 8.24 42.08 165.9 > 18.61 122.51 27.07 42.5 63.47 15.38 36.14 240.92 > 19.61 107.13 32.85 35.77 61.34 7.53 34.6 142.23 > 25.56 171.65 22.3 40.53 57.13 12.6 54.03 225.08 > 18.75 104.68 15.55 35.61 51.8 11.18 36.27 142.72 > 18.27 88.34 19.07 43.19 72.97 12.59 42.16 200.18 > 19.07 73.18 18.01 29.38 64.51 8.91 38.14 155.45 > 18.76 102.67 21.87 30.47 64.33 11.99 42.14 168.17 > 20.25 104.45 20.72 38.15 62.98 12.67 39.16 213.56 > 18.7 131.35 11.69 32.06 41.54 10.84 42.77 178.51 > 16.16 139.92 12.98 23.58 24.87 10.76 32.35 144.21 > 18.18 120.39 26.18 37.94 68.16 11.64 38.48 246.37 > 18.53 109.95 21.49 33.04 50.98 10.88 33.96 183.85 > 18.33 92.43 25.38 32.19 56.32 14 38.57 144.82 > 22.3 99.08 33.36 32.01 52.06 7.04 32.85 190.04 > 20.03 70.75 19.75 34.95 53.29 10.55 38.2 189.41 > 18.68 72.74 23.72 38.69 62.41 9.65 35.26 170.12 > 20.33 75.64 20.88 33.85 53.81 10.06 32.82 171.32 > 19.75 70.24 18.67 36.71 61.75 10.08 40.26 165.22 > 21.03 78.55 14.35 34.33 64.98 9.83 33.87 161.67]; X=[ 23.68 173.30 17.43 43.59 53.66 16.86 65.02 385.94 > 29.67 146.90 64.51 54.36 86.10 14.77 32.19 193.10]; [COEFF,DIST,CLASS] = dclass(X1,X2,X) |
CLASS =
1 2 2 根据结果,广东和西藏被归为第二大类