From 3f678e903f8a6fceb44c72236c949a75a50e1f69 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Sun, 19 Oct 2025 09:29:58 +0200 Subject: [PATCH 1/2] [Python] Adapt TMVA Pythonizations to XGBoost 3.1.0 JSON format XGBoost 3.1.0 was released yesterday, and it encodes the base score now in a list and not simple number, which needs to be parsed itself. --- .../_pythonization/_tmva/_tree_inference.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tmva/_tree_inference.py b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tmva/_tree_inference.py index 00fe332467200..1568cf5b53ca1 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tmva/_tree_inference.py +++ b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tmva/_tree_inference.py @@ -20,12 +20,23 @@ def get_basescore(model): Copy-pasted from XGBoost unit test code. See also: - * https://github.com/dmlc/xgboost/blob/a99bb38bd2762e35e6a1673a0c11e09eddd8e723/python-package/xgboost/testing/updater.py#L13 + * https://github.com/dmlc/xgboost/blob/2463938/python-package/xgboost/testing/updater.py#L43 * https://github.com/dmlc/xgboost/issues/9347 * https://discuss.xgboost.ai/t/how-to-get-base-score-from-trained-booster/3192 """ - base_score = float(json.loads(model.get_booster().save_config())["learner"]["learner_model_param"]["base_score"]) - return base_score + jintercept = json.loads(model.get_booster().save_config())["learner"]["learner_model_param"]["base_score"] + out = json.loads(jintercept) + if isinstance(out, float): + return out + # For XGBoost 3.1.0 and after, the value is itself a list. + # However, we don't support multiple base scores yet. + if len(out) > 1: + raise ValueError( + f"Model contains multiple base scores ({out}). " + "This typically occurs with XGBoost ≥ 3.1.0, which supports multi-target base scores. " + "This function only supports a single base score. " + ) + return out[0] def SaveXGBoost(xgb_model, key_name, output_path, num_inputs): From 892bea06d467304f4ca38b414f36f86756490434 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Sun, 19 Oct 2025 11:47:32 +0200 Subject: [PATCH 2/2] [TVMA] Disable xgboost multiclassification test for xgboost>=3.1.0 This is not supported yet. --- tmva/tmva/test/rbdt_xgboost.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tmva/tmva/test/rbdt_xgboost.py b/tmva/tmva/test/rbdt_xgboost.py index a457de7f914c4..93bc31c0c9e49 100644 --- a/tmva/tmva/test/rbdt_xgboost.py +++ b/tmva/tmva/test/rbdt_xgboost.py @@ -82,6 +82,8 @@ def test_XGBMulticlass_default(self): """ Test model trained with multiclass XGBClassifier. """ + if xgboost.__version__ >= "3.1.0": + self.skipTest("We don't support multiclassification with xgboost>=3.1.0 yet") _test_XGBMulticlass("default") def test_XGBRegression_default(self):