# Evaluating MVA within Root Data Frame

**URL:** <https://root-forum.cern.ch/t/evaluating-mva-within-root-data-frame/49238>\
**Category:** TMVA\
**Tags:** rdataframe\
**Created:** [March 17, 2022, 4:17pm UTC](https://root-forum.cern.ch/t/evaluating-mva-within-root-data-frame/49238 "2022-03-17T16:17:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ceballos](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ceballos/32/28525_2.png) [@ceballos](https://root-forum.cern.ch/u/ceballos)\
**Post date:** [March 17, 2022, 4:17pm UTC](https://root-forum.cern.ch/t/evaluating-mva-within-root-data-frame/49238/1 "2022-03-17T16:17:59Z")

</div>

Hello,

I’ve tried to find some information, but I couldn’t find any actual example. I am trying to evaluate a BDT output within RDF (it could be BDT or anything). I’ve already made the training and I have the xml files. I have used TMVA, if this is important to mention.

Nevertheless, how can I evaluate the BDT output? It’s not clear to me how this could be done.

Thanks, Guillelmo

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 17, 2022, 4:28pm UTC](https://root-forum.cern.ch/t/evaluating-mva-within-root-data-frame/49238/2 "2022-03-17T16:28:44Z")

</div>

Hi @ceballos ,  
basically you need a function or functor object that takes the column values as input and returns the classification output, let’s call it `EvalBDT`. Then you can use it as:

```cpp
auto df_with_bdt_weight = df.Define("weight", EvalBDT, {"x", "y", "z"})

```

assuming `x`, `y` and `z` are your inference inputs.

TMVA has experimental interfaces to create such a functor object, probably @moneta can provide an example.

Cheers,  
Enrico

---

<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:** [March 17, 2022, 4:48pm UTC](https://root-forum.cern.ch/t/evaluating-mva-within-root-data-frame/49238/3 "2022-03-17T16:48:36Z")

</div>

Hi,  
yes we have the tutorial [tmva003\_RReader.C](https://root.cern.ch/doc/master/tmva003__RReader_8C.html) that is an example on how to evaluate a BDT using the nw TMVA RReader class and RDataFrame.

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![ceballos](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ceballos/32/28525_2.png) [@ceballos](https://root-forum.cern.ch/u/ceballos)\
**Post date:** [March 18, 2022, 11:02am UTC](https://root-forum.cern.ch/t/evaluating-mva-within-root-data-frame/49238/4 "2022-03-18T11:02:30Z")

</div>

Hi Enrico, Lorenzo,

thanks a lot for the pointers, it worked! I am using pyroot, it would probably good to have the examples, both in C++ and python, if possible. For the record, let me write below what I did, following the example suggested by Lorenzo (\*)

Thanks again, Guillelmo

(\*)

# This is different w.r.t. C++ version

```
ROOT.gInterpreter.ProcessLine('''
TMVA::Experimental::RReader model("bdt_BDTG_vbfinc_v0.weights.xml");
computeModel = TMVA::Experimental::Compute<13, float>(model);
''')

```

# This is just to make sure which variables we are using

```
variables = ROOT.model.GetVariableNames()
print(variables)

```

# This is the actual application

.Define(“bdt\_vbfinc”, ROOT.computeModel, ROOT.model.GetVariableNames())

---

<div class="post-metadata">

**Author:** ![setesami](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/setesami/32/26795_2.png) [@setesami](https://root-forum.cern.ch/u/setesami)\
**Post date:** [April 4, 2024, 7:32pm UTC](https://root-forum.cern.ch/t/evaluating-mva-within-root-data-frame/49238/5 "2024-04-04T19:32:27Z")

</div>

Hello Enrico,

I have the same issue for evaluating the MVA weight within Root dataframe. My input variables are stored as vector instead of being float. In the normal root I can pass each element of vector as float within the event loop to evaluate the MVA weight but here as we dont have visible loop over events. Is there any example for that?

Thanks  
Mohsen
