Applying SHAP on a Reinforcement Learning Algorithm

15 vues (au cours des 30 derniers jours)
Mahsa Raeisinezhad
Mahsa Raeisinezhad le 5 Juin 2023
Commenté : Drew le 5 Mar 2025
I am trying to Apply SHAP on a reinforcement Learning Algorithm and I am not sure if MATLAB has the required SHAP packages such as shap.DeepExplainer() which is a python package.
If anyone has any further information on how to apply SHAP on the Neural Network agent of a Reinforcement Learning model, please let me know.
  6 commentaires
Mahsa Raeisinezhad
Mahsa Raeisinezhad le 25 Nov 2023
function myAct_ = predict_01(tbl, env)
obsInfo = getObservationInfo(env);
actInfo = getActionInfo(env);
agent = rlPPOAgent(obsInfo,actInfo);
actor = getActor(agent);
actorNet = getModel(actor);
% Get the i-th slice of transposedArray
dataArray = table2array(tbl);
dlObservationsF = dlarray(dataArray, 'C');
% dlObservationsF = dlarray(dataArray(i,:), 'C');
% Predict using the actor network
myAct = predict(actorNet, dlObservationsF);
myAct_ = extractdata(myAct);
myAct_ = max(myAct);
end
Mahsa Raeisinezhad
Mahsa Raeisinezhad le 25 Nov 2023
The above is how tried to use SHAP in Matlab, I created a function handle of my Neural Network (agent) predictions using the Environment and applied SHAP on each decision, but I still highly recommend transfering to Python and using Python shap packages.

Connectez-vous pour commenter.

Réponses (2)

Mahsa Raeisinezhad
Mahsa Raeisinezhad le 23 Nov 2023
I decided to transfer everything in Python and use python packages. I used ONNX and Tensorflow for transferring everything. Hopefully if I have time in the future I write my own code to create same outcomes in Matlab.
  1 commentaire
Drew
Drew le 5 Mar 2025
Starting in R2024a, MATLAB has new functionality to more easily create shapley summary plots. This is described in the release notes https://www.mathworks.com/help/releases/R2024a/stats/release-notes.html.
To see an example on MATLAB answers, see:

Connectez-vous pour commenter.


Ive J
Ive J le 23 Nov 2023
Document and refs are clear enough if you're aware enough what your intentions are. Follow this example if you're interested to still stick to MATLAB.

Community Treasure Hunt

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

Start Hunting!

Translated by