# What is the correct input format for xgboost trained on pandas dataframes

**URL:** <https://root-forum.cern.ch/t/what-is-the-correct-input-format-for-xgboost-trained-on-pandas-dataframes/52877>\
**Category:** TMVA\
**Created:** [December 22, 2022, 10:06pm UTC](https://root-forum.cern.ch/t/what-is-the-correct-input-format-for-xgboost-trained-on-pandas-dataframes/52877 "2022-12-22T22:06:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Marckx](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/david_marckx/32/29284_2.png) [@David\_Marckx](https://root-forum.cern.ch/u/David_Marckx)\
**Post date:** [December 22, 2022, 10:06pm UTC](https://root-forum.cern.ch/t/what-is-the-correct-input-format-for-xgboost-trained-on-pandas-dataframes/52877/1 "2022-12-22T22:06:53Z")

</div>

I am a newbie at integrating external ML libraries into TMVA. I trained a xgboost model with the sklearn wrapper and saved it:

```auto
bst = XGBClassifier(...)
bst.fit(X_train, y_train, sample_weight=weight_train_balanced) #(x and y are pandas dataframes with float or integer values in them)
ROOT.TMVA.Experimental.SaveXGBoost(bst, "XGB", "location/XGBtest.root", num_inputs=len(X_train.columns))

```

for SaveXGBoost to work I renamed the columns of my dataframes to f1,f2,… as would happen in native xgboost.

I can then acces it in my c++ framework via:

```auto
TMVA::Experimental::RBDT<> bdt("myBDT", "location/XGBtest.root");
varmap["_eventBDT"] = bdt.Compute(featurevec);

```

I however can’t figure out what input the Compute function of this bdt wants to recieve to give a prediction for one event. I followed the ROOT TMVA tmva103\_\_Application\_8C tutorial (as a new user I can’t post links), which indicates an ordered vector of the input variables is the way to go.

But this results in the following error (it seems to want one double…):  
error: cannot convert ‘std::vector\<float, std::allocator \>’ to ‘std::map\<std::\_\_cxx11::basic\_string, double\>::mapped\_type’ {aka ‘double’}

A map between "fi"s to its values doesn’t work either. Any ideas what input format would make my little bdt happy?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 5, 2023, 10:19am UTC](https://root-forum.cern.ch/t/what-is-the-correct-input-format-for-xgboost-trained-on-pandas-dataframes/52877/2 "2023-01-05T10:19:04Z")

</div>

Welcome to the ROOT forum

May be @moneta can help you.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [January 5, 2023, 4:26pm UTC](https://root-forum.cern.ch/t/what-is-the-correct-input-format-for-xgboost-trained-on-pandas-dataframes/52877/3 "2023-01-05T16:26:05Z")

</div>

Hi,

Apologies for the late reply. If you are using C++ the type required by `RBDT::Compute` is a `std::vector<T>` for a single event with size equal to the number of features or an `RTensor<T>` for evaluating many events at the same time with shape `(n_events, n_features)`.  
The output is also an `std::vector` or a `RTensor` depending on which signature you use.  
See the reference [documentation](https://root.cern/doc/master/classTMVA_1_1Experimental_1_1RBDT.html).

If you are using Python you can use a Numpy array of shape `(n_events, n_features)`.

In your case it looks like you are using as output a std::map. This seems to be also the cause of the error. Do

```auto
auto varEvent = bdt.Compute(featurevec);

```

Cheers

Lorenzo
