实验报告一-主成分分析(共17页).docx
精选优质文档-倾情为你奉上多元统计分析实验报告 姓 名: 张 莉 萍 学 号: 日 期: 2017年11月10日 评分标准序号数学原理(5分)程序(20分)结果分析(20分)写作(5分)总分题目1序号数学原理(5分)程序(20分)结果分析(20分)写作(5分)题目2实验报告一 主成分分析实验目的:1、 熟练掌握利用MATLAB进行主成分分析的计算步骤。2、 掌握选择主成分个数的原则以及利用特征值建立权向量的方法。3、 能根据主成分的数学公式,针对实际问题给出主成分的合理解释。4、 掌握典型相关分析的方法。表5-12 各地区国有及国有控股工业企业主要经济效益指标(2007年)地区工业增加值率总资产贡献率资产负债率流动资产周转次数工业成本费用利润率产品销售率北京25.925.5234.042.057.9399.19天津34.2916.1862.662.6212.4499.58河北29.4611.8761.022.537.2399.34山西37.5811.2867.651.958.6898.18内蒙古47.3611.4362.232.2113.899.08辽宁28.738.8660.882.174.1499.21吉林30.3115.1458.532.669.2695.97黑龙江52.1233.6755.262.5632.9499.21上海27.3912.4245.622.138.0499.26江苏26.4514.0258.992.886.9199.64浙江24.4814.8258.813.186.1799.65安徽35.1310.6365.652.394.9598.4福建29.7612.6759.342.418.1199.54江西26.751265.122.515.698.69山东31.617.6459.022.949.9199.36河南37.713.0265.022.686.8698.58湖北33.7510.6554.282.179.8798.56湖南35.9616.6262.352.62799.32广东32.8417.6848.652.8812.8599.36广西32.3112.1264.042.457.72101.2海南35.0213.5949.412.3414.5101.23重庆32.9611.9759.242.035.9796.58四川3710.7263.541.78.6298.8贵州37.4912.5265.691.868.9798.35云南41.2220.9449.161.8512.4499.42西藏63.033.3220.40.5310.7690.38陕西43.6716.6157.281.9117.8298.36甘肃26.5713.4258.382.547.5198.31青海41.6214.5863.151.9226.5998.11宁夏38.988.2763.531.835.0798.53新疆45.5825.8449.363.1629.88100.29(1) 根据指标的属性将原始数据统一趋势化。(2) 利用协方差、相关系数矩阵进行主成分分析,可否只用第一主成分排名。(3) 构造新的实对称矩阵,使得可以只用第一主成分排名。(4) 排名的结果是否合理?为什么?解:(1)A=25.92,5.52,34.04,2.05,7.93,99.19; 34.29,16.18,62.66,2.62,12.44,99.58; 45.58,25.84,49.36,3.16,29.88,100.29令:r=corrcoef(A); % 计算矩阵A的相关系数矩阵得到的相关系数矩阵为:r = 1.0000 0.2121 -0.3414 -0.5342 0.5812 -0.4993 0.2121 1.0000 0.1377 0.5214 0.7293 0.3818 -0.3414 0.1377 1.0000 0.3994 -0.1695 0.4629 -0.5342 0.5214 0.3994 1.0000 0.0838 0.6592 0.5812 0.7293 -0.1695 0.0838 1.0000 0.0909 -0.4993 0.3818 0.4629 0.6592 0.0909 1.0000表明各个变量之间无明显的共性关系,可以进一步进行主成分分析的命令。对原始数据进行数据统一趋势化,将资产负债率转化成效益型,其变换公式为B=(bij)n*p,bij=(xij-jminxij)(jmaxxij-jminxij)(效益型)(jmaxxij-xij)(jmaxxij-jminxij)(成本型)(jmaxxij-j-xij-j)maxxij-j-jminxij-j(适度型)令:m,n=size(A)A1=(A(:,1)-min(A(:,1)./(max(A(:,1)-min(A(:,1);A2=(A(:,2)-min(A(:,2)./(max(A(:,2)-min(A(:,2);A3=(max(A(:,3)-A(:,3)./(max(A(:,3)-min(A(:,3);A4=(A(:,4)-min(A(:,4)./(max(A(:,4)-min(A(:,4);A5=(A(:,5)-min(A(:,5)./(max(A(:,5)-min(A(:,5);A6=(A(:,6)-min(A(:,6)./(max(A(:,6)-min(A(:,6);B=A1,A2,A3,A4,A5,A6得到矩阵B为:B = 0.0374 0.0725 0.7113 0.5736 0.1316 0.8120 0.2545 0.4237 0.1056 0.7887 0.2882 0.8479 0.1292 0.2817 0.1403 0.7547 0.1073 0.8258 0.3398 0.2623 0 0.5358 0.1576 0.7189 0.5935 0.2672 0.1147 0.6340 0.3354 0.8018 0.1102 0.1825 0.1433 0.6189 0 0.8138 0.1512 0.3895 0.1930 0.8038 0.1778 0.5152 0.7170 1.0000 0.2622 0.7660 1.0000 0.8138 0.0755 0.2998 0.4662 0.6038 0.1354 0.8184 0.0511 0.3526 0.1833 0.8868 0.0962 0.8535 0 0.3789 0.1871 1.0000 0.0705 0.8544 0.2763 0.2409 0.0423 0.7019 0.0281 0.7392 0.1370 0.3081 0.1759 0.7094 0.1378 0.8442 0.0589 0.2860 0.0535 0.7472 0.0507 0.7659 0.1847 0.4718 0.1826 0.9094 0.2003 0.8276 0.3429 0.3196 0.0557 0.8113 0.0944 0.7558 0.2405 0.2415 0.2830 0.6189 0.1990 0.7539 0.2978 0.4382 0.1122 0.7887 0.0993 0.8240 0.2169 0.4731 0.4021 0.8868 0.3024 0.8276 0.2031 0.2900 0.0764 0.7245 0.1243 0.9972 0.2734 0.3384 0.3860 0.6830 0.3597 1.0000 0.2200 0.2850 0.1780 0.5660 0.0635 0.5714 0.3248 0.2438 0.0870 0.4415 0.1556 0.7760 0.3375 0.3031 0.0415 0.5019 0.1677 0.7346 0.4342 0.5806 0.3913 0.4981 0.2882 0.8332 1.0000 0 1.0000 0 0.2299 0 0.4978 0.4379 0.2195 0.5208 0.4750 0.7355 0.0542 0.3328 0.1962 0.7585 0.1170 0.7309 0.4446 0.3710 0.0952 0.5245 0.7795 0.7124 0.3761 0.1631 0.0872 0.4906 0.0323 0.7512 0.5473 0.7420 0.3871 0.9925 0.8938 0.9134(2)令R=corrcoef(B) % 计算矩阵B的相关系数矩阵得到的相关系数矩阵为:R = 1.0000 0.2121 0.3414 -0.5342 0.5812 -0.4993 0.2121 1.0000 -0.1377 0.5214 0.7293 0.3818 0.3414 -0.1377 1.0000 -0.3994 0.1695 -0.4629 -0.5342 0.5214 -0.3994 1.0000 0.0838 0.6592 0.5812 0.7293 0.1695 0.0838 1.0000 0.0909 -0.4993 0.3818 -0.4629 0.6592 0.0909 1.0000表明各个变量之间无明显的共性关系,可以进一步进行主成分分析的命令。a. 利用相关系数矩阵进行主成分分析令:v1,d1=eig(corrcoef(B) % 样本相关系数矩阵的特征值得到结果如下:v1 = 0.3973 0.4564 -0.3541 0.0499 -0.6454 -0.2990 -0.2931 0.5722 0.0316 -0.2765 -0.1388 0.7000 0.4030 0.1312 0.8834 0.1228 -0.1528 0.0399 -0.5513 0.0765 0.2943 -0.4985 -0.2307 -0.5494 -0.0061 0.6631 0.0031 0.1927 0.6371 -0.3423 -0.5384 0.0377 0.0813 0.7876 -0.2860 -0.0055d1 = 2.5989 0 0 0 0 0 0 2.0777 0 0 0 0 0 0 0.6831 0 0 0 0 0 0 0.3671 0 0 0 0 0 0 0.1405 0 0 0 0 0 0 0.1327因为,最大的特征值对应的不是正向量,所以不能用第一主成分进行排名。b. 利用协方差矩阵进行主成分分析令:v2,d2=eig(cov(B) % 样本协方差矩阵的特征值得到结果如下:v2 = 0.3165 -0.5994 -0.1127 -0.3839 -0.0469 -0.6150 -0.7289 -0.2252 -0.3177 0.0564 0.5328 -0.1733 -0.0180 -0.1808 0.0602 0.8683 -0.2758 -0.3652 0.5653 -0.1391 -0.5057 0.2953 0.4787 0.2983 0.2160 0.5656 0.2651 0.0348 0.5102 -0.5493 0.0453 -0.4670 0.7462 0.0837 0.3852 0.2601d2 = 0.0050 0 0 0 0 0 0 0.0067 0 0 0 0 0 0 0.0122 0 0 0 0 0 0 0.0301 0 0 0 0 0 0 0.0931 0 0 0 0 0 0 0.1068因为,最大的特征值对应的不是正向量,所以不能用第一主成分进行排名。(3)利用R矩阵进行主成分分析m,n=size(B); % 计算原始数据维数fori=1:nforj=1:nR(i,j)=2*dot(B(:,i),B(:,j)./sum(B(:,i).2)+sum(B(:,j).2) % 计算R矩阵v3,d3=eig(R); % R矩阵的特征值和特征向量q=sum(d3)/sum(sum(d3) % 计算贡献率得到结果如下:v3 = 0.0573 0.1700 0.8123 -0.0311 -0.3650 0.4169 -0.2457 0.6976 -0.3708 -0.3348 0.0048 0.4510 -0.0216 -0.0427 -0.3306 0.7663 -0.4179 0.3558 0.7370 0.0253 -0.0286 0.1050 0.5246 0.4112 0.0936 -0.6149 -0.2584 -0.5160 -0.3343 0.4103 -0.6196 -0.3223 0.1606 0.1501 0.5524 0.3985d3 = 0.0199 0 0 0 0 0 0 0.0947 0 0 0 0 0 0 0.1897 0 0 0 0 0 0 0.4629 0 0 0 0 0 0 0.9318 0 0 0 0 0 0 4.3011q =0.0033 0.0158 0.0316 0.0771 0.1553 0.7168输出的结果显示,最大特征值(4.3011)对应的是正向量,且其贡献率为71.68%,所以能用第一主成分得分进行排名。(4)令F=B-ones(m,1)*mean(B)*d3(:,6); % 计算主成分得分F2,I1=sort(F,descend); % I1给出各名次的序号F2,I2=sort(I1); % I2给出各地区的排名Plot(1:m,F,*); % 主成分得分图得到结果如下:地区序号得分(F)排名(I2)地区序号得分(F)排名(I2)北京10.194516湖北17-0.055221天津20.34916湖南180.24612河北30.25411广东190.261910山西4-0.205927广西200.99132内蒙古50.150917海南211.00321辽宁60.202414重庆22-0.840129吉林7-1.081930四川230.039918黑龙江80.202415贵州24-0.138525上海90.222213云南250.28578江苏100.37295西藏26-3.297931浙江110.37684陕西27-0.134524安徽12-0.118723甘肃28-0.154326福建130.33327青海29-0.233628江西14-0.003719宁夏30-0.067122山东150.26199新疆310.63063河南16-0.047320排名的结果是合理的,因为第一主成分分析的贡献率为71.68%,可以用第一主成分代替原来的六个变量,对样本总体进行排名。实验报告二 聚类方法与聚类有效性实验目的1、 熟练掌握应用MATLAB软件计算谱系聚类与K均值聚类的命令。2、 熟练掌握模糊C均值类与模糊减法聚类的MATLAB实现。3、 掌握最优聚类数的理论及其实现。实验数据与内容2008年我国34个地区中的29个地区的城镇居民人均收入见表6-6。解决以下问题: 表6-6 城镇居民人均收入 (单位:元/人)省(区、市)工薪收入经营净收入财产性收入转移性收入北京18738.96778.36452.757707.87河北8891.51078.67224.863946.39山西9019.35983.21202.313654.11内蒙古10284.431555.31324.643031.05辽宁9494.591483.3248.044610.32黑龙江7393.391241.37122.833506.48上海21791.111399.14369.126199.77江苏12319.861999.61307.315548.78浙江15538.833161.871324.944955.14安徽9302.38959.43293.923603.72福建12668.822185.13952.913879.29江西9105.961106.31265.352985.96山东12940.621194.4346.93067.05河南9043.521161.96156.463545.86湖北9474.811114.68244.133340.65湖南9070.971575.08316.483614.74广东15188.392405.92701.253382.95广西10321.21314.4441.153316.44海南8999.751311.38396.892890.59重庆10957.62788.26205.943265.92四川91171040.14262.93265.06贵州7811.16770.86110.93492.7云南8596.881165.96849.453505.74西藏12314.69303.34138.08891.42陕西9794.82544151.463356.85甘肃8354.63638.7665.332610.61青海8595.48763.0750.173458.63宁夏8793.541856.94182.673285.49新疆9422.22938.15141.751976.49(1) 计算各样品间的欧氏距离、马氏距离和加权平方距离。(2) 运用谱系聚类法进行聚类,包括确定最优聚类数,选择合适的类间距离,同时作出谱系图。(3) 运用K均值聚类法进行聚类。(4) 运用模糊C均值聚类和模糊减法聚类法进行聚类。(5) 综合分析以上不同的聚类法所得的聚类结果,能得到什么样的结论?解:(1)x=15538.83,3161.87,1324.94,4955.14;9302.38,959.43,293.92,3603.72;9422.22,938.15,141.75,1976.49;15538.83,3161.87,1324.94,4955.14a. 计算欧氏距离令:d1=pdist(x,'euclidean'); % 计算各行之间的欧氏距离 D1=squareform(d1); % 将行向量d1转变成一个方阵得到结果如下:D1 =1.0e+03 * Columns 1 through 8 0 6.8289 3.2383 7.1139 3.8914 7.0385 6.6887 6.8677 6.8289 0 3.6531 0.6653 3.6855 0.3609 0.3543 0.6582 3.2383 3.6531 0 3.8896 1.4431 3.8646 3.4843 3.7137 7.1139 0.6653 3.8896 0 3.8374 0.5765 0.5122 0.7867 3.8914 3.6855 1.4431 3.8374 0 3.9312 3.4790 3.9268 7.0385 0.3609 3.8646 0.5765 3.9312 0 0.4879 0.4492 6.6887 0.3543 3.4843 0.5122 3.4790 0.4879 0 0.6748 6.8677 0.6582 3.7137 0.7867 3.9268 0.4492 0.6748 0 1.8855 6.0788 2.5897 6.2476 2.5972 6.2953 5.8756 6.1899 5.8398 1.1261 2.6169 1.2885 2.6357 1.3377 0.8920 1.3174 7.1629 0.8571 3.9386 0.2824 3.9469 0.7151 0.7002 0.7781 5.5432 1.7003 2.4111 1.9004 2.0388 1.9708 1.5206 2.0766 7.0517 0.3956 3.8445 0.2871 3.8328 0.3323 0.3737 0.6430 8.3094 1.5183 5.1435 1.4386 5.1699 1.2948 1.7108 1.5136 7.3825 0.9266 4.2154 0.9349 4.3948 0.8254 1.0803 0.8295 6.0406 4.1092 3.6411 3.9171 2.4419 4.2993 3.8384 4.4258 6.6165 0.7045 3.4451 0.9702 3.2313 0.9910 0.6610 1.2965 8.0661 1.4281 4.8374 0.9818 4.6506 1.2772 1.4305 1.5688 7.6045 0.7866 4.4279 0.8051 4.3940 0.6154 0.9739 0.9903 7.1620 1.0854 4.0089 0.8704 4.2086 0.7836 1.0109 0.5317 7.2547 1.6389 4.0465 1.0782 3.6981 1.6299 1.3803 1.8010 0 6.8289 3.2383 7.1139 3.8914 7.0385 6.6887 6.8677 Columns 9 through 16 1.8855 5.8398 7.1629 5.5432 7.0517 8.3094 7.3825 6.0406 6.0788 1.1261 0.8571 1.7003 0.3956 1.5183 0.9266 4.1092 2.5897 2.6169 3.9386 2.4111 3.8445 5.1435 4.2154 3.6411 6.2476 1.2885 0.2824 1.9004 0.2871 1.4386 0.9349 3.9171 2.5972 2.6357 3.9469 2.0388 3.8328 5.1699 4.3948 2.4419 6.2953 1.3377 0.7151 1.9708 0.3323 1.2948 0.8254 4.2993 5.8756 0.8920 0.7002 1.5206 0.3737 1.7108 1.0803 3.8384 6.1899 1.3174 0.7781 2.0766 0.6430 1.5136 0.8295 4.4258 0 4.9953 6.3113 4.5580 6.2396 7.5801 6.7099 4.3822 4.9953 0 1.3891 0.8601 1.2489 2.5954 1.7883 3.3119 6.3113 1.3891 0 2.0698 0.4955 1.4660 0.8756 4.0086 4.5580 0.8601 2.0698 0 1.8586 3.1561 2.4874 2.7784 6.2396 1.2489 0.4955 1.8586 0 1.3611 0.8297 4.0519 7.5801 2.5954 1.4660 3.1561 1.3611 0 1.1485 5.2219 6.7099 1.7883 0.8756 2.4874 0.8297 1.1485 0 4.6805 4.3822 3.3119 4.0086 2.7784 4.0519 5.2219 4.6805 0 5.7324 0.9778 1.2242 1.1929 0.8523 2.0016 1.5268 3.5336 7.1291 2.2279 1.0281 2.6920 1.0998 1.0455 1.3239 4.3308 6.8261 1.8588 0.9523 2.3752 0.6569 0.7874 0.8963 4.5434 6.4400 1.6419 0.7362 2.4138 0.8824 1.4808 1.0046 4.5327 6.1396 1.6837 1.1038 2.0116 1.3337 2.2189 1.8901 3.1538 1.8855 5.8398 7.1629 5.5432 7.0517 8.3094 7.3825 6.0406 Columns 17 through 22 6.6165 8.0661 7.6045 7.1620 7.2547 0 0.7045 1.4281 0.7866 1.0854 1.6389 6.828