Reference to non-existent field 'predictFcn'.
3 次查看(过去 30 天)
显示 更早的评论
I'm going to predict a new data using a SVM classification model which I created using the classification learner apps. After I export the model into workspace, I save the model into .mat file using command
save('trainedClassifier')
because I want to use the model to predict new data in my GUIDE program. And here is the code I use to predict new data using the model
Img = handles.Abu;
[m,n,~] = size(Img);
axes(handles.axes1)
cla reset
set(gca,'XTick',[])
set(gca,'YTick',[])
imshow(Img);
%Below is the code I use to create mask to determine ROI of the image
h = imrect(gca, [10 10 750 750]);
setResizable(h,false)
wait(h);
mask = createMask(h);
%Below is the code I used to extract feature
Mean = mean2(Img(mask));
Std = std2(Img(mask));
Variance = var (double(Img(mask)));
Kurtosis = kurtosis(double(Img(mask)));
%Below is the I use to predict new data
T = table(Mean, Std, Variance, Kurtosis);
trainedClassifier = load('trainedClassifier.mat');
yfit = trainedClassifier.predictFcn(T);
%Below is the code I use to display the result into edit text
set(handles.edit1, 'String', Mean);
set(handles.edit2, 'String', Std);
set(handles.edit3, 'String', Variance);
set(handles.edit4, 'String', Kurtosis);
set(handles.edit5, 'String', yfit);
but I'm getting error Reference to non-existent field 'predictFcn'. How to fix this problem ? Is it possible to use a model which created from the Classification Learner apps in a GUIDE program ?
1 个评论
Jahnavi Samal
2023-1-23
For me too getting the same error. Could u plz tell me how did u resolve it?
回答(1 个)
Jahnavi Samal
2023-1-25
编辑:Jahnavi Samal
2023-1-25
While saving the training model from classificationLearner app the model gets imported into the workspace with a variable name. Use that variable name with predictFcn after loading the saved trainedmodel .mat file It worked for me.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Classification Learner App 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!