使用 Matlab fitcdiscr 的 LDA 系数

Coefficients of the LDA using Matlab fitcdiscr

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

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

我不打算在这里解释什么是特征向量和特征值,因为网上有很多文档。但基本上,生成的特征向量将确定使每个 class.

之间的距离最大化的轴

我写了一个最小的(受此 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如果要区分不同的话还是不错的class但还不够完美

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

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