3from ROOT
import TMVA, TFile, TTree, TCut
4from subprocess
import call
5from os.path
import isfile
7from keras.models
import Sequential
8from keras.layers.core
import Dense, Activation
9from keras.regularizers
import l2
10from keras.optimizers
import SGD
18 '!V:!Silent:Color:DrawProgressBar:Transformations=D,G:AnalysisType=Regression')
21if not isfile(
'tmva_reg_example.root'):
22 call([
'curl',
'-O',
'http://root.cern.ch/files/tmva_reg_example.root'])
25tree = data.Get(
'TreeR')
28for branch
in tree.GetListOfBranches():
29 name = branch.GetName()
31 dataloader.AddVariable(name)
32dataloader.AddTarget(
'fvalue')
34dataloader.AddRegressionTree(tree, 1.0)
35dataloader.PrepareTrainingAndTestTree(TCut(
''),
36 'nTrain_Regression=4000:SplitMode=Random:NormMode=NumEvents:!V')
42model.add(Dense(64, activation=
'tanh', W_regularizer=l2(1e-5), input_dim=2))
43model.add(Dense(1, activation=
'linear'))
46model.compile(loss=
'mean_squared_error', optimizer=SGD(lr=0.01))
53factory.BookMethod(dataloader, TMVA.Types.kPyKeras,
'PyKeras',
54 'H:!V:VarTransform=D,G:FilenameModel=model.h5:NumEpochs=20:BatchSize=32')
55factory.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')
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.