Can I calculate SHAP values on a CatBoost model fit using monotone constraints set to "-1"?

919 views Asked by At

I fit a CatBoostClassifier model (in Python) with the argument monotone_constraints set to a dictionary with values equaling "-1".

However, when I attempt to calculate SHAP values:

df_shap_vals = model.get_feature_importance(data=X_pooled,
                                            type='ShapValues',
                                            prettified=False,
                                            thread_count=-1,
                                            verbose=False)

I get the error:

CatBoostError: c:/program files (x86)/go agent/pipelines/buildmaster/catboost.git/catboost/libs/fstr/shap_values.cpp:810: Cannot calc shap values, model contains non zero approx for zero-weight leaf

Note: I have previously been able to calculate SHAP values using the code above when I did not set the monotone_constraints argument.

1

There are 1 answers

0
Chuci Chen On BEST ANSWER

I also had the same issue using the old catboost version.

In version 0.24.4, the underlying issue has been fixed, hence my suggestion is to try the mentioned version out.