How to use "GetROCCurve" with an existing loader folder

Hi, experts,

In the TMVA tutorial TMVA_CNN_Classification.C, there is this line in the end of the program:

auto c1 = factory.GetROCCurve(loader);

How do I use this function by itself when I already have an existing loader folder with my training and testing results? I would like to just plot some ROC curves without having to run the whole training and testing process. And also, this c1 is a TCanvas, is there anyway that I can get the ROC curve in a TGraph? I just want to set different x and y ranges, or if I can do it with the TCanvas?

Best Regards,
Jackhammer

Welcome to the ROOT forum.
I think @moneta can help you.

Thank you for tagging an expert for me, but it’s been a week. I hope someone can give me some suggestions.

Hi @Jackhammer0102 ,

thank you for the ping and sorry for the high latency. @moneta we need your help here :slight_smile:

Cheers,
Enrico

Hi ,
Apologies for the delay in answering. I have missed your message.

When you have done your training, you can still compute the ROC curve, but you need to use the TMVA output file, which contains all the result of the training and testing.
You can use either the TMVAGUI or the TMVA::ROCCurve class using the output that is read from the file. If you need I can provide an example for the second case.
The class itself returns a TGraph so you can customise the range

Cheers

Lorenzo

Hi, Enrico,

Thank you so much for tagging the expert for me!

Hi, Lorenzo,

That’s totally fine, and thank you for the reply!
I would really appreciate if you could show me an example on how to use TMVA::ROCCurve to make ROC curves using the TMVA output file.

Best Regards,
Jackhammer

Hi,
Here is an example using the output file after running the tutorial TMVA_Higgs_Classification.C:

TFile f("Higgs_ClassificationOutput.root");   // open output file created after training
t = (TTree*) f.Get("dataset/TestTree");  // use test tree 
t->Print();
// get BDT signal result
size_t  ns =  t->Draw("BDT","classID==0");
std::vector<float> bdt_s(t->GetV1(), t->GetV1()+ns);    
// get BDT background result
size_t nb = t->Draw("BDT","classID==1");
std::vector<float> bdt_b(t->GetV1(), t->GetV1()+nb);
TMVA::ROCCurve roc(bdt_s, bdt_b);
TGraph * g  = roc.GetROCCurve();
// you can now change the graph as you wish
g->SetLineColor(kRed); 
g->Draw("AL");

Lorenzo

Hi, Lorenzo,

Thank you for the example, it was very helpful and I’ve successfully plotted out the ROC curve for my BDT test tree, but I am having a hard time trying to plot other ROC curves all together. I also have DNN and CNN in the same TMVA output file, how can I plot all of them in one graph?

I did this but I didn’t get three ROC curves in one graph, I only got one ROC curve:

  // Get BDT signal result
  size_t ns_bdt = testTree->Draw("BDT", "classID==0");
  std::vector<float> s_bdt(testTree->GetV1(), testTree->GetV1()+ns_bdt);
  // Get BDT background result
  size_t nb_bdt = testTree->Draw("BDT", "classID==1");
  std::vector<float> b_bdt(testTree->GetV1(), testTree->GetV1()+nb_bdt);
  // TGraph ROC curve for BDT
  TMVA::ROCCurve roc_bdt(s_bdt, b_bdt);
  TGraph *g_bdt = roc_bdt.GetROCCurve();

  // Get CNN signal result
  size_t ns_cnn = testTree->Draw("TMVA_CNN_CPU", "classID==0");
  std::vector<float> s_cnn(testTree->GetV1(), testTree->GetV1()+ns_cnn);
  // Get CNN background result
  size_t nb_cnn = testTree->Draw("TMVA_CNN_CPU", "classID==1");
  std::vector<float> b_cnn(testTree->GetV1(), testTree->GetV1()+nb_cnn);
  // TGraph ROC curve for CNN
  TMVA::ROCCurve roc_cnn(s_cnn, b_cnn);
  TGraph *g_cnn = roc_cnn.GetROCCurve();

  // Get DNN signal result
  size_t ns_dnn = testTree->Draw("TMVA_DNN_CPU", "classID==0");
  std::vector<float> s_dnn(testTree->GetV1(), testTree->GetV1()+ns_dnn);
  // Get DNN background result
  size_t nb_dnn = testTree->Draw("TMVA_DNN_CPU", "classID==1");
  std::vector<float> b_dnn(testTree->GetV1(), testTree->GetV1()+nb_dnn);
  // TGraph ROC curve for DNN
  TMVA::ROCCurve roc_dnn(s_dnn, b_dnn);
  TGraph *g_dnn = roc_dnn.GetROCCurve();

  // Draw TGraph ROC curves
  g_bdt->Draw("AL");
  g_cnn->Draw("AL, same");
  g_dnn->Draw("AL, same");

Hi,
You should use the A option in TGraph::Draw (draw axis) only for the first one. Do:

g_bdt->Draw("AL");
  g_cnn->Draw("L,");
  g_dnn->Draw("L");

or you can use the TMuktiGraph class, see ROOT: tutorials/graphs/multigraph.C File Reference

Lorenzo

Hi, Lorenzo,

Now it works, thank you so much for your help, I really appreciate that!

Best Regards,
Jackhammer