Logo ROOT   6.12/07
Reference Guide
TMVACrossValidation.C File Reference

Detailed Description

View in nbviewer Open in SWAN This example explains how to use the cross-validation feature of TMVA.

It is validated the Fisher algorithm with a 5-fold cross-validation.

0.0156800746918
4.76969313622
Processing /mnt/build/workspace/root-makedoc-v612/rootspi/rdoc/src/v6-12-00-patches/tutorials/tmva/TMVACrossValidation.C...
DataSetInfo : [dataset] : Added class "Signal"
: Add Tree TreeS of type Signal with 6000 events
DataSetInfo : [dataset] : Added class "Background"
: Add Tree TreeB of type Background with 6000 events
: Dataset[dataset] : Class index : 0 name : Signal
: Dataset[dataset] : Class index : 1 name : Background
: Evaluate method: Fisher
: Evaluation done.
<HEADER> CrossValidation : ==== Results ====
: Fold 0 ROC-Int : 0.9036
: Fold 1 ROC-Int : 0.9088
: Fold 2 ROC-Int : 0.8942
: Fold 3 ROC-Int : 0.8802
: Fold 4 ROC-Int : 0.8858
: ------------------------
: Average ROC-Int : 0.8945
: Std-Dev ROC-Int : 0.0119
#include "TFile.h"
#include "TTree.h"
#include "TString.h"
#include "TSystem.h"
#include "TMVA/Tools.h"
void TMVACrossValidation()
{
// This loads the library
// Load data
TFile *input(0);
TString fname = "./tmva_class_example.root";
if (!gSystem->AccessPathName( fname )) {
input = TFile::Open( fname ); // check if file in local directory exists
}
else {
input = TFile::Open("http://root.cern.ch/files/tmva_class_example.root", "CACHEREAD");
}
if (!input) {
std::cout << "ERROR: could not open data file" << std::endl;
exit(1);
}
TTree* signalTree = (TTree*)input->Get("TreeS");
TTree* background = (TTree*)input->Get("TreeB");
// Setup dataloader
TMVA::DataLoader* dataloader = new TMVA::DataLoader("dataset");
dataloader->AddSignalTree(signalTree);
dataloader->AddBackgroundTree(background);
dataloader->AddVariable("var1");
dataloader->AddVariable("var2");
dataloader->AddVariable("var3");
dataloader->AddVariable("var4");
dataloader->PrepareTrainingAndTestTree("", "SplitMode=Random:NormMode=NumEvents:!V");
// Setup cross-validation with Fisher method
TMVA::CrossValidation cv(dataloader);
cv.BookMethod(TMVA::Types::kFisher, "Fisher", "!H:!V:Fisher");
// Run cross-validation and print results
cv.Evaluate();
auto results = cv.GetResults();
for (auto r : results)
r.Print();
}
int main()
{
TMVACrossValidation();
}
Author
Stefan Wunsch

Definition in file TMVACrossValidation.C.