Logo ROOT   6.16/01
Reference Guide
ApplicationRegressionKeras.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3from ROOT import TMVA, TFile, TString
4from array import array
5from subprocess import call
6from os.path import isfile
7
8# Setup TMVA
11reader = TMVA.Reader("Color:!Silent")
12
13# Load data
14if not isfile('tmva_reg_example.root'):
15 call(['curl', '-O', 'http://root.cern.ch/files/tmva_reg_example.root'])
16
17data = TFile.Open('tmva_reg_example.root')
18tree = data.Get('TreeR')
19
20branches = {}
21for 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
29reader.BookMVA('PyKeras', TString('dataset/weights/TMVARegression_PyKeras.weights.xml'))
30
31# Print some example regressions
32print('Some example regressions:')
33for i in range(20):
34 tree.GetEntry(i)
35 print('True/MVA value: {}/{}'.format(branches['fvalue'][0],reader.EvaluateMVA('PyKeras')))
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3975
static void PyInitialize()
Initialize Python interpreter.
The Reader class serves to use the MVAs in a specific analysis context.
Definition: Reader.h:63
static Tools & Instance()
Definition: Tools.cxx:75