Join us on Wednesday, June 3rd for a deep dive into Customer Predictive Analytics Learn more

DkuXGBRegressor to XGBRegressor

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
2 Replies
Dataiker
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
...


 

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