【问题标题】:The pooled covariance matrix of TRAINING must be positive definiteTRAINING 的合并协方差矩阵必须是正定的
【发布时间】:2013-07-31 04:49:27
【问题描述】:

我知道这个问题已经被问过几次了,但我找不到解决问题的方法。

我没有比观察更多的变量,而且我的矩阵中没有NAN 值。这是我的功能:

function [ind, idx_ran] = fselect(features_f, class_f, dir)

idx = linspace(1,size(features_f, 2), size(features_f, 2));

idx_ran = idx(:,randperm(size(features_f, 2)));

features_t_ran = features_f(:,idx_ran); % randomize colums

len = length(class_f);

r = randi(len, [1, round(len*0.15)]);

x = features_t_ran;
y = class_f;

xtrain = x;
ytrain = y;

xtrain(r,:) = [];
ytrain(r,:) = [];

xtest = x(r,:);
ytest = y(r,:);

f = @(xtrain, ytrain, xtest, ytest)(sum(~strcmp(ytest, classify(xtest, xtrain, ytrain))));
fs = sequentialfs(f, x, y, 'direction', dir);

ind = find(fs < 1);

end

这是我的测试和训练数据。

>> whos xtest
  Name         Size             Bytes  Class     Attributes

  xtest      524x42            176064  double              

>> whos xtrain
  Name           Size              Bytes  Class     Attributes

  xtrain      3008x42            1010688  double              

>> whos ytest
  Name         Size            Bytes  Class    Attributes

  ytest      524x1             32488  cell               

>> whos ytrain
  Name           Size             Bytes  Class    Attributes

  ytrain      3008x1             186496  cell               

>> 

这是错误,

Error using crossval>evalFun (line 465)
The function
'@(xtrain,ytrain,xtest,ytest)(sum(~strcmp(ytest,classify(xtest,xtrain,ytrain))))' generated
the following error:
The pooled covariance matrix of TRAINING must be positive definite.

Error in crossval>getFuncVal (line 482)
funResult = evalFun(funorStr,arg(:));

Error in crossval (line 324)
    funResult = getFuncVal(1, nData, cvp, data, funorStr, []);

Error in sequentialfs>callfun (line 485)
    funResult = crossval(fun,x,other_data{:},...

Error in sequentialfs (line 353)
                crit(k) = callfun(fun,x,other_data,cv,mcreps,ParOptions);

Error in fselect (line 26)
fs = sequentialfs(f, x, y, 'direction', dir);

Error in workflow_forward (line 31)
    [ind, idx_ran] = fselect(features_f, class_f, 'forward');

这是昨天的工作。 :/

【问题讨论】:

  • 如果昨天还在工作,你做了什么改变?
  • @TryHard 之前我的 x 是 3988x42 而不是 3532x42。

标签: matlab classification


【解决方案1】:

如果您检查函数classify,您会发现当程序检查从训练矩阵的 QR 分解获得的矩阵 R 的条件数时会产生错误。换句话说,它对您提供的训练矩阵不满意。它发现这个矩阵是病态的,因此任何解决方案都将是不稳定的(该函数执行矩阵求逆的等价,这将导致病态训练矩阵除以一个非常小的数)。

似乎通过缩小训练集的大小会降低稳定性。我的建议是尽可能使用更大的训练集。

编辑

您可能想知道,为什么观察值比变量多,但仍然存在病态问题。答案是不同的观察可以是彼此的线性组合。

【讨论】:

    猜你喜欢
    • 2018-08-05
    • 2013-04-02
    • 1970-01-01
    • 2018-02-18
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 2020-04-13
    相关资源
    最近更新 更多