How to implement SVM with linear kernel function?

11 visualizzazioni (ultimi 30 giorni)
D Aghor
D Aghor il 10 Dic 2018
Commentato: D Aghor il 5 Nov 2024 alle 7:56
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?

Risposta accettata

Akshat
Akshat il 5 Nov 2024 alle 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.

Più risposte (0)

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by