bug in fitcecoc() help --> predict function error

3 次查看(过去 30 天)
entering in order, the command:
[~,~,~,PosteriorRegion] = predict(Mdl,[x1Grid(:),x2Grid(:)]);
generates an error:
>> main2a1
Error using classreg.learning.impl.CompactSVMImpl/score (line 62)
You must pass X as a matrix with 4 columns.
Error in classreg.learning.classif.CompactClassificationSVM/score (line 424)
f = score(this.Impl,X,true,varargin{:});
Error in classreg.learning.classif.ClassificationModel/predict (line 410)
scores = score(this,X,varargin{:});
Error in classreg.learning.classif.CompactClassificationSVM/predict (line 266)
predict@classreg.learning.classif.ClassificationModel(this,X,varargin{:});
Error in classreg.learning.classif.CompactClassificationECOC>localScore/loopBody (line 922)
[~,s] = predict(trained{l},X,predictArgs{:});
Error in internal.stats.parallel.smartForSliceout (line 174)
[slice{:}] = loopbody(iter, S);
Error in classreg.learning.classif.CompactClassificationECOC>localScore (line 886)
internal.stats.parallel.smartForSliceout(T,@loopBody,useParallel);
Error in classreg.learning.classif.CompactClassificationECOC/score (line 184)
pscore = localScore(X,trained,useParallel,verbose,this.ObservationsInRows);
Error in classreg.learning.classif.CompactClassificationECOC/predict (line 366)
[negloss,pscore] = score(...
Error in main2a1 (line 6)
[~,~,~,PosteriorRegion] = predict(Mdl,[x1Grid(:),x2Grid(:)]);
>>
  4 个评论
Ravi Singh
Ravi Singh 2020-3-24
Hi Walter ,
I need to know if i can generate one svm model(mdl.mat) file and use it for different data several times. I had generated one file and tried using it with different data having same feature but i got error stating it does not have same number of columns.
Walter Roberson
Walter Roberson 2020-3-25
The number of columns of data processed through predict() must be the same as the number of columns of data trained on.
If the different data has matching columns plus extra columns, then extract the corresponding columns to pass to predict()

请先登录,再进行评论。

回答(1 个)

Nicolas Schmit
Nicolas Schmit 2017-9-20
main2a1 Error using classreg.learning.impl.CompactSVMImpl/score (line 62) You must pass X as a matrix with 4 columns.
-> Check the number of columns of the matrix X when using predict(Mdl, X);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by