• 大小: 2KB
    文件类型: .m
    金币: 2
    下载: 0 次
    发布日期: 2024-02-03
  • 语言: Matlab
  • 标签:

资源简介

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);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%

评论

共有 条评论

相关资源