How to implement SVM with linear kernel function?

11 views (last 30 days)
I have a dataset containing 134 features extracted for 330 ROIs cropped. I have to apply SVM for binary classification of the images followed by Sequential Minimal Optimization. How to select the training data set and test data set? Which commands should be used?

Accepted Answer

Akshat
Akshat on 5 Nov 2024 at 5:10
In order to use Sequential Minimal Optimization (SMO) for a SVM model, we can take the following steps:
  • Split of data using "cvpartition". If you partition your data into training and testing set using "cvpartition", you are enabling the data for cross validation. Find more about this on the following documentation page: https://www.mathworks.com/help/stats/cvpartition.html. The following code can be used as a boilerplate to make the partitions:
% X: data, Y: labels
cv = cvpartition(size(X, 1), 'HoldOut', 0.3);
XTrain = X(training(cv), :);
YTrain = Y(training(cv), :);
XTest = X(test(cv), :);
YTest = Y(test(cv), :);
SVMModel = fitcsvm(XTrain, YTrain, 'KernelFunction', 'linear', 'Standardize', true, 'Solver', 'SMO');
YPred = predict(SVMModel, XTest);
% Calculate the accuracy
accuracy = sum(YPred == YTest) / length(YTest);
fprintf('Test Accuracy: %.2f%%\n', accuracy * 100);
Feel free to ask any follow-ups in case you need any more help.

More Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!