'Factory' object has no attribute 'AddVariable' : in TMVA - python

When I try running TMVAClassification.py given in TMVA package I get the following output:

Traceback (most recent call last):
  File "TMVAClassification.py", line 424, in <module>
  File "TMVAClassification.py", line 153, in main
    factory.AddVariable( "myvar1 := var1+var2", 'F' )
AttributeError: 'Factory' object has no attribute 'AddVariable'

Can anyone help me?

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.

1 Like

Thank for reminding that.

I have attached working code if anyone needs.

TMVAClassification.py (22.1 KB)
tmva_class_example.root (201.9 KB)


Just a bit of user feedback: Completely changing the interface in such a disruptive way creates a lot of work downstream. We have code that has to live in ROOT 6.06 and (with new data) in 6.08. In 6.06 there is not even yet a DataLoader class (afaict). The 6.08 release note (“New DataLoader class that allows flexibility in variable and dataset selection.”) does not indicate that this change is embedded in a complete change in interface for TMVA::Factory.

I know you know this.



Per the topic Python is used; if so, you can patch up the class in one place to allow for compatibility (and print Python warnings to catch all cases over a period of time).