This macro provides an example of how to use TMVA for k-folds cross evaluation in application.
This requires that CrossValidation was run with a deterministic split, such as "...:splitExpr=int([eventID])%int([numFolds]):..."
.
- Project : TMVA - a ROOT-integrated toolkit for multivariate data analysis
- Package : TMVA
- Root Macro: TMVACrossValidationApplication
Weightfile for method BDTG not found. Did you run TMVACrossValidation with a specified splitExpr?
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
{
tree->SetBranchAddress(
"x", &
x);
tree->SetBranchAddress(
"y", &
y);
tree->SetBranchAddress(
"eventID", &eventID);
x = rng.Gaus(offset, scale);
y = rng.Gaus(offset, scale);
++eventID;
}
tree->ResetBranchAddresses();
}
int TMVACrossValidationApplication()
{
reader->AddSpectator(
"eventID", &eventID);
TString jobname(
"TMVACrossEvaluation");
{
if (weightfileExists) {
reader->BookMVA(methodName, weightfile);
} else {
std::cout << "Weightfile for method " << methodName << " not found."
" Did you run TMVACrossValidation with a specified"
" splitExpr?" << std::endl;
exit(0);
}
}
{
if (weightfileExists) {
reader->BookMVA(methodName, weightfile);
} else {
std::cout << "Weightfile for method " << methodName << " not found."
" Did you run TMVACrossValidation with a specified"
" splitExpr?" << std::endl;
exit(0);
}
}
tree->Branch(
"x", &
x,
"x/F");
tree->Branch(
"y", &
y,
"y/F");
tree->Branch(
"eventID", &eventID,
"eventID/I");
fillTree(
tree, 1000, 1.0, 1.0, 100);
fillTree(
tree, 1000, -1.0, 1.0, 101);
tree->SetBranchAddress(
"x", &
x);
tree->SetBranchAddress(
"y", &
y);
tree->SetBranchAddress(
"eventID", &eventID);
TH1F histBDTG{
"BDTG",
"BDTG", nbin, -1, 1};
TH1F histFisher{
"Fisher",
"Fisher", nbin, -1, 1};
for (
Long64_t ievt = 0; ievt <
tree->GetEntries(); ievt++) {
histBDTG.Fill(valBDTG);
histFisher.Fill(valFisher);
}
tree->ResetBranchAddresses();
{
TFile *target =
new TFile(
"TMVACrossEvaluationApp.root",
"RECREATE");
histBDTG.Write();
histFisher.Write();
delete target;
}
return 0;
}
int main(
int argc,
char **argv)
{
TMVACrossValidationApplication();
}
R__EXTERN TSystem * gSystem
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
virtual void Close(Option_t *option="")
Close a file.
1-D histogram with a float per channel (see TH1 documentation)}
The Reader class serves to use the MVAs in a specific analysis context.
Random number generator class based on M.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
A TTree object has a header with a name and a title.
int main(int argc, char **argv)
- Author
- Kim Albertsson (adapted from code originally by Andreas Hoecker)
Definition in file TMVACrossValidationApplication.C.