predict showing a error

조회 수: 1 (최근 30일)
GMurtaza
GMurtaza 2018년 2월 19일
답변: Shubham 2024년 9월 6일
classifier_svm = fitcecoc(trainingFeatures, trainingLabels,'Learners', 'svm', 'Coding', 'onevsall','ObservationsIn', 'columns','CrossVal','on','Verbos',1);
testFeatures = activations(net, TestImgs, featureLayer, 'MiniBatchSize',32);
[predictedLabels_svm,scores_svm] = predict(classifier_svm, testFeatures);
Error is
No valid system or dataset was specified.

답변 (1개)

Shubham
Shubham 2024년 9월 6일
Hi GMurtaza,
It looks like you're trying to train an SVM classifier using the fitcecoc function in MATLAB, but you're running into an error. Here are a few things to check and correct in your code:
  • There's a small typo in your fitcecoc function call. The argument should be 'Verbose' instead of 'Verbos'. This typo might be causing part of the issue.
  • Make sure that your trainingFeatures and trainingLabels are correctly formatted. Since you have 'ObservationsIn', 'columns', each column in trainingFeatures should represent a single observation. Double-check that your data is structured this way.
  • When you set 'CrossVal', 'on', the function returns a cross-validated model rather than a single model. If you want to use cross-validation, you should use kfoldPredict to make predictions, instead of predict.
Here’s how you can adjust your code:
% Train the SVM classifier with ECOC
classifier_svm = fitcecoc(trainingFeatures, trainingLabels, ...
'Learners', 'svm', ...
'Coding', 'onevsall', ...
'ObservationsIn', 'columns', ...
'Verbose', 1); % Fixed the typo
% Extract features from the test images
testFeatures = activations(net, TestImgs, featureLayer, 'MiniBatchSize', 32);
% Predict labels for the test features
[predictedLabels_svm, scores_svm] = predict(classifier_svm, testFeatures);
% If you're using cross-validation, you should use kfoldPredict like this:
% predictedLabels_svm = kfoldPredict(classifier_svm);
Additional Tips:
  • Decide if you want to use cross-validation. If you do, remember to use crossval to make a cross-validated model and then kfoldPredict for predictions.
  • Ensure that trainingFeatures, trainingLabels, and testFeatures are all in the correct format and dimensions. This will help avoid any unexpected errors.

카테고리

Help CenterFile Exchange에서 Support Vector Machine Classification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by