Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ApplicationClassificationKeras.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_tmva_keras
3## \notebook -nodraw
4## This tutorial shows how to apply a trained model to new data.
5##
6## \macro_code
7##
8## \date 2017
9## \author TMVA Team
10
11from ROOT import TMVA, TFile, TString, gROOT
12from array import array
13from subprocess import call
14from os.path import isfile
15
16# Setup TMVA
19reader = TMVA.Reader("Color:!Silent")
20
21# Load data
22data = TFile.Open(str(gROOT.GetTutorialDir()) + "/machine_learning/data/tmva_class_example.root")
23signal = data.Get('TreeS')
24background = data.Get('TreeB')
25
26branches = {}
27for branch in signal.GetListOfBranches():
28 branchName = branch.GetName()
29 branches[branchName] = array('f', [-999])
30 reader.AddVariable(branchName, branches[branchName])
31 signal.SetBranchAddress(branchName, branches[branchName])
32 background.SetBranchAddress(branchName, branches[branchName])
33
34# Book methods
35reader.BookMVA('PyKeras', TString('dataset/weights/TMVAClassification_PyKeras.weights.xml'))
36
37# Print some example classifications
38print('Some signal example classifications:')
39for i in range(20):
41 print(reader.EvaluateMVA('PyKeras'))
42print('')
43
44print('Some background example classifications:')
45for i in range(20):
47 print(reader.EvaluateMVA('PyKeras'))
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
The Reader class serves to use the MVAs in a specific analysis context.
Definition Reader.h:64
Basic string class.
Definition TString.h:139