3from ROOT
import TMVA, TFile, TTree, TCut
4from subprocess
import call
5from os.path
import isfile
7from keras.models
import Sequential
8from keras.layers
import Dense, Activation
9from keras.regularizers
import l2
10from keras.optimizers
import SGD
18 '!V:!Silent:Color:DrawProgressBar:Transformations=D,G:AnalysisType=Classification')
21if not isfile(
'tmva_class_example.root'):
22 call([
'curl',
'-O',
'http://root.cern.ch/files/tmva_class_example.root'])
25signal = data.Get(
'TreeS')
26background = data.Get(
'TreeB')
29for branch
in signal.GetListOfBranches():
30 dataloader.AddVariable(branch.GetName())
32dataloader.AddSignalTree(signal, 1.0)
33dataloader.AddBackgroundTree(background, 1.0)
34dataloader.PrepareTrainingAndTestTree(TCut(
''),
35 'nTrain_Signal=4000:nTrain_Background=4000:SplitMode=Random:NormMode=NumEvents:!V')
41model.add(Dense(64, activation=
'relu', W_regularizer=l2(1e-5), input_dim=4))
42model.add(Dense(2, activation=
'softmax'))
45model.compile(loss=
'categorical_crossentropy',
46 optimizer=SGD(lr=0.01), metrics=[
'accuracy', ])
53factory.BookMethod(dataloader, TMVA.Types.kFisher,
'Fisher',
54 '!H:!V:Fisher:VarTransform=D,G')
55factory.BookMethod(dataloader, TMVA.Types.kPyKeras,
'PyKeras',
56 'H:!V:VarTransform=D,G:FilenameModel=model.h5:NumEpochs=20:BatchSize=32')
59factory.TrainAllMethods()
60factory.TestAllMethods()
61factory.EvaluateAllMethods()
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.
This is the main MVA steering class.
static void PyInitialize()
Initialize Python interpreter.