# Problems when using the TMVA::Reader-\>EvaluateMulticlass() method

**URL:** <https://root-forum.cern.ch/t/problems-when-using-the-tmva-reader-evaluatemulticlass-method/53764>\
**Category:** TMVA\
**Created:** [February 24, 2023, 3:11pm UTC](https://root-forum.cern.ch/t/problems-when-using-the-tmva-reader-evaluatemulticlass-method/53764 "2023-02-24T15:11:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![evalient](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/7ea924/32.png) [@evalient](https://root-forum.cern.ch/u/evalient)\
**Post date:** [February 24, 2023, 3:11pm UTC](https://root-forum.cern.ch/t/problems-when-using-the-tmva-reader-evaluatemulticlass-method/53764/1 "2023-02-24T15:11:12Z")

</div>

Hi everyone!

I am trying to evaluate the multiclass scores in some code from some n-tuples. I have seen that for the case of binominal BDTs, there is a TMVA::Reader method called EvaluateMVA in which you can explicitly pass for each event, as an argument, a vector with the variables that the Reader needs.  
Do you know if there is some equivalent way to do it with the EvaluateMulticlass method? Because none of the constructors take this vector of inputs as argument…  
Is there any way to use the EvaluateMVA for a Multiclass classification?

Thanks a lot in advance,

Enrique

---

<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:** [February 27, 2023, 9:32am UTC](https://root-forum.cern.ch/t/problems-when-using-the-tmva-reader-evaluatemulticlass-method/53764/2 "2023-02-27T09:32:23Z")

</div>

@moneta should be able to help

---

<div class="post-metadata">

**Author:** ![evalient](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/7ea924/32.png) [@evalient](https://root-forum.cern.ch/u/evalient)\
**Post date:** [February 27, 2023, 3:17pm UTC](https://root-forum.cern.ch/t/problems-when-using-the-tmva-reader-evaluatemulticlass-method/53764/3 "2023-02-27T15:17:13Z")

</div>

Thank you @bellenot @moneta !

---

<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:** [February 27, 2023, 4:30pm UTC](https://root-forum.cern.ch/t/problems-when-using-the-tmva-reader-evaluatemulticlass-method/53764/4 "2023-02-27T16:30:29Z")

</div>

Hi,  
There is a `Reader::EvaluateMultiClass`, what you are missing is passing a `std::vector<float>` with the input features ?  
This is not a very efficient API to use it, but if you need you can probably include these few lines in your code by setting the variables in the `TMVA::Event` class. Is there any reason that you cannot use the standard `Reader` API where you set the input variables using `Reader::AddVariable` ?

Lorenzo

---

<div class="post-metadata">

**Author:** ![evalient](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/7ea924/32.png) [@evalient](https://root-forum.cern.ch/u/evalient)\
**Post date:** [March 2, 2023, 3:17pm UTC](https://root-forum.cern.ch/t/problems-when-using-the-tmva-reader-evaluatemulticlass-method/53764/5 "2023-03-02T15:17:49Z")

</div>

Hello @moneta

Exactly, that would be my doubt: is such feature (passing a `std::vector<float>` with the input) available?  
I have tried to add a TMVA::Event, but this does not seem to be used when calling EvaluateMulticlass. I have attached an example of the code implementing this TMVA::Event before calling the EvaluateMulticlass.

Enrique  
[TMVAMulticlassApplication\_simple.C](https://root-forum.cern.ch/uploads/short-url/lilCGGJCfEjHwywSzUoFkJ9OMaT.C) (1.7 KB)

---

<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 2, 2023, 3:51pm UTC](https://root-forum.cern.ch/t/problems-when-using-the-tmva-reader-evaluatemulticlass-method/53764/6 "2023-03-02T15:51:20Z")

</div>

Hi,

You cannot create an Event not attached to anything, but you need to use the one attached to the Method class. So you need first to get an instance to the used method (returned from `Reader::BookMVA`) and then from the class get the event and then fill the values.  
You need to add these lines in your code

```auto
// need casting here from IMethod to MethodBase
auto methodBDTG = (TMVA::MethodBase*) reader->BookMVA( "BDTG method", "dataset/weights/TMVAMulticlass_BDTG.weights.xml");

// later in the event loop: 
// and we need to remove the const from the returned event:
auto event = const_cast<TMVA::Event*>(methodBDTG->GetEvent());
event->SetVal(0,....);
event->SetVal(1,....);

score = reader->EvaluateMulticlass( "BDTG method" );

```

If you have further problems please let me know

Cheers

Lorenzo
