Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.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_Cross Validation - Fatal编程技术网

Matlab 使用线性判别分析的交叉验证

Matlab 使用线性判别分析的交叉验证,matlab,cross-validation,Matlab,Cross Validation,以下代码使用线性判别分析执行10倍交叉验证: load fisheriris indices = crossvalind('Kfold',species,10); cp = classperf(species); % initializes the CP object for i = 1:10 test = (indices == i); train = ~test; class = classify(meas(test),meas(train),species(train))

以下代码使用线性判别分析执行10倍交叉验证:

load fisheriris
indices = crossvalind('Kfold',species,10);
cp = classperf(species); % initializes the CP object

for i = 1:10
    test = (indices == i); train = ~test;
    class = classify(meas(test),meas(train),species(train));
    % updates the CP object with the current classification results
    classperf(cp,class,test)  
end

cp.CorrectRate

如何将其修改为使用fitcdiscr而不是第7行的分类?当我尝试时,我得到一个错误(错误的参数数量)。我不知道需要或不需要什么参数。

fitcdiscr返回一个基于训练数据的模型,并带有真正的标签。因此,为了得到预测类(class),我们需要使用模型方法进行预测

load fisheriris 
indices = crossvalind('Kfold',species,10);
cp = classperf(species);
for i = 1:10
    test = (indices == i); train = ~test;
    Mdl = fitcdiscr(meas(train,:), species(train,:));
    class = Mdl.predict(meas(test,:));
    classperf(cp,class,test);
end
cp.CorrectRate
我用旧函数(分类)对此进行了测试,正确率是相同的。

可能从:
fitcdiscr(meas,species)
当我尝试fitcdiscr(meas,species)时,我得到以下错误:使用classreg.learning.internal.DisallowVectorOps/subsref时出错(第16行)不能使用()索引将索引编入ClassificationDiscriminant类的对象。classperf(第223行)中的错误gps=varargin{1}(:);