# How to increase granularity of ROC?

**URL:** <https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581>\
**Category:** TMVA\
**Created:** [December 3, 2020, 5:38pm UTC](https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581 "2020-12-03T17:38:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlee](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jlee/32/24176_2.png) [@jlee](https://root-forum.cern.ch/u/jlee)\
**Post date:** [December 3, 2020, 5:38pm UTC](https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581/1 "2020-12-03T17:38:37Z")

</div>

Dear ROOT experts,

I’m doing TMVA by following the tutorial macro named TMVAClassification.C:

> **[ROOT: tutorials/tmva/TMVAClassification.C File Reference](https://root.cern/doc/master/TMVAClassification_8C.html)**

I saw that the ROC expressed with 99 points from 0 to 1 in the output of TMVA.  
I want to increase the granularity of ROC instead of using default setting.  
Could someone guide me how can I do this?

Thanks in advance,  
Jongho

---

<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:** [December 4, 2020, 2:43pm UTC](https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581/2 "2020-12-04T14:43:36Z")

</div>

Hi,

Unfortunately I noticed that the function `TMVA::Factory::GetROCCurve` is missing a parameter specifying the number of points (the default is 100).  
I will add this option. As a workaround the solution is to create the ROC curve from the TMVA output fil.  
Here is an example on how to do from the outputfile of `TMVAClassification.C` for the BDT method.

```auto
TFile f("TMVA.root");
auto TestTree = (TTree*) f.Get("dataset/TestTree");
// retrieve from the Testing tree the mva output plus weight and class id
int n = TestTree->Draw("BDT:weight:classID","");
// fill vector for the 3 quantities
std::vector<float> mvas(TestTree->GetV1(), TestTree->GetV1()+n);                                                                                                                       
std::vector<float> weights(TestTree->GetV2(), TestTree->GetV2()+n);    
std::vector<bool> targets(TestTree->GetV3(), TestTree->GetV3()+n); 
// classID ==0 is signal , instead for ROC target==1 is considered signal
// need to flip boolean vector
targets.flip();
TMVA::ROCCurve roc( mvas, targets,weights);
// get a graph given number of points (e.g. 1000)
auto curve = roc.GetROCCurve(1000);
curve->Draw();

```

Lorenzo

---

<div class="post-metadata">

**Author:** ![jlee](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jlee/32/24176_2.png) [@jlee](https://root-forum.cern.ch/u/jlee)\
**Post date:** [December 4, 2020, 4:43pm UTC](https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581/3 "2020-12-04T16:43:22Z")

</div>

Hi Lorenzo,  
Thanks for your detailed answer with example!  
I’ll try above example to draw ROC curve.

---

<div class="post-metadata">

**Author:** ![jlee](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jlee/32/24176_2.png) [@jlee](https://root-forum.cern.ch/u/jlee)\
**Post date:** [December 4, 2020, 5:08pm UTC](https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581/4 "2020-12-04T17:08:19Z")

</div>

Hi @moneta,

When I tried this macro, everything was fine except the last line.  
It opens a canvas, however, the ROC curve is not appear.  
I’ve checked that three vectors were filled with proper values.  
Can you please give some help?

I’m using ROOT v6.22.02 with ubuntu20 - gcc9.3 binary distribution.

Jongho

---

<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:** [December 4, 2020, 5:16pm UTC](https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581/5 "2020-12-04T17:16:31Z")

</div>

Try

```auto
curve->Draw("AP");

```

---

<div class="post-metadata">

**Author:** ![jlee](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jlee/32/24176_2.png) [@jlee](https://root-forum.cern.ch/u/jlee)\
**Post date:** [December 4, 2020, 5:22pm UTC](https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581/6 "2020-12-04T17:22:13Z")

</div>

`curve->Draw("AP")` doesn’t work either.  
I also tried manually by making a canvas and add `c1->Update();` just after `Draw` command.  
The output is below.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/5/9/599fc6506ba2e332199240c75eeb14ee77abc619.png)

Jongho

---

<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:** [December 4, 2020, 6:58pm UTC](https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581/7 "2020-12-04T18:58:57Z")

</div>

Can you please post you code so I can reproduce this ?  
Thank you

---

<div class="post-metadata">

**Author:** ![jlee](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jlee/32/24176_2.png) [@jlee](https://root-forum.cern.ch/u/jlee)\
**Post date:** [December 4, 2020, 7:11pm UTC](https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581/8 "2020-12-04T19:11:30Z")

</div>

Thanks for taking care of this issue.  
You can get input of the code from [here](https://www.dropbox.com/s/8aj0g3ny6ryesf2/output_R6.root?dl=0)  
[high\_granularity\_roc.cpp](https://root-forum.cern.ch/uploads/short-url/1itZuWNfzdCXU0Zlq0FCQB3Nb2O.cpp) (1.3 KB)

Jongho

---

<div class="post-metadata">

**Author:** ![jlee](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jlee/32/24176_2.png) [@jlee](https://root-forum.cern.ch/u/jlee)\
**Post date:** [December 7, 2020, 11:07am UTC](https://root-forum.cern.ch/t/how-to-increase-granularity-of-roc/42581/9 "2020-12-07T11:07:10Z")

</div>

Hi @moneta

I just got the ROC curve by changing the following command line:  
`TMVA::ROCCurve roc(mvas, targets, weights);`  
to  
`TMVA::ROCCurve *roc = new TMVA::ROCCurve(mvas, targets, weights);`

Jongho
