Logo ROOT   6.08/07
Reference Guide
TMVACrossValidation.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_tmva
3 /// \notebook -nodraw
4 /// This example explains how to use the cross-validation feature of TMVA. It is
5 /// validated the Fisher algorithm with a 5-fold cross-validation.
6 /// - Project : TMVA - a Root-integrated toolkit for multivariate data analysis
7 /// - Package : TMVA
8 /// - Exectuable: TMVACrossValidation
9 ///
10 /// \macro_output
11 /// \macro_code
12 /// \author Stefan Wunsch
13 
14 #include "TFile.h"
15 #include "TTree.h"
16 #include "TString.h"
17 #include "TSystem.h"
18 
19 #include "TMVA/DataLoader.h"
20 #include "TMVA/CrossValidation.h"
21 #include "TMVA/Tools.h"
22 
23 void TMVACrossValidation()
24 {
25  // This loads the library
27 
28  // Load data
29  TString fname = "./tmva_class_example.root";
30  if (gSystem->AccessPathName(fname))
31  gSystem->Exec("curl -O http://root.cern.ch/files/tmva_class_example.root");
32  TFile *input = TFile::Open(fname);
33 
34  TTree* signalTree = (TTree*)input->Get("TreeS");
35  TTree* background = (TTree*)input->Get("TreeB");
36 
37  // Setup dataloader
39 
40  dataloader->AddSignalTree(signalTree);
41  dataloader->AddBackgroundTree(background);
42 
43  dataloader->AddVariable("var1");
44  dataloader->AddVariable("var2");
45  dataloader->AddVariable("var3");
46  dataloader->AddVariable("var4");
47 
48  dataloader->PrepareTrainingAndTestTree("", "SplitMode=Random:NormMode=NumEvents:!V");
49 
50  // Setup cross-validation with Fisher method
51  TMVA::CrossValidation cv(dataloader);
52  cv.BookMethod(TMVA::Types::kFisher, "Fisher", "!H:!V:Fisher");
53 
54  // Run cross-validation and print results
55  cv.Evaluate();
56  TMVA::CrossValidationResult results = cv.GetResults();
57  results.Print();
58 }
59 
60 int main()
61 {
62  TMVACrossValidation();
63 }
void AddBackgroundTree(TTree *background, Double_t weight=1.0, Types::ETreeType treetype=Types::kMaxTreeType)
Definition: DataLoader.cxx:382
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1266
static Tools & Instance()
Definition: Tools.cxx:80
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
Basic string class.
Definition: TString.h:137
void AddVariable(const TString &expression, const TString &title, const TString &unit, char type='F', Double_t min=0, Double_t max=0)
Definition: DataLoader.cxx:456
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3907
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition: TSystem.cxx:658
void PrepareTrainingAndTestTree(const TCut &cut, const TString &splitOpt)
Definition: DataLoader.cxx:580
A TTree object has a header with a name and a title.
Definition: TTree.h:98
void AddSignalTree(TTree *signal, Double_t weight=1.0, Types::ETreeType treetype=Types::kMaxTreeType)
Definition: DataLoader.cxx:353
int main(int argc, char **argv)