DkuXGBRegressor to XGBRegressor

Solved!
John_Kelly
Level 2
DkuXGBRegressor to XGBRegressor

Is there a simple way to convert a DkuXGBRegressor instance to an XGBRegressor instance?



I'm trying to use the model in SHAP (https://shap.readthedocs.io/en/latest/#), but of course get the error: Model type not yet supported by TreeExplainer: <class 'dataiku.doctor.prediction.dku_xgboost.DkuXGBRegressor'>.



The XGBRegressor model is supported in SHAP, though.

0 Kudos
1 Solution
Samuel_R_
Dataiker

Hello, this happens because the SHAP library tests against the name of the class (see here: https://github.com/slundberg/shap/blob/master/shap/explainers/tree.py#L510). 



To circumvent this, you can try the following:




from xgboost import XGBRegressor

# get clf as a DkuXGBRegressor
clf = ...

# cast cls as a XGBRegressor
clf.__class__ = XGBRegressor

# use SHAP with clf
...


 

View solution in original post

2 Replies
Samuel_R_
Dataiker

Hello, this happens because the SHAP library tests against the name of the class (see here: https://github.com/slundberg/shap/blob/master/shap/explainers/tree.py#L510). 



To circumvent this, you can try the following:




from xgboost import XGBRegressor

# get clf as a DkuXGBRegressor
clf = ...

# cast cls as a XGBRegressor
clf.__class__ = XGBRegressor

# use SHAP with clf
...


 

John_Kelly
Level 2
Author
I was hoping it was something that simple. That seems to have done the trick, thanks!
0 Kudos

Labels

?
Labels (2)
A banner prompting to get Dataiku