資源描述:
《主成分分析matlab源程序代碼.doc》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、dataset=[263.8621.611442.754680.268.7642.072182.617560.261.1961.597692.350370.248.7082.096092.852790.253.3651.694572.94920.268.4341.568192.781130.13252258.7412.146532.691110.244.1922.021562.226070.219.7381.612241.885990.244.7021.914772.259450.245.2862.124992.352820.251.961.837142.535190.251.1641
2、.741672.629610.251.8242.001332.626650.257.682.148782.656860.]stdr=std(dataset);%求個變量的標(biāo)準(zhǔn)差[n,m]=size(dataset);%定義矩陣行列數(shù)sddata=dataset./stdr(ones(n,1),:);%將原始數(shù)據(jù)采集標(biāo)準(zhǔn)化sddata%輸出標(biāo)準(zhǔn)化數(shù)據(jù)[p,princ,eigenvalue,t2]=princomp(sddata);%調(diào)用前三個主成分系數(shù)p3=p(:,1:3);%提取前三個主成分得分系數(shù),通過看行可以看出對應(yīng)的原始數(shù)據(jù)的列,每個列在每個主成分的得分p3%輸出前三個主成分得分
3、系數(shù)sc=princ(:,1:3);%提取前三個主成分得分值sc%輸出前三個主成分得分值e=eigenvalue(1:3)';%提取前三個特征根并轉(zhuǎn)置M=e(ones(m,1),:).^0.5;%輸出前三個特征根并轉(zhuǎn)置compmat=p3.*M;%利用特征根構(gòu)造變換矩陣per=100*eigenvalue/sum(eigenvalue);%求出成分載荷矩陣的前三列per%求出各主成分的貢獻(xiàn)率cumsum(per);%列出各主成分的累積貢獻(xiàn)率figure(1)pareto(per);%將貢獻(xiàn)率繪成直方圖t2figure(2)%輸出各省與平局距離plot(eigenvalue,'r+');
4、%繪制方差貢獻(xiàn)散點(diǎn)圖holdon%保持圖形plot(eigenvalue,'g-');%繪制方差貢獻(xiàn)山麓圖figure(3)%關(guān)閉圖形plot(princ(:,1),princ(:,2),'+');%繪制2維成份散點(diǎn)圖%gname%,(rowname)%標(biāo)示個別散點(diǎn)代表的省data市[st2,index]=sort(t2);%st2=flipud(st2);%index=flipud(index);%extreme=index(1);