Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
ApplicationClassificationKeras.py
Go to the documentation of this file.
1#!/usr/bin/env python
2## \file
3## \ingroup tutorial_tmva_keras
4## \notebook -nodraw
5## This tutorial shows how to apply a trained model to new data.
6##
7## \macro_code
8##
9## \date 2017
10## \author TMVA Team
11
12from ROOT import TMVA, TFile, TString, gROOT
13from array import array
14from subprocess import call
15from os.path import isfile
16
17# Setup TMVA
20reader = TMVA.Reader("Color:!Silent")
21
22# Load data
23data = TFile.Open(str(gROOT.GetTutorialDir()) + "/tmva/data/tmva_class_example.root")
24signal = data.Get('TreeS')
25background = data.Get('TreeB')
26
27branches = {}
28for branch in signal.GetListOfBranches():
29 branchName = branch.GetName()
30 branches[branchName] = array('f', [-999])
31 reader.AddVariable(branchName, branches[branchName])
32 signal.SetBranchAddress(branchName, branches[branchName])
33 background.SetBranchAddress(branchName, branches[branchName])
34
35# Book methods
36reader.BookMVA('PyKeras', TString('dataset/weights/TMVAClassification_PyKeras.weights.xml'))
37
38# Print some example classifications
39print('Some signal example classifications:')
40for i in range(20):
42 print(reader.EvaluateMVA('PyKeras'))
43print('')
44
45print('Some background example classifications:')
46for i in range(20):
48 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