完整word版主成分分析法matlab实现实例演示文档格式.docx
- 文档编号:18423109
- 上传时间:2022-12-16
- 格式:DOCX
- 页数:14
- 大小:58.54KB
完整word版主成分分析法matlab实现实例演示文档格式.docx
《完整word版主成分分析法matlab实现实例演示文档格式.docx》由会员分享,可在线阅读,更多相关《完整word版主成分分析法matlab实现实例演示文档格式.docx(14页珍藏版)》请在冰豆网上搜索。
%cwstd.m,用总和标准化法标准化矩阵
functionstd=cwstd(vector)
cwsum=sum(vector,1);
%对列求和
[a,b]=size(vector);
%矩阵大小,a为行数,b为列数
fori=1:
a
forj=1:
b
std(i,j)=vector(i,j)/cwsum(j);
end
end
3.2cwfac.m计算相关系数矩阵
%cwfac.m
functionresult=cwfac(vector);
fprintf('
相关系数矩阵:
\n'
)
std=CORRCOEF(vector)%计算相关系数矩阵
特征向量(vec)及特征值(val):
[vec,val]=eig(std)%求特征值(val)及特征向量(vec)
newval=diag(val);
[y,i]=sort(newval);
%对特征根进行排序,y为排序结果,i为索引
特征根排序:
forz=1:
length(y)
newy(z)=y(length(y)+1-z);
%g\n'
newy)
rate=y/sum(y);
\n贡献率:
newrate=newy/sum(newy)
sumrate=0;
newi=[];
fork=length(y):
-1:
1
sumrate=sumrate+rate(k);
newi(length(y)+1-k)=i(k);
ifsumrate>
0.85break;
end
end%记下累积贡献率大85%的特征值的序号放入newi中
主成分数:
%g\n\n'
length(newi));
主成分载荷:
forp=1:
length(newi)
forq=1:
result(q,p)=sqrt(newval(newi(p)))*vec(q,newi(p));
end%计算载荷
disp(result)
3.3cwscore.m
%cwscore.m,计算得分
functionscore=cwscore(vector1,vector2);
sco=vector1*vector2;
csum=sum(sco,2);
[newcsum,i]=sort(-1*csum);
[newi,j]=sort(i);
计算得分:
score=[sco,csum,j]
%得分矩阵:
sco为各主成分得分;
csum为综合得分;
j为排序结果
3.4cwprint.m
%cwprint.m
functionprint=cwprint(filename,a,b);
%filename为文本文件文件名,a为矩阵行数(样本数),b为矩阵列数(变量指标数)
fid=fopen(filename,'
r'
vector=fscanf(fid,'
%g'
[ab]);
标准化结果如下:
v1=cwstd(vector)
result=cwfac(v1);
cwscore(v1,result);
4.程序测试
4.1原始数据
中国大陆35个大城市某年的10项社会经济统计指标数据见下表。
城市
名称
年底
总人口
(万人)
非农业
人口比(%)
农业
总产值
(万元)
工业
客运总量
货运总量
(万吨)
地方财政
预算内收入(万元)
城乡居民年底储蓄余额
在岗职工人数(万人)
在岗职工工资总额
北京
1249.90
0.5978
1843427
19999706
20323
45562
2790863
26806646
410.80
5773301
天津
910.17
0.5809
1501136
22645502
3259
26317
1128073
11301931
202.68
2254343
石家庄
875.40
0.2332
2918680
6885768
2929
1911
352348
7095875
95.60
758877
太原
299.92
0.6563
236038
2737750
1937
11895
203277
3943100
88.65
654023
呼和浩特
207.78
0.4412
365343
816452
2351
2623
105783
1396588
42.11
309337
沈阳
677.08
0.6299
1295418
5826733
7782
15412
567919
9016998
135.45
1152811
大连
545.31
0.4946
1879739
8426385
10780
19187
709227
7556796
94.15
965922
长春
691.23
0.4068
1853210
5966343
4810
9532
357096
4803744
102.63
884447
哈尔滨
927.09
0.4627
2663855
4186123
6720
7520
481443
6450020
172.79
1309151
上海
1313.12
0.7384
2069019
54529098
6406
44485
4318500
25971200
336.84
5605445
南京
537.44
0.5341
989199
13072737
14269
11193
664299
5680472
113.81
1357861
杭州
616.05
0.3556
1414737
12000796
17883
11684
449593
7425967
96.90
1180947
宁波
538.41
0.2547
1428235
10622866
22215
10298
501723
5246350
62.15
824034
合肥
429.95
0.3184
628764
2514125
4893
1517
233628
1622931
47.27
369577
福州
583.13
0.2733
2152288
6555351
8851
7190
467524
5030220
69.59
680607
厦门
128.99
0.4865
333374
5751124
3728
2570
418758
2108331
46.93
657484
南昌
424.20
0.3988
688289
2305881
3674
3189
167714
2640460
62.08
479,555
济南
557.63
0.4085
1486302
6285882
5915
11775
460690
4126970
83.31
756696
青岛
702.97
0.3693
2382320
11492036
13408
17038
658435
4978045
103.52
961704
郑州
615.36
0.3424
677425
5287601
10433
6768
387252
5135338
84.66
696848
武汉
740.20
0.5869
1211291
7506085
9793
15442
604658
5748055
149.20
1314766
长沙
582.47
0.3107
1146367
3098179
8706
5718
323660
3461244
69.57
596986
广州
685.00
0.6214
1600738
23348139
22007
23854
1761499
20401811
182.81
3047594
深圳
119.85
0.7931
299662
20368295
8754
4274
1847908
9519900
91.26
1890338
南宁
285.87
0.4064
720486
1149691
5130
3293
149700
2190918
45.09
371809
海口
54.38
0.8354
44815
717461
5345
2356
115174
1626800
19.01
198138
重庆
3072.34
0.2067
4168780
8585525
52441
25124
898,912
9090969
223.73
1606804
成都
1003.56
0.335
1935590
5894289
40140
19632
561189
7479684
132.89
1200671
贵阳
321.50
0.4557
362061
2247934
15703
4143
197908
1787748
55.28
419681
昆明
473.39
0.3865
793356
3605729
5604
12042
524216
4127900
88.11
842321
西安
674.50
0.4094
739905
3665942
10311
9766
408896
5863980
114.01
885169
兰州
287.59
0.5445
259444
2940884
1832
4749
169540
2641568
65.83
550890
西宁
133.95
0.5227
65848
711310
1746
1469
49134
855051
27.21
219251
银川
95.38
0.5709
171603
661226
2106
1193
74758
814103
23.72
178621
乌鲁木齐
158.92
0.8244
78513
1847241
2668
9041
254870
2365508
55.27
517622
4.2运行结果
>
cwprint('
cwbook.txt'
35,10)
fid=
6
数据标准化结果如下:
v1=
0.05810.03560.04350.06800.05570.11120.11940.11840.10830.1392
0.04230.03460.03540.07700.00890.06420.04830.04990.05340.0544
0.04070.01390.06880.02340.00800.00470.01510.03140.02520.0183
0.01390.03910.00560.00930.00530.02900.00870.01740.02340.0158
0.00970.02630.00860.00280.00640.00640.00450.00620.01110.0075
0.03150.03750.03050.01980.02130.03760.02430.03980.03570.0278
0.02530.02950.04430.02860.02950.04680.03040.03340.02480.0233
0.03210.02420.04370.02030.01320.02330.01530.02120.02700.0213
0.04310.02760.06280.01420.01840.01840.02060.02850.04550.0316
0.06100.04400.04880.18530.01760.10860.18480.11480.08880.1352
0.02500.03180.02330.04440.03910.02730.02840.02510.03000.0327
0.02860.02120.03340.04080.04900.02850.01920.03280.02550.0285
0.02500.01520.03370.03610.06090.02510.02150.02320.01640.0199
0.02000.01900.01480.00850.01340.00370.01000.00720.01250.0089
0.02710.01630.05080.02230.02430.01750.02000.02220.01830.0164
0.00600.02900.00790.01950.01020.00630.01790.00930.01240.0159
0.01970.02370.01620.00780.01010.00780.00720.01170.01640.0116
0.02590.02430.03500.02140.01620.02870.01970.01820.02200.0182
0.03270.02200.05620.03910.03670.04160.02820.02200.02730.0232
0.02860.02040.01600.01800.02860.01650.01660.02270.02230.0168
0.03440.03490.02860.02550.02680.03770.02590.02540.03930.0317
0.02710.01850.02700.01050.02390.01400.01390.01530.01830.0144
0.03180.03700.03770.07930.06030.05820.07540.09010.04820.0735
0.00560.04720.00710.06920.02400.01040.07910.04210.02400.0456
0.01330.02420.01700.00390.01410.00800.00640.00970.01190.0090
0.00250.04970.00110.00240.01460.00570.00490.00720.00500.0048
0.14280.01230.09830.02920.14370.06130.03850.04020.05900.0387
0.04660.01990.04560.02000.11000.04790.02400.03310.03500.0290
0.01490.02710.00850.00760.04300.01010.00850.00790.01460.0101
0.02200.02300.01870.01230.01540.02940.02240.01820.02320.0203
0.03130.02440.01740.01250.02830.02380.01750.02590.03000.0213
0.01340.03240.00610.01000.00500.01160.00730.01170.01730.0133
0.00620.03110.00160.00240.00480.00360.00210.00380.00720.0053
0.00440.03400.00400.00220.00580.00290.00320.00360.00630.0043
0.00740.04910.00190.00630.00730.02210.01090.01050.01460.0125
std=
1.0000-0.34440.84250.36030.73900.62150.40390.49670.67610.4689
-0.34441.0000-0.47500.3096-0.35390.19710.35710.26000.15700.3090
0.8425-0.47501.00000.33580.58910.50560.32360.44560.55750.3742
0.36030.30960.33581.00000.15070.76640.94120.84800.73200.8614
0.7390-0.35390.58910.15071.00000.42940.19710.31820.38930.2595
0.62150.19710.50560.76640.42941.00000.83160.89660.93020.9027
0.40390.35710.32360.94120.19710.83161.00000.92330.83760.9527
0.49670.26000.44560.84800.31820.89660.92331.00000.92010.9731
0.67610.15700.55750.73200.38930.93020.83760.92011.00000.9396
0.46890.30900.37420.86140.25950.90270.95270.97310.93961.0000
特征向量(vec):
vec=
-0.13670.2282-0.26280.19390.6371-0.21630.3176-0.1312-0.41910.2758
-0.0329-0.02170.00090.0446-0.1447-0.44370.4058-0.55620.54870.0593
-0.0522-0.02800.2040-0.0492-0.5472-0.42250.34400.3188-0.44380.24010.0067-0.4176-0.2856-0.23890.1926-0.4915-0.41890.27260.20650.34030.04040.14080.08960.0380-0.1969-0.0437-0.4888-0.6789-0.44050.1861
-0.03430.23600.0640-0.82940.03770.26620.1356-0.12900.02780.3782
0.29810.47390.56850.23580.1465-0.1502-0.26310.12450.21520.3644
0.15670.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 完整 word 版主 成分 分析 matlab 实现 实例 演示
![提示](https://static.bdocx.com/images/bang_tan.gif)