DataLoader Example¶
Declare Factory¶
In [ ]:
TMVA::Tools::Instance();
auto inputFile = TFile::Open("https://raw.githubusercontent.com/iml-wg/tmvatutorials/master/inputdata.root");
auto outputFile = TFile::Open("TMVAOutputCV.root", "RECREATE");
TMVA::Factory factory("TMVAClassification", outputFile,
"!V:ROC:!Correlations:!Silent:Color:!DrawProgressBar:AnalysisType=Classification" );
Declare DataLoader(s)¶
In [ ]:
TMVA::DataLoader loader("dataset");
loader.AddVariable("var1");
loader.AddVariable("var2");
loader.AddVariable("var3");
Setup Dataset(s)¶
In [ ]:
TTree *tsignal, *tbackground;
inputFile->GetObject("Sig", tsignal);
inputFile->GetObject("Bkg", tbackground);
TCut mycuts, mycutb;
loader.AddSignalTree (tsignal, 1.0); //signal weight = 1
loader.AddBackgroundTree(tbackground, 1.0); //background weight = 1
loader.PrepareTrainingAndTestTree(mycuts, mycutb,
"nTrain_Signal=1000:nTrain_Background=1000:SplitMode=Random:NormMode=NumEvents:!V" );
Booking Methods¶
First dataset¶
In [ ]:
//Boosted Decision Trees
factory.BookMethod(&loader,TMVA::Types::kBDT, "BDT",
"!V:NTrees=200:MinNodeSize=2.5%:MaxDepth=2:BoostType=AdaBoost:AdaBoostBeta=0.5:UseBaggedBoost:BaggedSampleFraction=0.5:SeparationType=GiniIndex:nCuts=20" );
//Multi-Layer Perceptron (Neural Network)
factory.BookMethod(&loader, TMVA::Types::kMLP, "MLP",
"!H:!V:NeuronType=tanh:VarTransform=N:NCycles=100:HiddenLayers=N+5:TestRate=5:!UseRegulator" );
Train Methods¶
In [ ]:
factory.TrainAllMethods();
Test and Evaluate Methods¶
In [ ]:
factory.TestAllMethods();
factory.EvaluateAllMethods();
Plot ROC Curve¶
We enable JavaScript visualisation for the plots
In [ ]:
%jsroot on
In [ ]:
auto c1 = factory.GetROCCurve(&loader);
c1->Draw();