How to calculate Shapley Values
    6 views (last 30 days)
  
       Show older comments
    
Hi I'm trying to calculate shapley values by creating a model and specifying a query point.
I have a 100x5 array (samplealpha...) of predictor data and a corresponding 100x1 vector (imaxnum) of response variables.
This is my code so far:
responsevar=imaxnum;
% responsevar=imaxday;
% responsevar=rec;
% responsevar=dead;
array=[samplealpha;samplebeta;sampledelta;samplekappa;sampleTi;responsevar]';
% table=array2table(array);
model=fitrkernel(array(:,1:5),array(:,6));
a=shapley(model,array(:,1:5));
queryPoint=array(1,:);
b=fit(a,queryPoint);
plot(b)
This is the error message I'm getting: 
Error using shapley/fit (line 400)
Unable to predict using the blackbox model for the specified 'QueryPoint' value.
Error in seirdshapley (line 88)
b=fit(a,queryPoint);
Caused by:
    Error using classreg.learning.internal.numPredictorsCheck (line 29)
    X data must have 5 column(s).
Please help thanks!!
0 Comments
Answers (1)
  Star Strider
      
      
 on 16 Nov 2021
        However, one possible problem is that ‘array’ is not a (100x5) array and is instead a (1x500) vector (after the transposition).  I have no idea what the components of ‘array’ are, however the semicolon (;) operator will vertically concatenate them, not horizontally concatenate them.  That requires a comma (,) delimiter.    
array=[samplealpha;samplebeta;sampledelta;samplekappa;sampleTi;responsevar]';
If I guessed in error and ‘array’ actually is a (100x5) matrix, I’ll delete this Answer.  
What size is ‘array’?  
.
2 Comments
  Star Strider
      
      
 on 16 Nov 2021
				Then something else is wrong, and I would have to be able to have ‘array’ to work with, to see what the problem is with it.  The code otherwise clearly works — 
array = randn(10,6);                                % Normally-Distributed Random Variable Array To Use Default 'fitkernel' Assumptions
model=fitrkernel(array(:,1:5),array(:,6));
a=shapley(model,array(:,1:5))
a.BlackboxModel
.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
