How to use Shapley function for an already fitted regression model?

8 ビュー (過去 30 日間)
Ahmed Elkady
Ahmed Elkady 2022 年 11 月 27 日
編集済み: Drew 2023 年 4 月 18 日
Say, I have a regression model:
Y = 1.5 * (V1)^3 * (V2)^-5 * (V2)^10.3
where, V1, V2 and V3 are the model features/predictors and Y is the dependant variable.
I also have the data used to fit/train that model, say "Data" which is a 100x3 matrix
How can I use the Shapley function in that case? since as I understand this function can only be used on model objects generated by the Statistics and Machine Learning Toolbox.

回答 (2 件)

Drew
Drew 2023 年 4 月 18 日
編集済み: Drew 2023 年 4 月 18 日
You can calculate Shapley values for an arbitrary model by specifying the model prediction function with a function handle, and passing that function handle to the MATLAB shapley function. See the example "Specify Blackbox Model Using Function Handle" on the shapley doc page

the cyclist
the cyclist 2022 年 12 月 1 日
To my knowledge, there is no way to use MATLAB's shapley function other than with a blackbox model object as the input. The possible input types are in the documentation here.
It is unclear to me how you have the pre-existing regression fit, without the MATLAB object. It seems to me that the simplest thing to do would be to simply replicate the fit in MATLAB. That seems straightforward, but perhaps you have reasons not to do that. [I'm guessing that you don't have the ML & Stats Toolbox for doing the fitting, but then you also don't have access to the shapley() function.]
A second possiblity would be for you to search the File Exchange for user-contributed functions that calculate Shapley values.
A third -- and admittedly annoying -- possibility would be for you to code the Shapley value from scratch. The formula is in the documentation here, and of course elsewhere.
  1 件のコメント
Ahmed Elkady
Ahmed Elkady 2022 年 12 月 2 日
Thank you for the response. I believe there must be a workaround to transform an already fitted model into a "black box model" object. There is a similar thread on the topic (see below) but I'm not sure how to apply it to my case
Also, to answer your suggestion, I can't replicate the fit in Matlab ML toolbox cause the model has been fitted using a bespoke hybrid methodology.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by