Class to perform two class classification.
The first step before any analysis is to prepare the data, to do that you need to create an object of TMVA::DataLoader, in this object you need to configure the variables and the number of events to train/test. The class TMVA::Experimental::Classification needs a TMVA::DataLoader object, optional a TFile object to save the results and some extra options in a string like "V:Color:Transformations=I;D;P;U;G:Silent:DrawProgressBar:ModelPersistence:Jobs=2" where: V = verbose output Color = coloured screen output Silent = batch mode: boolean silent flag inhibiting any output from TMVA Transformations = list of transformations to test. DrawProgressBar = draw progress bar to display training and testing. ModelPersistence = to save the trained model in xml or serialized files. Jobs = number of ml methods to test/train in parallel using MultiProc, requires to call Evaluate method. Basic example.
{
TString fname =
gROOT->GetTutorialDir() +
"/machine_learning/data/tmva_class_example.root";
if (!
gSystem->AccessPathName(fname)) {
}
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");
TMVA::DataLoader *dataloader = new TMVA::DataLoader("dataset");
dataloader->
AddVariable(
"myvar2 := var1-var2",
"Expression 2",
"",
'F');
dataloader->
AddVariable(
"var3",
"Variable 3",
"units",
'F');
dataloader->
AddVariable(
"var4",
"Variable 4",
"units",
'F');
dataloader->
AddSpectator(
"spec1 := var1*2",
"Spectator 1",
"units",
'F');
dataloader->
AddSpectator(
"spec2 := var1*3",
"Spectator 2",
"units",
'F');
TMVA::Experimental::Classification *cl =
new TMVA::Experimental::Classification(dataloader,
Form(
"Jobs=%d", jobs));
"UseBaggedBoost:BaggedSampleFraction=0.5:nCuts=20:MaxDepth=2");
TCanvas *
c =
new TCanvas(
Form(
"ROC"));
c->SetTitle(
"ROC-Integral Curve");
auto mg = new TMultiGraph();
for (
UInt_t i = 0; i < results.size(); i++) {
auto roc = results[i].GetROCGraph();
roc->SetLineColorAlpha(i + 1, 0.1);
mg->Add(roc);
}
mg->Draw("AL");
mg->GetXaxis()->SetTitle(" Signal Efficiency ");
mg->GetYaxis()->SetTitle(" Background Rejection ");
c->BuildLegend(0.15, 0.15, 0.3, 0.3);
delete cl;
}
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
double Double_t
Double 8 bytes.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
void AddSpectator(const TString &expression, const TString &title="", const TString &unit="", Double_t min=0, Double_t max=0)
user inserts target in data set info
void SetBackgroundWeightExpression(const TString &variable)
void AddVariable(const TString &expression, const TString &title, const TString &unit, char type='F', Double_t min=0, Double_t max=0)
user inserts discriminating variable in data set info
virtual void BookMethod(TString methodname, TString methodtitle, TString options="")
Method to book the machine learning method to perform the algorithm.
std::vector< ClassificationResult > & GetResults()
Return the vector of TMVA::Experimental::ClassificationResult objects.
void Evaluate() override
Method to perform Train/Test over all ml method booked.
void classification(UInt_t jobs=4)