yandex / rep

Machine Learning toolbox for Humans
http://yandex.github.io/rep/
Other
687 stars 144 forks source link

Changes to TMVA API in new ROOT versions break TMVAClassifier #105

Open fndari opened 7 years ago

fndari commented 7 years ago

Hi all,

first of all, I wanted to thank and compliment the developers for this brilliant library. I finally had the chance to start playing with it today, but I was stopped in my tracks when trying to use a TMVAClassifier:

AssertionError: ERROR: TMVA process is incorrect finished 
 LOG: None 
 Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/ludo/miniconda3/envs/pyroot/lib/python2.7/site-packages/rep/estimators/_tmvaFactory.py", line 86, in main
    tmva_process(classifier, info, data, labels, sample_weight)
  File "/home/ludo/miniconda3/envs/pyroot/lib/python2.7/site-packages/rep/estimators/_tmvaFactory.py", line 40, in tmva_process
    factory.AddVariable(var)
AttributeError: 'Factory' object has no attribute 'AddVariable'

My ROOT/TMVA versions are:

You are running ROOT Version: 6.08/00, Nov 4, 2016
TMVA Version 4.2.1, Feb 5, 2015

Searching the web for this error message led me to this post on the ROOT forum: https://root-forum.cern.ch/t/25090, where the cause of problem is indicated as being due to a breaking change in the TMVA API:

In recent ROOT versions (6.06 or 6.08, don't remember exactly), the TMVA interface has changed. You need to create a TMVA::DataLoader and call AddVariable on the dataloader object.

As I understand, this is related to what was mentioned by @gandreassi in a comment to #104. Any idea on how complicated it would be to adapt tmva_process to the new interface?

gandreassi commented 7 years ago

Hi Ludovico,

this seems indeed the same problem that I encountered. What I did to solve it is pretty simple: it consisted of modifying rep/estimators/_tmvaFactory.py You need to adapt this to the new syntax of TMVA, which requires to create a DataLoader object and to use it in place of the factory itself in some places. An example that I found on how to use the dataloader is available here: https://root.cern/doc/master/TMVACrossValidation_8C.html

As I wrote in the thread that you quoted, I'd be happy to push my fix in a branch if the developers agree.