Logo ROOT   6.10/09
Reference Guide
ApplicationRegressionKeras.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from ROOT import TMVA, TFile, TString
4 from array import array
5 from subprocess import call
6 from os.path import isfile
7 
8 # Setup TMVA
11 reader = TMVA.Reader("Color:!Silent")
12 
13 # Load data
14 if not isfile('tmva_reg_example.root'):
15  call(['curl', '-O', 'http://root.cern.ch/files/tmva_reg_example.root'])
16 
17 data = TFile.Open('tmva_reg_example.root')
18 tree = data.Get('TreeR')
19 
20 branches = {}
21 for branch in tree.GetListOfBranches():
22  branchName = branch.GetName()
23  branches[branchName] = array('f', [-999])
24  tree.SetBranchAddress(branchName, branches[branchName])
25  if branchName != 'fvalue':
26  reader.AddVariable(branchName, branches[branchName])
27 
28 # Book methods
29 reader.BookMVA('PyKeras', TString('dataset/weights/TMVAClassification_PyKeras.weights.xml'))
30 
31 # Print some example regressions
32 print('Some example regressions:')
33 for i in range(20):
34  tree.GetEntry(i)
35  print('True/MVA value: {}/{}'.format(branches['fvalue'][0],reader.EvaluateMVA('PyKeras')))
static Tools & Instance()
Definition: Tools.cxx:75
static std::string format(double x, double y, int digits, int width)
static void PyInitialize()
Initialize Python interpreter.
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:3909
The Reader class serves to use the MVAs in a specific analysis context.
Definition: Reader.h:63