How to calculate Shapley Values

조회 수: 8 (최근 30일)
Shaun Tan
Shaun Tan 2021년 11월 16일
댓글: Star Strider 2021년 11월 16일
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!!

답변 (1개)

Star Strider
Star Strider 2021년 11월 16일
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
Shaun Tan
Shaun Tan 2021년 11월 16일
Hi,
'array' is a 100x5 matrix
Thanks
Star Strider
Star Strider 2021년 11월 16일
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
.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Support Vector Machine Regression에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by