# TMVA PyKeras comparison with standalone Keras API

**URL:** <https://root-forum.cern.ch/t/tmva-pykeras-comparison-with-standalone-keras-api/49479>\
**Category:** TMVA\
**Created:** [April 5, 2022, 11:34am UTC](https://root-forum.cern.ch/t/tmva-pykeras-comparison-with-standalone-keras-api/49479 "2022-04-05T11:34:51Z")\
**Posts on this page:** 3\
**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:** [April 5, 2022, 11:34am UTC](https://root-forum.cern.ch/t/tmva-pykeras-comparison-with-standalone-keras-api/49479/1 "2022-04-05T11:34:51Z")

</div>

Hi all 👋

I used TMVA PyKeras and trained NN with my data. Then I got the scores from my trained model for the signal and background data. If we look at the distribution  
 ![PyKeras_distribution](https://root-forum.cern.ch/uploads/default/original/3X/2/e/2e75e1ecbbb46f897acd378aad580e3a6bc9a5ac.jpeg)  
the signal samples massively tend to around 1 and background samples around 0, as it’s anticipated. When I try to build exactly the same NN model and train with exactly the same data, but using standalone Keras API and then try to get the scores from the trained model for the signal and background samples, we can see the following distribution

 ![KerasAPI_distribution](https://root-forum.cern.ch/uploads/default/original/3X/3/0/304f83a534e48cba1e0d6d077edb14b697bde681.png)  
It’s seen that the model poorly distinguishes the signal and background samples from each other.

It’s interesting for me that although the ROC AUC I get using TMVA PyKeras is 0.79 and ROC AUC with standalone Keras API is 0.81, the model which trained using TMVA distinguishes signal/background better. Such distribution is important for my research since I obtain the values such as significance of the signal using this distribution.

I wonder if there is some additional hidden steps that TMVA automatically performs when I try to get the scores from already trained model?

Cheers,  
Aizat

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [April 19, 2022, 11:41am UTC](https://root-forum.cern.ch/t/tmva-pykeras-comparison-with-standalone-keras-api/49479/2 "2022-04-19T11:41:23Z")

</div>

Hi @11133 ,  
sorry for the high latency, we need @moneta 's help, let’s ping him.

Cheers,  
Enrico

---

<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:** [April 19, 2022, 1:34pm UTC](https://root-forum.cern.ch/t/tmva-pykeras-comparison-with-standalone-keras-api/49479/3 "2022-04-19T13:34:48Z")

</div>

Hi,  
I think in the first case you have multiple background, in the second only one. Is all the background combined ? You should compare similar thing.  
The ROC results seem to me quite compatible, so in general I would say the discrimination is similar. Anyway, if you still have an issue, please post all the code and data so we can reproduce it

Lorenzo
