Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 训练的集合协方差矩阵必须是正定的_Matlab_Classification - Fatal编程技术网

Matlab 训练的集合协方差矩阵必须是正定的

Matlab 训练的集合协方差矩阵必须是正定的,matlab,classification,Matlab,Classification,我知道这个问题已经被问过好几次了,但我找不到解决问题的办法 我没有比观察值更多的变量,我的矩阵中也没有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

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

我没有比观察值更多的变量,我的矩阵中也没有
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
这里是错误

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');

这是昨天的工作/

如果您检查函数
分类
,您会发现错误是在程序检查通过训练矩阵的QR分解获得的矩阵R的条件编号时产生的。换句话说,它对您提供的培训矩阵不满意。它发现该矩阵是病态的,因此任何解都是不稳定的(该函数执行与矩阵求逆等价的操作,这将导致与病态训练矩阵的极小数除等价)

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

编辑


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

如果您检查函数
分类
,您会发现错误是在程序检查通过训练矩阵的QR分解获得的矩阵R的条件编号时产生的。换句话说,它对您提供的培训矩阵不满意。它发现该矩阵是病态的,因此任何解都是不稳定的(该函数执行与矩阵求逆等价的操作,这将导致与病态训练矩阵的极小数除等价)

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

编辑


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

如果它昨天起作用,你改变了什么?@TryHard在我的x之前是3988x42而不是3532x42。如果它昨天起作用,你改变了什么?@TryHard在我的x之前是3988x42而不是3532x42。
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');