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");
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();