Logo ROOT   6.08/07
Reference Guide
ApplicationClassificationKeras.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_class_example.root'):
15  call(['curl', '-O', 'http://root.cern.ch/files/tmva_class_example.root'])
16 
17 data = TFile.Open('tmva_class_example.root')
18 signal = data.Get('TreeS')
19 background = data.Get('TreeB')
20 
21 branches = {}
22 for branch in signal.GetListOfBranches():
23  branchName = branch.GetName()
24  branches[branchName] = array('f', [-999])
25  reader.AddVariable(branchName, branches[branchName])
26  signal.SetBranchAddress(branchName, branches[branchName])
27  background.SetBranchAddress(branchName, branches[branchName])
28 
29 # Book methods
30 reader.BookMVA('PyKeras', TString('dataset/weights/TMVAClassification_PyKeras.weights.xml'))
31 
32 # Print some example classifications
33 print('Some signal example classifications:')
34 for i in range(20):
35  signal.GetEntry(i)
36  print(reader.EvaluateMVA('PyKeras'))
37 print('')
38 
39 print('Some background example classifications:')
40 for i in range(20):
41  background.GetEntry(i)
42  print(reader.EvaluateMVA('PyKeras'))
static Tools & Instance()
Definition: Tools.cxx:80
static void PyInitialize()
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