making a working classifier image program, getting errors and unsure if its correct, please help

1 visualizzazione (ultimi 30 giorni)
hello, I am a novice matlab user and I am working on making a code that is able to classify images into three different classes.
From what i understand i have to train this classifier to do this, but I am not sure how to train the classifier, can someone help me with this please? Here is what i have so far:
% Load the image data and labels
load('image_data.mat');
load('labels.mat');
% Split the data into training and testing sets
[train_data,test_data,train_labels,test_labels] = ...
crossvalind('HoldOut', labels, 0.3);
% Define the SVM classifier
svm_classifier = fitcecoc(train_data, train_labels);
% Predict the labels for the testing set using the SVM classifier
predicted_labels = predict(svm_classifier, test_data);
% Calculate the accuracy of the classifier
accuracy = sum(predicted_labels == test_labels) / numel(test_labels);
% Display the accuracy of the classifier
disp(['The accuracy of the classifier is: ', num2str(accuracy)]);
But where in the code am I supposed to train the classifer with the features that I have measured from previous images so I can use those features to predict the class of future images. how can I train what i have so far (above) and then get it to spit out the classification for the future images after their features have been measured and classified as belonging to one of the groups of the previous images? Thanks and i hope to contribute to this forum one day.
  1 Commento
Ran Yang
Ran Yang il 11 Apr 2023
You said you're getting errors, what are they? The training step occurs when you call fitcecoc, and your model is stored in svm_classifier. The classification occurs on the next line. For each entry in test_data, the predicted class using the model you just trained is stored in predicted_labels. To update (i.e. retrain) your model, you need to update train_data and train_labels and fit the model again.

Accedi per commentare.

Risposte (1)

Cris LaPierre
Cris LaPierre il 11 Apr 2023
You might be interested in our Machine Learning for Computer Vision course, part of our Computer Vision for Engnineering and Science specialization. You can enroll for free and go at your own pace. You'll find helpful examples and excercises to show you how to classify images.

Community Treasure Hunt

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

Start Hunting!

Translated by