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

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

Yuzhen Lu
Yuzhen Lu 2018년 10월 23일
편집: Yuzhen Lu 2018년 10월 23일
Try the code (for model training to generate Mdl):
X = meas(:,3:4);
The model has been built with 4 measurements per sample, but the prediction is trying to be done with only 2 measurements per sample.
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.
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일

0 개 추천

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

카테고리

질문:

2017년 8월 2일

댓글:

2020년 3월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by