You must pass X as a floating-point matrix.

4 visualizaciones (últimos 30 días)
Warid Islam
Warid Islam el 6 de En. de 2021
Comentada: Warid Islam el 8 de En. de 2021
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.
File=handles.File;
InputImage=handles.InputImage;
TestSet=InputImage;
Labels = table2array(File);
Training=Labels(1:2004,1:9);
class=Labels(:,10);
SVMmodel= fitcsvm(Training, class, 'KernelFunction', 'Linear', 'Standardize', true, 'ClassNames', {'1', '2'});
result = predict(SVMmodel, TestSet);
result=num2str(result);
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)
predict@classreg.learning.classif.ClassificationModel(this,X,varargin{:});
Error in new>pushbutton4_Callback (line 143)
result = predict(SVMmodel, TestSet);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in new (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)new('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  1 comentario
Athrey Ranjith Krishnanunni
Athrey Ranjith Krishnanunni el 6 de En. de 2021
From the documentation for predict, it says that the syntax is
predict(Mdl,X)
where X is the predictor data, and should be a numeric array.
In your case, X is TestSet, so try running
whos('TestSet')
in the command line to see what comes up under the Size and Class headings.

Iniciar sesión para comentar.

Respuesta aceptada

Ive J
Ive J el 6 de En. de 2021
Your TestSet must have the same structure as your Training set. You can try this
result = predict(SVMmodel, Labels(:, 1:9));
  3 comentarios
Walter Roberson
Walter Roberson el 7 de En. de 2021
The return value from predict is labels in the same format as they were input to ficsvm. Your two labels are {'1', '2'} so you get a cell array of labels returned.
Consider changing the {'1', '2'} to be {'Malignant', 'Benign'} and then you would not have to do the if .
Warid Islam
Warid Islam el 8 de En. de 2021
Hi Walter,
Your suggestions worked big time. Thank you.
Best Regards
Warid Islam

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by