how to use multisvm
Show older comments
i want to use svm classifier for 4 class classification, and want to know how can i use svm for multiclass
Answers (1)
Purvaja
on 3 Feb 2025
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!!
Categories
Find more on Discriminant Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!