AttributeError: 'XGBTreeModelLoader' object has no attribute 'base_score'

using xgboost (2.0.3) and shap (0.45), I get the following error trace. Am stuck on how to resolve. Any suggestions welcome:


AttributeError Traceback (most recent call last)
Cell In[32], line 2
1 # Create the SHAP explainer with the model
----> 2 explainer = shap.TreeExplainer(fit_xgb)
4 # Compute SHAP values for the training set
5 shap_values = explainer.shap_values(preprocessed_data)

File c:\n\venv\Lib\site-packages\shap\explainers_tree.py:195, in TreeExplainer.init(self, model, data, model_output, feature_perturbation, feature_names, approximate, link, linearize_link)
193 self.feature_perturbation = feature_perturbation
194 self.expected_value = None
–> 195 self.model = TreeEnsemble(model, self.data, self.data_missing, model_output)
196 self.model_output = model_output
197 #self.model_output = self.model.model_output # this allows the TreeEnsemble to translate model outputs types by how it loads the model

File c:\n\venv\Lib\site-packages\shap\explainers_tree.py:1063, in TreeEnsemble.init(self, model, data, data_missing, model_output)
1061 elif safe_isinstance(model, “xgboost.core.Booster”):
1062 self.original_model = model
-> 1063 self._set_xgboost_model_attributes(
1064 data,
1065 data_missing,
1066 objective_name_map,
1067 tree_output_name_map,
1068 )
1069 elif safe_isinstance(model, “xgboost.sklearn.XGBClassifier”):

-> 1873 self.base_score = np.log(self.base_score)
1874 else:
1875 self.base_score = base_score

AttributeError: ‘XGBTreeModelLoader’ object has no attribute ‘base_score’

1 Like

Please file a bug report at https://github.com/shap/shap/issues, since the issue seems to be coming from the shap package.

I am getting the same error message starting this Monday 3/11/2024. I am getting this error when I use objective=‘reg:tweedie’.