DkuXGBRegressor to XGBRegressor
John_Kelly
Registered Posts: 16 ✭✭✭✭
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.
Tagged:
Best Answer
-
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
...
Answers
-
I was hoping it was something that simple. That seems to have done the trick, thanks!