# How are sensitivity and specificity computed in TMVA::ROCCurve?

**URL:** <https://root-forum.cern.ch/t/how-are-sensitivity-and-specificity-computed-in-tmva-roccurve/42806>\
**Category:** TMVA\
**Created:** [December 19, 2020, 8:11pm UTC](https://root-forum.cern.ch/t/how-are-sensitivity-and-specificity-computed-in-tmva-roccurve/42806 "2020-12-19T20:11:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Str55](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/str55/32/32911_2.png) [@Str55](https://root-forum.cern.ch/u/Str55)\
**Post date:** [December 19, 2020, 8:11pm UTC](https://root-forum.cern.ch/t/how-are-sensitivity-and-specificity-computed-in-tmva-roccurve/42806/1 "2020-12-19T20:11:03Z")

</div>

Dear experts,

I’m a little confused how specificity and sensitivity are computed in [TMVA::ROCCurve](https://root.cern/doc/v614/classTMVA_1_1ROCCurve.html).

I was under the assumption that they would be determined by looping over a bunch of operating points and finding sEff and bRej at each point. However, these functions ( [Sensitivity](https://root.cern/doc/v614/ROCCurve_8cxx_source.html#l00177), [Specificity](https://root.cern/doc/v614/ROCCurve_8cxx_source.html#l00141) ) appear to do something different.

When I implemented my own roc curve by calculating sEff and bRej for my BDT at 1000 evenly spaced operating points between -1 and 1, I had a very different result.

 ![roc1](https://root-forum.cern.ch/uploads/default/original/3X/5/6/5626a7f93c4a9c1371c613ad11adc40c10d5095e.png)

Thank you!  
-Steve

---

<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:** [December 21, 2020, 3:53pm UTC](https://root-forum.cern.ch/t/how-are-sensitivity-and-specificity-computed-in-tmva-roccurve/42806/2 "2020-12-21T15:53:38Z")

</div>

Maybe @moneta can give some hints

---

<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:** [January 4, 2021, 4:56pm UTC](https://root-forum.cern.ch/t/how-are-sensitivity-and-specificity-computed-in-tmva-roccurve/42806/3 "2021-01-04T16:56:10Z")

</div>

Hi,

The two functions are internal functions and compute the sensitivity (signal efficiency) and specificity (background rejection) at every signal (and background) output points.  
The obtained values are then plotted to make the ROC curve as a TGraph with x = sensitivity values and y = specifity values. See [TMVA::GetROCCurve](https://root.cern/doc/v614/ROCCurve_8cxx_source.html#l00277)

You should get very similar results as using uniform binning in the two variables. If not and you did not find any error in your code, please post the macro producing the above plot and I can verify it

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![Str55](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/str55/32/32911_2.png) [@Str55](https://root-forum.cern.ch/u/Str55)\
**Post date:** [January 4, 2021, 10:23pm UTC](https://root-forum.cern.ch/t/how-are-sensitivity-and-specificity-computed-in-tmva-roccurve/42806/4 "2021-01-04T22:23:14Z")

</div>

Hi Lorenzo,

I see the issue.

> [@moneta](#):
>
> The obtained values are then plotted to make the ROC curve as a TGraph with x = sensitivity values and y = specifity values

This is correct, and looking at the code of [TMVA::GetROCCurve](https://root.cern/doc/v614/ROCCurve_8cxx_source.html#l00277) confirms that. However, the Doxygen documentation for that function says the opposite:  
x = specificity  
y = sensitivity

That is what I was going off. Sure enough, my roc-making function lines up perfectly with TMVA::ROCCurve when I flip the axes to match what they should be.

Thanks for the help! I’ve submitted a [pull request](https://github.com/root-project/root/pull/6984) on the root github to fix the docu.

Cheers,  
Steve

---

<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:** [January 5, 2021, 8:27am UTC](https://root-forum.cern.ch/t/how-are-sensitivity-and-specificity-computed-in-tmva-roccurve/42806/5 "2021-01-05T08:27:35Z")

</div>

Hi Steve,

Thank you for submitting the PR and noting this mistake. I have now merged your changes

Cheers

Lorenzo
