How to implement SVM with linear kernel function?

1 Ansicht (letzte 30 Tage)
D Aghor
D Aghor am 10 Dez. 2018
Kommentiert: D Aghor am 5 Nov. 2024
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?

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by