How to calculate Shapley Values

8 Ansichten (letzte 30 Tage)
Shaun Tan
Shaun Tan am 16 Nov. 2021
Kommentiert: Star Strider am 16 Nov. 2021
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!!

Antworten (1)

Star Strider
Star Strider am 16 Nov. 2021
I had no idea that shapley even existed until now, so I have no experience with it.
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 Kommentare
Shaun Tan
Shaun Tan am 16 Nov. 2021
Hi,
'array' is a 100x5 matrix
Thanks
Star Strider
Star Strider am 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 =
shapley with properties: BlackboxModel: [1×1 RegressionKernel] QueryPoint: [] BlackboxFitted: [] ShapleyValues: [] NumSubsets: 32 X: [10×5 double] CategoricalPredictors: [] Method: 'interventional-kernel' Intercept: -0.6809
a.BlackboxModel
ans =
RegressionKernel ResponseName: 'Y' Learner: 'svm' NumExpansionDimensions: 256 KernelScale: 1 Lambda: 0.1000 BoxConstraint: 1 Epsilon: 0.0558 Properties, Methods
.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by