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

**URL:** <https://root-forum.cern.ch/t/factory-object-has-no-attribute-addvariable-in-tmva-python/25090>\
**Category:** TMVA\
**Tags:** python\
**Created:** [June 12, 2017, 4:03am UTC](https://root-forum.cern.ch/t/factory-object-has-no-attribute-addvariable-in-tmva-python/25090 "2017-06-12T04:03:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vidya\_Sagar\_V](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/v/74df32/32.png) [@Vidya\_Sagar\_V](https://root-forum.cern.ch/u/Vidya_Sagar_V)\
**Post date:** [June 12, 2017, 4:03am UTC](https://root-forum.cern.ch/t/factory-object-has-no-attribute-addvariable-in-tmva-python/25090/1 "2017-06-12T04:03:29Z")

</div>

When I try running [TMVAClassification.py](http://TMVAClassification.py) given in TMVA package I get the following output:

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

```

Can anyone help me?

---

<div class="post-metadata">

**Author:** ![behrenhoff](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/behrenhoff/32/12285_2.png) [@behrenhoff](https://root-forum.cern.ch/u/behrenhoff)\
**Post date:** [June 12, 2017, 7:24am UTC](https://root-forum.cern.ch/t/factory-object-has-no-attribute-addvariable-in-tmva-python/25090/2 "2017-06-12T07:24:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Vidya\_Sagar\_V](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/v/74df32/32.png) [@Vidya\_Sagar\_V](https://root-forum.cern.ch/u/Vidya_Sagar_V)\
**Post date:** [June 13, 2017, 10:05am UTC](https://root-forum.cern.ch/t/factory-object-has-no-attribute-addvariable-in-tmva-python/25090/3 "2017-06-13T10:05:50Z")

</div>

Thank for reminding that.

I have attached working code if anyone needs.

[TMVAClassification.py](https://root-forum.cern.ch/uploads/default/original/2X/c/c6d2d5a5d4e4bff1aed30016989980ebebc7208e.py) (22.1 KB)  
[tmva\_class\_example.root](https://root-forum.cern.ch/uploads/default/original/2X/4/4cae738053dc6208288b81f00325a0f6adbc5c1e.root) (201.9 KB)

---

<div class="post-metadata">

**Author:** ![urs](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/urs/32/12337_2.png) [@urs](https://root-forum.cern.ch/u/urs)\
**Post date:** [August 14, 2017, 3:23pm UTC](https://root-forum.cern.ch/t/factory-object-has-no-attribute-addvariable-in-tmva-python/25090/4 "2017-08-14T15:23:34Z")

</div>

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.

Cheers,  
–U.

---

<div class="post-metadata">

**Author:** ![wlav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@wlav](https://root-forum.cern.ch/u/wlav)\
**Post date:** [August 14, 2017, 5:05pm UTC](https://root-forum.cern.ch/t/factory-object-has-no-attribute-addvariable-in-tmva-python/25090/5 "2017-08-14T17:05:14Z")

</div>

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