# Error while training CNN in TMVA

**URL:** <https://root-forum.cern.ch/t/error-while-training-cnn-in-tmva/38228>\
**Category:** TMVA\
**Created:** [March 3, 2020, 12:03am UTC](https://root-forum.cern.ch/t/error-while-training-cnn-in-tmva/38228 "2020-03-03T00:03:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darthgera123](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/97f17d/32.png) [@darthgera123](https://root-forum.cern.ch/u/darthgera123)\
**Post date:** [March 3, 2020, 12:03am UTC](https://root-forum.cern.ch/t/error-while-training-cnn-in-tmva/38228/1 "2020-03-03T00:03:31Z")

</div>

Hi,  
I am trying to implement a simple CNN in TMVA. I have 2 TTree objects sig\_tree;1 and bkg\_tree;1. When I try to train them after I write factory.TrainAllMethods();, I get this error -

```auto
Factory : Train all methods
                         : Building event vectors for type 2 Signal
                         : Dataset[dataset] : create input formulas for tree sig_tree
<FATAL> : Expression var_0 could not be resolved to a valid formula. 
***> abort program execution

Error in <TTreeFormula::Compile>: Bad numerical expression : "var_0"

```

As far as I know when I do sig\_tree;1-\>ls(), I do not get anything as “var\_0”. Do i change some variable name? Please Help

Regards  
Pulkit Gera

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [March 3, 2020, 10:49am UTC](https://root-forum.cern.ch/t/error-while-training-cnn-in-tmva/38228/2 "2020-03-03T10:49:28Z")

</div>

Hi,

The problem is that the expression passed in TMVA when adding a variable must match the branch name in the TTree.  
Note that in case of the Tree containing a collection (an array of floats or a std::vector ) you can use the new function available from ROOT 6.20, `DataLoader::AddVariablesArray`, see

[https://root.cern.ch/doc/master/classTMVA\_1\_1DataLoader.html#a068fefb7d74208ed4b6bba8e842f1293](https://root.cern.ch/doc/master/classTMVA_1_1DataLoader.html#a068fefb7d74208ed4b6bba8e842f1293)

Lorenzo

---

<div class="post-metadata">

**Author:** ![Neel\_Shah](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/neel_shah/32/28438_2.png) [@Neel\_Shah](https://root-forum.cern.ch/u/Neel_Shah)\
**Post date:** [March 26, 2022, 8:31am UTC](https://root-forum.cern.ch/t/error-while-training-cnn-in-tmva/38228/3 "2022-03-26T08:31:40Z")

</div>

@moneta@darthgera123 I am also facing the same issue with training of CNN in TMVA.

This the notebook where i faced the same error in `factory.TrainAllMethods()` method. I even used `DataLoader::AddVariablesArray` method,but still this error was not resolved.

@darthgera123 can you please suggest how did you resolve this issue.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [March 28, 2022, 8:27am UTC](https://root-forum.cern.ch/t/error-while-training-cnn-in-tmva/38228/4 "2022-03-28T08:27:50Z")

</div>

The error reported indicates that the input Tree does not contain that variable. You should check the input content, by calling Three::Print before using it in TMVA

Lorenzo
