【问题标题】:How to use pca function in MATLAB to select effective features? [duplicate]如何在 MATLAB 中使用 pca 函数来选择有效的特征? [复制]
【发布时间】:2019-09-17 10:48:15
【问题描述】:

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

我只是想使用 pca 函数(在 MATLAB 中)选择最佳特征,以将数据分类到标签为“健康”和“不健康”(监督分类)的两个类别。

我的问题是我应该在这个函数上设置一些参数来做到这一点还是我应该自己编写代码而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】:
% 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)'

【讨论】:

    猜你喜欢
    • 2012-10-29
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2015-08-19
    • 2014-02-05
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多