# PyKeras application : how is the output computed?

**URL:** <https://root-forum.cern.ch/t/pykeras-application-how-is-the-output-computed/30922>\
**Category:** TMVA\
**Created:** [October 1, 2018, 4:48pm UTC](https://root-forum.cern.ch/t/pykeras-application-how-is-the-output-computed/30922 "2018-10-01T16:48:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas92](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/3da27b/32.png) [@Nicolas92](https://root-forum.cern.ch/u/Nicolas92)\
**Post date:** [October 1, 2018, 4:48pm UTC](https://root-forum.cern.ch/t/pykeras-application-how-is-the-output-computed/30922/1 "2018-10-01T16:48:33Z")

</div>

Dear TMVA experts,

I have started playing around with the PyKeras method, but I could not yet understand how the NN output is computed (for application).

I believe the relevant function is Double\_t MethodPyKeras::GetMvaValue(…) [0], which returns the single value : `fOutput[TMVA::Types::kSignal];`

This `fOutput` vector is said [1] to hold the probabilities for each target class (I have 2, signal and background).

- Therefore, does `return fOutput[TMVA::Types::kSignal];` mean that only 1 output neuron (\<-\> signal) is read, not the 2 I have in my model ?

- What’s more I can not find where/how `fOutput` is filled. Does it simply contain the values held by each output neuron, or is some transformation applied (e.g. to ensure that the result are probabilities, etc.) ?

Thanks in advance, cheers,  
Nicolas

[0] [https://root.cern.ch/doc/v608/MethodPyKeras\_8cxx\_source.html#l00306](https://root.cern.ch/doc/v608/MethodPyKeras_8cxx_source.html#l00306)  
[1] [https://root.cern.ch/doc/v608/MethodPyKeras\_8cxx\_source.html#l00109](https://root.cern.ch/doc/v608/MethodPyKeras_8cxx_source.html#l00109)

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 1, 2018, 7:50pm UTC](https://root-forum.cern.ch/t/pykeras-application-how-is-the-output-computed/30922/2 "2018-10-01T19:50:04Z")

</div>

@moneta knows who can help for the TMVA related questions

---

<div class="post-metadata">

**Author:** ![Nicolas92](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/3da27b/32.png) [@Nicolas92](https://root-forum.cern.ch/u/Nicolas92)\
**Post date:** [October 8, 2018, 8:48am UTC](https://root-forum.cern.ch/t/pykeras-application-how-is-the-output-computed/30922/3 "2018-10-08T08:48:05Z")

</div>

Dear experts,

any news on this ?

Nicolas

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [October 8, 2018, 2:14pm UTC](https://root-forum.cern.ch/t/pykeras-application-how-is-the-output-computed/30922/4 "2018-10-08T14:14:59Z")

</div>

Hi,

You are indeed correct that this is the relevant method.

For classification and multiclass classification the the values are read from the keras model and returned untransformed. In the binary classification setting, the TMVA model is to output only the signal class since the background class is a trivial transformation of this value.

If you want to get all outputs you can use the multiclass setting, then the function `GetMulticlassValues` is used.

The `fOutput` vector is filled through python, the python runtime is invoked to evaluate the keras model and make the predictions accessible to the c++ backend of TMVA.

Hope this helps!

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![Nicolas92](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/3da27b/32.png) [@Nicolas92](https://root-forum.cern.ch/u/Nicolas92)\
**Post date:** [October 9, 2018, 12:20pm UTC](https://root-forum.cern.ch/t/pykeras-application-how-is-the-output-computed/30922/5 "2018-10-09T12:20:09Z")

</div>

Dear Kim,

it does, thank you very much.

Cheers,  
Nicolas
