# How to plot ROC curve for a specific BDT response value?

**URL:** <https://root-forum.cern.ch/t/how-to-plot-roc-curve-for-a-specific-bdt-response-value/37674>\
**Category:** TMVA\
**Created:** [January 22, 2020, 4:37pm UTC](https://root-forum.cern.ch/t/how-to-plot-roc-curve-for-a-specific-bdt-response-value/37674 "2020-01-22T16:37:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![swanski82](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@swanski82](https://root-forum.cern.ch/u/swanski82)\
**Post date:** [January 22, 2020, 4:37pm UTC](https://root-forum.cern.ch/t/how-to-plot-roc-curve-for-a-specific-bdt-response-value/37674/1 "2020-01-22T16:37:44Z")

</div>

Hi everyone,

I have a naive question. I am trying to evaluate the performance of BDT. I define a “working point” as choosing a BDT response value within [-1, 1] and want to determine the effect of this chosen cut by ROC curve.

Any idea would be appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 22, 2020, 4:50pm UTC](https://root-forum.cern.ch/t/how-to-plot-roc-curve-for-a-specific-bdt-response-value/37674/2 "2020-01-22T16:50:20Z")

</div>

May be @moneta can help you.

---

<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:** [January 27, 2020, 4:23pm UTC](https://root-forum.cern.ch/t/how-to-plot-roc-curve-for-a-specific-bdt-response-value/37674/3 "2020-01-27T16:23:30Z")

</div>

Hi,

To figure out where on the roc-curve a particular cuts ends up you can do the following (just a sketch):

```auto
TTreeReader reader (a_tmva_tree);

TTreeReaderArray<char> reader_array (reader, "className");
TTreeReaderValue<float> val (reader, "BDTG");
TTreeReaderValue<int> val (reader, "ClassID");

int nentries = a_tmva_tree.GetEntries();
int signal_class = 0;

reader->SetEntry(0);
// WARN: This is hacky
if (className[0] == 'S') { // Signal
    signal_class = *class_id;
} elseif className[0] == 'B' { // Background
    signal_class = 1-*class_id;
} else {
    throw("ERROR!");
}

int num_true_positive = 0;
int num_false_positives = 0;

for (int i = 0; i < nentries; ++i) {
    reader->SetEntry(i);
    if (val >= YOUR_CUT and class_id == signal_class) {
        n_true_positives += 1;
    } else {
        n_false_positives += 1;
}

// From nentires, n_true_positives, and n_false_positives
// you can now calculate the ROC value for your cut value.

```

---

<div class="post-metadata">

**Author:** ![swanski82](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@swanski82](https://root-forum.cern.ch/u/swanski82)\
**Post date:** [January 28, 2020, 9:49am UTC](https://root-forum.cern.ch/t/how-to-plot-roc-curve-for-a-specific-bdt-response-value/37674/4 "2020-01-28T09:49:09Z")

</div>

Thanks for the reply! It was indeed helpful. I just want to understand the reason of this part:

```auto
if (className[0] == 'S') { // Signal
    signal_class = *class_id;
} elseif className[0] == 'B' { // Background
    signal_class = 1-*class_id;
} else {
    throw("ERROR!");
}

```

sorry, I just sent my reply incomplete 😕

anyway. AFAIK, classID (int) variable already corresponds to 0 (signal) or 1 (background).  
why do we need to check the className as well? Do they overlap correspondingly?  
e.g. if className = “S” class\_id should be 0 ?

---

<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:** [January 28, 2020, 10:20am UTC](https://root-forum.cern.ch/t/how-to-plot-roc-curve-for-a-specific-bdt-response-value/37674/5 "2020-01-28T10:20:21Z")

</div>

The integer coding for the class is determined by the order of the dataloader declarations.

```cpp
dataloader->AddSignalTree(); // class 0
dataloader->AddBackgroundTree(); // class 1

```

vs.

```cpp
dataloader->AddBackgroundTree(...); // class 0
dataloader->AddSignalTree(...); // class 1

```

The reason for this is to accomodate multi-class classification.

Cheers,  
Kim
