How to implement SVM with linear kernel function?

조회 수: 11 (최근 30일)
D Aghor
D Aghor 2018년 12월 10일
댓글: D Aghor 2024년 11월 5일 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?

채택된 답변

Akshat
Akshat 2024년 11월 5일 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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by