I see that you wish to classify multiple classes using SVM. We can achieve this using “ClassificationECOC” function. You can perform the following steps:
- Assume some data with 4 classes for prediction
- Combine the classes into a single dataset
data = [class1; class2; class3; class4];
X = data(:, 1:2); % Features
Y = data(:, 3); % Labels
- Train the SVM model using fitcecoc
svmModel = fitcecoc(X, Y);
- Display the trained model
disp(svmModel);
- Make predictions on the training data
predictions = predict(svmModel, X);
- Calculate accuracy
accuracy = sum(predictions == Y) / length(Y) * 100;
fprintf('Accuracy: %.2f%%\n', accuracy);
- Get predictions for some points
Predictions = predict(svmModel, Points);
You can check another example by simply typing this command in your MATLAB command window:
openExample('stats/TrainAnECOCClassifierUsingSVMLearnersExample')
For more clarification details on the functions used, you can refer “ClassificationECOC”, check out the following in documentation:
Hope this helps you!!
