资源简介
pca源码(matlab)pca源码(matlab)pca源码(matlab)
代码片段和文件信息
clear
clc
%pca处理
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fid = fopen(‘E:\毕业设计\data\TrainSample.txt‘‘r‘);
[Acount]=fscanf(fid‘%d %d‘[5002000]);
fclose(fid);
%词语特征-文档矩阵 及其 协方差矩阵
A = A‘;
R_A = A‘ * A;
%求最大的特征值
d = eig(R_A);
[V D] = eig(R_A);
clear R_A;
s = sum(d);
for i=1:500
if (sum(d(500-i:500))/s > 0.85)
break;
end
end
clear s;
global W_KL;
W_KL = V(:500-i:500)‘;
clear V D;
%经pca处理后的样本
global P;
P = A*W_KL‘;
P = P‘;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%k均值聚类
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k=500;%聚类后的数目
p_cluster(:1:k) = cluster(P(:1:1000) k i+1 1000);
p_cluster(:k+1:2*k) = cluster(P(:1001:2000) k i+1 1000);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
- 上一篇:lvq学习算法源码matlab
- 下一篇:织物密度测量MATLAB实现
评论
共有 条评论