# XGBoost Multiclass Predictions Inconsistent Between ROOT/Python

**URL:** <https://root-forum.cern.ch/t/xgboost-multiclass-predictions-inconsistent-between-root-python/56586>\
**Category:** TMVA\
**Created:** [October 3, 2023, 1:02pm UTC](https://root-forum.cern.ch/t/xgboost-multiclass-predictions-inconsistent-between-root-python/56586 "2023-10-03T13:02:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chandler\_K](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/chandler_k/32/32906_2.png) [@Chandler\_K](https://root-forum.cern.ch/u/Chandler_K)\
**Post date:** [October 3, 2023, 1:02pm UTC](https://root-forum.cern.ch/t/xgboost-multiclass-predictions-inconsistent-between-root-python/56586/1 "2023-10-03T13:02:02Z")

</div>

I have trained an `XGBClassifier()` in Python. It is a multi-class classifier and is defined as:

```auto
model = XGBClassifier(
    max_depth=7,
    reg_alpha=2,
    reg_lambda=4,
    gamma=0.1,
    objective='multi:softprob',
    num_class=4,
    learning_rate=0.1,
    n_estimators=100,
    eval_metric=['mlogloss'],
    missing=99999.0,
    early_stopping_rounds=10, 
    seed=0,
    nthread=8
)

```

However, when I then save this model to .root format via `ROOT.TMVA.Experimental.SaveXGBoost(model, MODEL_NAME, f"{PATH_TO_MODEL[:-5]}.root", num_inputs=N_FEATURES)` then I write a simple ROOT script that prints the predictions of this model they are inconsistent with my Python model. For a random sample from the training data I find:

Python predictions = [0.98837775, 0.00120619, 0.00707766, 0.00333839]  
ROOT Predictions = [0.89028, 0.032496, 0.0263328, 0.0508909]

(The training sample is the same - I have even printed out the numpy array and copied and pasted it into my ROOT script).

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 3, 2023, 1:06pm UTC](https://root-forum.cern.ch/t/xgboost-multiclass-predictions-inconsistent-between-root-python/56586/2 "2023-10-03T13:06:12Z")

</div>

Maybe @moneta will be able to help once he’s back in a couple of days

---

<div class="post-metadata">

**Author:** ![Chandler\_K](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/chandler_k/32/32906_2.png) [@Chandler\_K](https://root-forum.cern.ch/u/Chandler_K)\
**Post date:** [October 3, 2023, 1:47pm UTC](https://root-forum.cern.ch/t/xgboost-multiclass-predictions-inconsistent-between-root-python/56586/3 "2023-10-03T13:47:28Z")

</div>

So I think I have found the solution to the problem. The “missing” parameter is not supported either during the encoding in `SaveXGBoost` or in the `TMVA::Experimental::RBDT<>`. If you re-train the model with the missing parameter removed (in Python) the ROOT model generates the same predictions.

Caveat being of course that the `missing` parameter does aid in training the models. Maybe this feature should be added/supported?
