Evaluating MVA within Root Data Frame

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

1 Like

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:

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

Hi,
yes we have the tutorial tmva003_RReader.C that is an example on how to evaluate a BDT using the nw TMVA RReader class and RDataFrame.

Cheers

Lorenzo

1 Like

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())