You must pass X as a floating-point matrix.

조회 수: 15(최근 30일)
Warid Islam
Warid Islam 2021년 1월 6일
댓글: Warid Islam 2021년 1월 8일
I am building a GUI to classify breast images. I am using SVM as the classifier technique. However, I am getting an error message. Please find my code an the error message below. Any help would be appreciated.
Labels = table2array(File);
SVMmodel= fitcsvm(Training, class, 'KernelFunction', 'Linear', 'Standardize', true, 'ClassNames', {'1', '2'});
result = predict(SVMmodel, TestSet);
The error message is displayed below:
Error using classreg.learning.impl.CompactSVMImpl/score (line 45)
You must pass X as a floating-point matrix.
Error in classreg.learning.classif.CompactClassificationSVM/score (line 591)
f = score(this.Impl,X,true,varargin{:});
Error in classreg.learning.classif.ClassificationModel/predict (line 411)
scores = score(this,X,varargin{:});
Error in classreg.learning.classif.CompactClassificationSVM/predict (line 433)
Error in new>pushbutton4_Callback (line 143)
result = predict(SVMmodel, TestSet);
Error in gui_mainfcn (line 95)
Error in new (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in>@(hObject,eventdata)new('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  댓글 수: 1
Athrey Ranjith Krishnanunni
Athrey Ranjith Krishnanunni 2021년 1월 6일
From the documentation for predict, it says that the syntax is
where X is the predictor data, and should be a numeric array.
In your case, X is TestSet, so try running
in the command line to see what comes up under the Size and Class headings.

댓글을 달려면 로그인하십시오.

채택된 답변

Ive J
Ive J 2021년 1월 6일
Your TestSet must have the same structure as your Training set. You can try this
result = predict(SVMmodel, Labels(:, 1:9));
  댓글 수: 3
Warid Islam
Warid Islam 2021년 1월 8일
Hi Walter,
Your suggestions worked big time. Thank you.
Best Regards
Warid Islam

댓글을 달려면 로그인하십시오.

추가 답변(0개)




Community Treasure Hunt

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

Start Hunting!

Translated by