13from ROOT
import TMVA, TFile, TTree, TCut
14from subprocess
import call
15from os.path
import isfile
17from keras.models
import Sequential
18from keras.layers.core
import Dense, Activation
19from keras.regularizers
import l2
20from keras.optimizers
import SGD
28 '!V:!Silent:Color:DrawProgressBar:Transformations=D,G:AnalysisType=Regression')
31if not isfile(
'tmva_reg_example.root'):
32 call([
'curl',
'-O',
'http://root.cern.ch/files/tmva_reg_example.root'])
35tree = data.Get(
'TreeR')
38for branch
in tree.GetListOfBranches():
39 name = branch.GetName()
41 dataloader.AddVariable(name)
42dataloader.AddTarget(
'fvalue')
44dataloader.AddRegressionTree(tree, 1.0)
45dataloader.PrepareTrainingAndTestTree(
TCut(
''),
46 'nTrain_Regression=4000:SplitMode=Random:NormMode=NumEvents:!V')
52model.add(Dense(64, activation=
'tanh', W_regularizer=l2(1e-5), input_dim=2))
53model.add(Dense(1, activation=
'linear'))
56model.compile(loss=
'mean_squared_error', optimizer=SGD(lr=0.01))
63factory.BookMethod(dataloader, TMVA.Types.kPyKeras,
'PyKeras',
64 'H:!V:VarTransform=D,G:FilenameModel=model.h5:NumEpochs=20:BatchSize=32')
65factory.BookMethod(dataloader, TMVA.Types.kBDT,
'BDTG',
66 '!H:!V:VarTransform=D,G:NTrees=1000:BoostType=Grad:Shrinkage=0.1:UseBaggedBoost:BaggedSampleFraction=0.5:nCuts=20:MaxDepth=4')
69factory.TrainAllMethods()
70factory.TestAllMethods()
71factory.EvaluateAllMethods()
A specialized string object used for TTree selections.
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.