Shapley based feature selection

10 ビュー (過去 30 日間)
MB
MB 2025 年 3 月 1 日
編集済み: MB 2025 年 3 月 11 日
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 件のコメント
MB
MB 2025 年 3 月 2 日
Sorry for the late reply. I’ve just uploaded the data.
MB
MB 2025 年 3 月 11 日
編集済み: MB 2025 年 3 月 11 日
I found a Python example that can help: Python Example.

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2025 年 3 月 2 日
The Shapley values don't require the class labels (i.e. the actual responses) to determine feature importance.
The Shapley values only indicate, for a given model, how much each feature affects the predicted class label. For example, suppose you are trying to predict whether someone is going to repay their car loan on time. For borrower Alice, the model might predict "NO", because she already has a lot of debt. For borrower Bob, the model might also predict "NO", but because Bob has low income (even if he has low debt).
The Shapley values of debt and income will be different for Alice and Bob. It does not matter whether they actually default or not. The Shapley value is explaining only where the prediction came from.
I hope that helps.
  1 件のコメント
MB
MB 2025 年 3 月 2 日

Thank you both.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2025 年 3 月 2 日
編集済み: Walter Roberson 2025 年 3 月 2 日
YtestPred = predict(Mdl, Xtest);
test_accuracy = nnz(Ytest(:) == YtestPred(:)) / numel(Ytest) * 100;
fprintf('test accuracy: %.2f\n', test_accuracy);

カテゴリ

Help Center および File ExchangeMATLAB Mobile についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by