如何在MATLAB中使用pca函数来选择有效的特性? [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我是pca的新手,经过一些研究后我发现使用pca算法我们可以选择最有效的功能。

我只想使用pca函数(在MATLAB中)选择最佳特征来将数据分类为两个类别,标签为“health”和“unhealthy”(监督分类)。

我的问题是,我应该在此函数上设置一些参数来执行此操作,还是应该自己编写代码并且pca函数没有这种兼容性?

例如,我有一个包含200行和5个功能的数据集:

1-Age 
2-Weight
3-Tall
4-Skin Color
5-Eye color 

并希望使用“pca”函数来查找有效的功能(作为示例):

1-Age
3-Tall 
5-Eye Color

分类数据(2个类别,标签为“健康”和“不健康”)。

matlab classification pca feature-selection supervised-learning
1个回答
1
投票
% remove labels
features=AllMyData(:,1:end-1);

% get dimensions
[m,n] = size(features);

%# Remove the mean
features = features - repmat(mean(features,2), 1, size(features,2));

%# Compute the SVD
[U,S,V] = svd(features);

%# Compute the number of eigenvectors representing
%#  the 95% of the variation
coverage = cumsum(diag(S));
coverage = coverage ./ max(coverage);
[~, nEig] = max(coverage > 0.95);

%# Compute the norms of each vector in the new space
norms = zeros(n,1);
for i = 1:n
  norms(i) = norm(V(i,1:nEig))^2;
end

[~, idx] = sort(norms);
idx(1:n)'
© www.soinside.com 2019 - 2024. All rights reserved.