# Variable transformation using TMVA

**URL:** <https://root-forum.cern.ch/t/variable-transformation-using-tmva/47532>\
**Category:** TMVA\
**Created:** [November 4, 2021, 12:43pm UTC](https://root-forum.cern.ch/t/variable-transformation-using-tmva/47532 "2021-11-04T12:43:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [November 4, 2021, 12:43pm UTC](https://root-forum.cern.ch/t/variable-transformation-using-tmva/47532/1 "2021-11-04T12:43:23Z")

</div>

Hi all,

Does anyone face the problem when transforming some set of variables from the entire variable list? Eventually, I would like to apply Gaussian transformation on just some of the variables not for all, so following the instructions given in the TMVA user’s guide, I wrote the following line in my code:

factory.BookMethod(dataloader, TMVA.Types.kPyKeras, ‘PyKeras’, “H:!V:VarTransform=(names of the variables which I want to transform)”)

Unfortunalely, I get the following error:  
 : Dataset[TMVAb15\_b1\_sb] : Class 3Jets, not known for variable transformation (InvMass, please check.

Although, I added all the variables to the DataLoader.

Cheers,

---

<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:** [November 8, 2021, 4:08pm UTC](https://root-forum.cern.ch/t/variable-transformation-using-tmva/47532/2 "2021-11-08T16:08:41Z")

</div>

Hi,  
Can you please post your code and possibly also your input data (or a subset of it), so we can reproduce the issue you are having.  
Normally it should work the transformation for individual variables if done as in the Users Guide, see paragraph 4.1.5, page 52.

Lorenzo

---

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [November 11, 2021, 9:00am UTC](https://root-forum.cern.ch/t/variable-transformation-using-tmva/47532/3 "2021-11-11T09:00:41Z")

</div>

Hi,  
Please find in the attachment my code.

[Keras\_dnn\_with\_correct\_weights.py](https://root-forum.cern.ch/uploads/short-url/aD2Yp5xnr3yGQdyjniHtNqbuhcG.py) (4.4 KB)

I also tried to transform variables by their index as it’s written in the TMVA Users Guide:  
VarTransform=N(_V0_, _V3_ , _T3_, etc.). However, the same error appeared.

Ultimately, I want to transform all my variables except lead\_lep\_charge.

Cheers,

---

<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:** [November 11, 2021, 10:15pm UTC](https://root-forum.cern.ch/t/variable-transformation-using-tmva/47532/4 "2021-11-11T22:15:35Z")

</div>

Hi,  
Thank you for your code example. Can you also please post a small snapshots of your data file (just few events), so I can try your script ?  
I have tried similar code with PyKeras and it works for me.

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [November 12, 2021, 8:42am UTC](https://root-forum.cern.ch/t/variable-transformation-using-tmva/47532/5 "2021-11-12T08:42:43Z")

</div>

Hi,

Yeap, sure. I’ve attached two root files, one is signal pp-\>tHbq, another one is background pp-\>tt. [TransformedMiniNtuple\_tHbq\_SM\_300K.root](https://root-forum.cern.ch/uploads/short-url/wooORS2Y6AmNpXaMhLyZzVE0RRR.root) (799.9 KB)  
[TransformedMiniNtuple\_tt\_SM\_300K.root](https://root-forum.cern.ch/uploads/short-url/wJs7TIwaZzUAypYCyw5qb56ak6Q.root) (891.0 KB)

Just for the record: I tried to run my project on lxplus.

Thank you!

Cheers,

---

<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:** [November 12, 2021, 11:06am UTC](https://root-forum.cern.ch/t/variable-transformation-using-tmva/47532/6 "2021-11-12T11:06:43Z")

</div>

Hi,  
Thank you for the data file. You script has an error, the last variable in the data file is called `lead_lep_pid` instead of `lead_lep_charge`.  
Another problem is that you should remove the space when defining the transformation variables.  
Do:

```auto
"....VarTransform=G(InvMass_3Jets,delta_eta_tH,....)"

```

After this I think it should work, if not please let me know

Cheers  
Lorenzo

---

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [November 14, 2021, 12:06pm UTC](https://root-forum.cern.ch/t/variable-transformation-using-tmva/47532/7 "2021-11-14T12:06:04Z")

</div>

Hi Lorenzo,

It did work, thank you so much! I didn’t even think that the problem might be related to the spaces between variable names 🙂

Thank you!

Cheers,
