【问题标题】:Coefficients of the LDA using Matlab fitcdiscr使用 Matlab fitcdiscr 的 LDA 系数
【发布时间】:2021-02-12 02:33:24
【问题描述】:

我正在使用 Matlab 命令 fitcdiscr 来实现具有 379 个功能和 8 个类的 LDA。我想获得每个特征的全局权重,以研究它们对预测的影响。如何从 ClassificationDiscriminant 对象的 Coeffs 字段中的成对(对于每对类)系数中获取它?

【问题讨论】:

  • 什么是您的“全局权重”?特征值?
  • 嗨!我的意思是每个特征的权重(或分数),它允许我根据特征对分类的重要性对特征进行排名。我现在找到了 8x7/2=28 成对分类器(8 个类的所有组合)的权重,但我想知道是否可以以某种有意义的方式将它们组合起来,以获得 8 个分类中特征的“全局”分数类。我的推理可能是错误的,不适用于 LDA,对不起,我不是这方面的专家!提前感谢您的任何提示。
  • 我认为你在这里遗漏了一些重要的概念。 LDA 的目标是线性组合特征以获得更好区分每个类别的一些新特征!检查我的答案。

标签: matlab classification coefficients linear-discriminant


【解决方案1】:

看起来fitcdiscr 没有输出特征值或特征向量。

我不打算在这里解释什么是特征向量和特征值,因为网上有很多文档。但基本上产生的特征向量将确定最大化每个类之间距离的轴。

我写了一个最小的(受excellent article 启发)示例,输出它们:

% We load the fisheriris dataset
load fisheriris
feature = meas;   % 150x4 array
class = species; % 150x1 cell

% Extract unique class and the corresponding index for each feature.
[ucl,~,idc] = unique(class);

% Number of parameter and number of class
np = size(meas,2);
nc = length(ucl);

% Mean by class
MBC = splitapply(@mean,feature,idc);

% Compute the Within class Scatter Matrix WSM
WSM = zeros(np);
for ii = 1:nc
    FM = feature(idc==ii,:)-MBC(ii,:);
    WSM = WSM + FM.'*FM;
end
WSM

% Compute the Between class Scatter Matrix
BSM = zeros(np);
GPC = accumarray(idc,ones(size(classe)));
for ii = 1:nc
    BSM = BSM + GPC(ii)*((MBC(ii,:)-mean(feature)).'*(MBC(ii,:)-mean(feature)));
end
BSM

% Now we compute the eigenvalues and the eigenvectors
[eig_vec,eig_val] = eig(inv(WSM)*BSM)

% Compute the new feature:
new_feature = feature*eig_vec

与:

eig_vec = 

 [-0.2087 -0.0065  0.7666 -0.4924  % -> feature 1
  -0.3862 -0.5866 -0.0839  0.4417  % -> feature 2
   0.5540  0.2526 -0.0291  0.2875  % -> feature 3
   0.7074 -0.7695 -0.6359 -0.5699] % -> feature 4

% So the first new feature is a linear combination of 
% -0.2087*feature1 + -0.3862*feature2 + 0.5540*feature3 + 0.7074*feature4

eig_val = 

 [ 32.1919  % eigen value of the new feature 1
   0.2854   % eigen value of the new feature 2
   0.0000   % eigen value of the new feature 3
  -0.0000]  % eigen value of the new feature 4

在这种情况下,我们有 4 个特征,这是这 4 个特征的直方图(1 class= 1 种颜色):

如果我们想区分不同的类别,我们看到特征 3 和 4 还不错,但并不完美。

现在,在 LDA 之后,我们有了这些新功能:

我们看到几乎所有信息都收集在第一个新功能(新功能 1)中。所有其他功能都没什么用,所以只保留new feature 1 并删除另一个。我们现在有一个 1D 数据集而不是 4D 数据集。

【讨论】:

  • 非常感谢,现在一切都清楚了,非常有用。因此,通过查看第一个(最具判别力的)特征向量(具有更高特征值的特征向量),我可以了解对判别贡献最大的(旧)特征(在线性组合中具有更高“权重”的特征)。
  • 没错!但是请注意,在实际情况下,您通常会保留多个特征向量(如果我们有多个特征向量具有很大的关联特征值)。如果您使用eig_vec*diag(eig_val),您将获得对“功能相对重要程度”的良好估计。
猜你喜欢
  • 2017-05-05
  • 2014-05-20
  • 2021-09-19
  • 1970-01-01
  • 2013-01-31
  • 2018-04-05
  • 2017-11-29
  • 2013-12-20
  • 2021-09-06
相关资源
最近更新 更多