# RDataFrame and TMVA in pyroot

**URL:** <https://root-forum.cern.ch/t/rdataframe-and-tmva-in-pyroot/38930>\
**Category:** Newbie\
**Tags:** python, rdataframe, tmva\
**Created:** [April 16, 2020, 7:54pm UTC](https://root-forum.cern.ch/t/rdataframe-and-tmva-in-pyroot/38930 "2020-04-16T19:54:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dertexaner](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dertexaner/32/21605_2.png) [@dertexaner](https://root-forum.cern.ch/u/dertexaner)\
**Post date:** [April 16, 2020, 7:54pm UTC](https://root-forum.cern.ch/t/rdataframe-and-tmva-in-pyroot/38930/1 "2020-04-16T19:54:25Z")

</div>

Dear experts,

I was wondering if you could provide a pyROOT implementation of the experimental RReader example provided in [RDataFrame & TMVA](https://root-forum.cern.ch/t/rdataframe-tmva/37709).

In particular, it is not clear to me how to pythonize the Define command in [https://github.com/root-project/root/blob/master/tutorials/tmva/tmva003\_RReader.C#L82-L86](https://github.com/root-project/root/blob/master/tutorials/tmva/tmva003_RReader.C#L82-L86)

Thanks!

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [April 17, 2020, 8:46am UTC](https://root-forum.cern.ch/t/rdataframe-and-tmva-in-pyroot/38930/2 "2020-04-17T08:46:12Z")

</div>

@swunsch @etejedor Can you help?

---

<div class="post-metadata">

**Author:** ![swunsch](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/50afbb/32.png) [@swunsch](https://root-forum.cern.ch/u/swunsch)\
**Post date:** [April 17, 2020, 8:52am UTC](https://root-forum.cern.ch/t/rdataframe-and-tmva-in-pyroot/38930/3 "2020-04-17T08:52:25Z")

</div>

Hi!

Happy to see that you found the new feature 🙂 Though the disclaimer comes first: You are on experimental terrain!

Now the solution to your issue. Unfortunately, PyROOT (so the Python bindings for C++) are not (yet) able to parse the template we use in C++ (see [here](https://root.cern/doc/master/namespaceTMVA_1_1Experimental.html#a1ff0a536f0ce7697e41b15d0b4197321)). However, you can play a little trick to make it still working in Python! Because PyROOT sees all objects created by the C++ interpreter cling, you can just make a call in C++. Please note that the snipplet assumes that you have run the tutorial `tmva103_RReader.C` before:

```python
import ROOT

ROOT.gInterpreter.ProcessLine('''
TMVA::Experimental::RReader model("tmva003_BDT/weights/tmva003_BDT.weights.xml");
computeModel = TMVA::Experimental::Compute<4, float>(model);
''')

df = ROOT.RDataFrame('TreeS', 'http://root.cern.ch/files/tmva_class_example.root')
df = df.Define('y', ROOT.computeModel, ROOT.model.GetVariableNames())
h = df.Histo1D('y')

h.Draw()

```

Best  
Stefan

---

<div class="post-metadata">

**Author:** ![dan\_m](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/a8b319/32.png) [@dan\_m](https://root-forum.cern.ch/u/dan_m)\
**Post date:** [April 21, 2020, 4:50pm UTC](https://root-forum.cern.ch/t/rdataframe-and-tmva-in-pyroot/38930/5 "2020-04-21T16:50:13Z")

</div>

Hi Stefan,

This thread proved very helpful indeed. However, I have a related question and was not sure if I should open a new thread, so I shall reply here.

I tried this same approach, and if I understand correctly this particular example works with the tutorial `tmva103_RReader.C` where we use 4 floats as input. I was wondering if it is possible to use the same approach with a BDT that was trained on different data type inputs. For example, one of my inputs is a double (among other floats) and I see:

`Error in <TTreeReaderValueBase::CreateProxy()>: The branch score contains data of type double. It cannot be accessed by a TTreeReaderValue<float>`

after execution of the RDF event loop. Is there a workaround for this?

Thanks,  
Spandan

---

<div class="post-metadata">

**Author:** ![swunsch](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/50afbb/32.png) [@swunsch](https://root-forum.cern.ch/u/swunsch)\
**Post date:** [April 21, 2020, 9:08pm UTC](https://root-forum.cern.ch/t/rdataframe-and-tmva-in-pyroot/38930/6 "2020-04-21T21:08:57Z")

</div>

Hi!

Unfortunately the current implementation supports only floats. But for most models floats should be fully sufficient, so just down cast your inputs and you should be fine!

Best  
Stefan
