3 from ROOT
import TMVA, TFile, TTree, TCut
4 from subprocess
import call
5 from os.path
import isfile
7 from keras.models
import Sequential
8 from keras.layers.core
import Dense, Activation
9 from keras.regularizers
import l2
10 from keras.optimizers
import SGD
18 '!V:!Silent:Color:DrawProgressBar:Transformations=D,G:AnalysisType=Regression')
21 if not isfile(
'tmva_reg_example.root'):
22 call([
'curl',
'-O',
'http://root.cern.ch/files/tmva_reg_example.root'])
25 tree = data.Get(
'TreeR')
28 for branch
in tree.GetListOfBranches():
29 name = branch.GetName()
31 dataloader.AddVariable(name)
32 dataloader.AddTarget(
'fvalue')
34 dataloader.AddRegressionTree(tree, 1.0)
35 dataloader.PrepareTrainingAndTestTree(TCut(
''),
36 'nTrain_Regression=4000:SplitMode=Random:NormMode=NumEvents:!V')
42 model.add(Dense(64, activation=
'tanh', W_regularizer=l2(1e-5), input_dim=2))
43 model.add(Dense(1, activation=
'linear'))
46 model.compile(loss=
'mean_squared_error', optimizer=SGD(lr=0.01))
49 model.save(
'model.h5')
53 factory.BookMethod(dataloader, TMVA.Types.kPyKeras,
'PyKeras',
54 'H:!V:VarTransform=D,G:FilenameModel=model.h5:NumEpochs=20:BatchSize=32')
55 factory.BookMethod(dataloader, TMVA.Types.kBDT,
'BDTG',
56 '!H:!V:VarTransform=D,G:NTrees=1000:BoostType=Grad:Shrinkage=0.1:UseBaggedBoost:BaggedSampleFraction=0.5:nCuts=20:MaxDepth=4')
59 factory.TrainAllMethods()
60 factory.TestAllMethods()
61 factory.EvaluateAllMethods()
static void PyInitialize()
Initialize Python interpreter.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
This is the main MVA steering class.