No description has been provided for this image No description has been provided for this image

TMVA Cross Validation

Declare Variables

In [1]:
TMVA::DataLoader loader("dataset");

loader.AddVariable("var1");
loader.AddVariable("var2");
loader.AddVariable("var3");
loader.AddVariable("var4");

Setup Dataset

In [2]:
// Load the data file
TFile* inputFile = TFile::Open("https://raw.githubusercontent.com/iml-wg/tmvatutorials/master/inputdata.root");

// Get signal and background data from input file
TTree *tsignal = (TTree*) inputFile->Get("Sig");
TTree *tbackground = (TTree*) inputFile->Get("Bkg");

// Register this data in the dataloader
loader.AddSignalTree(tsignal);
loader.AddBackgroundTree(tbackground);   
loader.PrepareTrainingAndTestTree("",
        "nTrain_Signal=1000:nTrain_Background=1000:SplitMode=Random:NormMode=NumEvents:!V");
DataSetInfo              : [dataset] : Added class "Signal"
                         : Add Tree Sig of type Signal with 6000 events
DataSetInfo              : [dataset] : Added class "Background"
                         : Add Tree Bkg of type Background with 6000 events
                         : Dataset[dataset] : Class index : 0  name : Signal
                         : Dataset[dataset] : Class index : 1  name : Background

Perform Cross Validation

In [3]:
// Book boosted decision tree method
TMVA::CrossValidation cv(&loader);
cv.BookMethod(TMVA::Types::kBDT, "BDT",
        "NTrees=10:MinNodeSize=2.5%:MaxDepth=2:nCuts=20");
In [4]:
// Run cross-validation
cv.Evaluate();

// Print results
TMVA::CrossValidationResult results = cv.GetResults();
results.Print();
                         : Evaluate method: BDT
                         : Evaluation done.
<HEADER> CrossValidation          :  ==== Results ====
                         : Fold  0 ROC-Int : 0.8732
                         : Fold  1 ROC-Int : 0.8589
                         : Fold  2 ROC-Int : 0.8592
                         : Fold  3 ROC-Int : 0.8614
                         : Fold  4 ROC-Int : 0.8567
                         : ------------------------
                         : Average ROC-Int : 0.8619
                         : Std-Dev ROC-Int : 0.0065