Shapley based feature selection
Show older comments
Hello everyone, I am trying to perform Shapley based feature selection. I wrote the code below but I did not use the Ytest variable. Xtest does not contain the class labels; they are in the Ytest variable. I am a little confused. Am I doing something wrong? Thanks for the help.
DataSet = load('Seeds.txt');
[~,nFeatures] = size(DataSet);
X = DataSet(:,(1:nFeatures - 1));
Y = DataSet(:,nFeatures);
c = cvpartition(Y, 'Holdout', 0.20, 'Stratify', true);
Xtrain = X(training(c), :);
Xtest = X(test(c), :);
Ytrain = Y(training(c));
Ytest = Y(test(c));
Mdl = fitcecoc(Xtrain, Ytrain);
LimeRes = shapley(Mdl);
FitRes = fit(LimeRes, Xtest);
plot(FitRes)
3 Comments
the cyclist
on 1 Mar 2025
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar.
MB
on 2 Mar 2025
Accepted Answer
More Answers (1)
Walter Roberson
on 2 Mar 2025
Edited: Walter Roberson
on 2 Mar 2025
YtestPred = predict(Mdl, Xtest);
test_accuracy = nnz(Ytest(:) == YtestPred(:)) / numel(Ytest) * 100;
fprintf('test accuracy: %.2f\n', test_accuracy);
Categories
Find more on MATLAB Mobile in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!