Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
ApplicationRegressionKeras.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 (regression).
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_reg_example.root')
23tree = data.Get('TreeR')
24
25branches = {}
26for branch in tree.GetListOfBranches():
27 branchName = branch.GetName()
28 branches[branchName] = array('f', [-999])
29 tree.SetBranchAddress(branchName, branches[branchName])
30 if branchName != 'fvalue':
31 reader.AddVariable(branchName, branches[branchName])
32
33# Book methods
34reader.BookMVA('PyKeras', TString('dataset/weights/TMVARegression_PyKeras.weights.xml'))
35
36# Print some example regressions
37print('Some example regressions:')
38for i in range(20):
39 tree.GetEntry(i)
40 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::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:3787
static void PyInitialize()
Initialize Python interpreter.
The Reader class serves to use the MVAs in a specific analysis context.
Definition Reader.h:64
static Tools & Instance()
Definition Tools.cxx:72
Basic string class.
Definition TString.h:138