Feature selection for svm classifier

8 ビュー (過去 30 日間)
Amir Naderi
Amir Naderi 2020 年 1 月 22 日
回答済み: Ayush Aniket 2024 年 8 月 29 日
hi
i have a training data , size 380 x 88 ( 380 is the number of samples and 88 the number of features)
and its class matrix is a 380 x 1 (class -1 and class +1)
how i can selecting its best features for svm classifier ?
thank you ♥

回答 (1 件)

Ayush Aniket
Ayush Aniket 2024 年 8 月 29 日
For SVM, Sequential Feature Selection is a suitable feature selection method because it recursively adds the most important features based on the weights assigned by the Machine Learning model (SVM). These weights inherently capture the interactions between features effectively, thus using them for feature selection helps identify the most significant features.
You can use the sequentialfs function in MATLAB to implement it as shown below:
% Sample data
X = randn(380, 88); % 380 samples, 88 features
y = randi([0, 1], 380, 1) * 2 - 1; % Class labels -1 and +1
cv = cvpartition(y,"KFold",10);
myFunHandle = @(XTrain,yTrain,XTest,yTest) ...
loss(fitcsvm(XTrain,yTrain),XTest,yTest)*size(XTest,1);
% Perform sequential feature selection
opts = statset('display', 'iter'); % Display iteration information
[selectedFeatures, history] = sequentialfs(myFunHandle, X, y, 'CV',cv,'options', opts);
% Display selected features
disp('Selected Features:');
disp(find(selectedFeatures));
The function uses a custom criterion function (SVM model here) to select the features.Refer to the following documentation to read about the sequentialfs function:
After the features are selected, the final training set can be constituted using them and train a SVM model.

カテゴリ

Help Center および File ExchangeStatistics 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