本文整理汇总了Python中trainer.Trainer.useTransformations方法的典型用法代码示例。如果您正苦于以下问题:Python Trainer.useTransformations方法的具体用法?Python Trainer.useTransformations怎么用?Python Trainer.useTransformations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trainer.Trainer
的用法示例。
在下文中一共展示了Trainer.useTransformations方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1:
# 需要导入模块: from trainer import Trainer [as 别名]
# 或者: from trainer.Trainer import useTransformations [as 别名]
#trainerSub=Trainer(trainingPath+"tth_nominal.root",trainingPath+"tbar_nominal.root",SubBDTOptions,variablesSub,[],False,"weights/weights_Sub.xml")
#trainerSub.useTransformations(False)
#trainerSub.setWeightExpression("Weight_XS")
##trainerSub.run(variablesSub, 2000,0.001,0.5, 40,2)
#trainerSub.run(variablesSub,SubBDTOptions)
#f.write("SubBDT Parameters:\n")
#f.write(SubBDTOptions+"\n\n")
#samplesTrainingSub=[Sample("tth",trainingPath+"tth_nominal.root",-1,1.),Sample("ttbar_nominal",trainingPath+"Training_ttbar_bb.root",.5,1.),Sample("ttbar_b",trainingPath+"Training_ttbar_b.root",.5,1.),Sample("ttbar_cc",trainingPath+"Training_ttbar_cc.root",.5,1.),Sample("ttbar_light",trainingPath+"Training_ttbar_l.root",.5,1.),Sample("ttbar",trainingPath+"Training_ttbar.root",.1,1.)]
#print "Writing SubBDT output"
#weightfileSub=trainerSub.weightfile
#evaluaterSub=Evaluater(weightfileSub,variablesSub,samplesTrainingSub,[],[])
#evaluaterSub.WriteBDTVars("","_SubBDT","Sub")
print "Training Final BDT"
trainerFinal=Trainer(trainingPath+"tth_nominal.root",trainingPath+"ttbar_nominal.root",evaluationPath+"tth_nominal.root",evaluationPath+"ttbar_nominal.root",FinalBDTOptions,variablesFinal,[],False,"weights/weights_Final_"+category+"_"+name+".xml")
trainerFinal.useTransformations(False)
trainerFinal.setWeightExpression("Weight_XS")
trainerFinal.run(variablesFinal,FinalBDTOptions)
f.write("FinalBDT Parameters:\n")
f.write(FinalBDTOptions+"\n\n")
f.close()
samplesTrainingFinal=[Sample("tth",trainingPath+"tth_nominal.root",-1,1.),Sample("ttbar_light",trainingPath+"ttbar_l_nominal.root",.1,1.),Sample("ttbar_b",trainingPath+"ttbar_b_nominal.root",.5,1.),Sample("ttbar_bb",trainingPath+"ttbar_bb_nominal.root",.5,1.),Sample("ttbar_2b",trainingPath+"ttbar_2b_nominal.root",.5,1.),Sample("ttbar_cc",trainingPath+"ttbar_cc_nominal.root",.5,1.),Sample("ttbar",trainingPath+"ttbar_nominal.root",.1,1.),Sample("SingleT",trainingPath+"SingleT_nominal.root",0.031,1.),Sample("DiBoson",trainingPath+"DiBoson_nominal.root",0.07,1.),Sample("ttW",trainingPath+"ttW_nominal.root",0.139,1.),Sample("ttZ",trainingPath+"ttZ_nominal.root",0.124,1.)]
dataTrain=Sample("data",trainingPath+"MCData.root",-1,1.)
print "Writing FinalBDT output"
weightfileFinal=trainerFinal.weightfile
evaluaterFinal=Evaluater(weightfileFinal,variablesFinal,samplesTrainingFinal,[],[])
evaluaterFinal.WriteBDTVars("","_FinalBDT","Final")
示例2: selection
# 需要导入模块: from trainer import Trainer [as 别名]
# 或者: from trainer.Trainer import useTransformations [as 别名]
"BDTOhio_v2_input_h1"]
#samples have a name, a color, a path, and a selection (not implemented yet for training)
#only the path is really relevant atm
cat='6j4t'
signal_test=Sample('t#bar{t}H test',ROOT.kBlue,'/nfs/dust/cms/user/hmildner/mva-training/trees/tthbb_fast_'+cat+'_even.root','')
signal_train=Sample('t#bar{t}H training',ROOT.kGreen,'/nfs/dust/cms/user/hmildner/mva-training/trees/tthbb_fast_'+cat+'_odd.root','')
background_test=Sample('t#bar{t} test',ROOT.kRed+1,'/nfs/dust/cms/user/hmildner/mva-training/trees/ttbar_'+cat+'_even.root','')
background_train=Sample('t#bar{t} training',ROOT.kRed-1,'/nfs/dust/cms/user/hmildner/mva-training/trees/ttbar_'+cat+'_odd.root','')
trainer=Trainer(variables,addtional_variables)
trainer.addSamples(signal_train,background_train,signal_test,background_test) #add the sample defined above
trainer.setTreeName('MVATree') # name of tree in files
trainer.setReasonableDefaults() # set some configurations to reasonable values
trainer.setEqualNumEvents(True) # reweight events so that integral in training and testsample is the same
trainer.useTransformations(False) # faster this way
trainer.setVerbose(False) # no output during BDT training and testing
trainer.setWeightExpression('Weight')
trainer.setSelection('N_Jets>=6&&N_BTagsM>=4') # selection for category (not necessary if trees are split)
trainer.removeWorstUntil(10) # removes worst variable until only 10 are left
trainer.optimizeOption('NTrees') # optimizies the number of trees by trying more and less trees # you need to reoptimize ntrees depending on the variables and on other parameters
trainer.addBestUntil(12) # add best variables until 12 are used
trainer.optimizeOption('NTrees')
trainer.removeWorstUntil(10)
trainer.optimizeOption('NTrees')
trainer.removeWorstUntil(8)
trainer.optimizeOption('NTrees')
print "these are found to be the 8 best variables and best bdt and factory options"
print trainer.best_variables
print trainer.bdtoptions
print trainer.factoryoptions
示例3:
# 需要导入模块: from trainer import Trainer [as 别名]
# 或者: from trainer.Trainer import useTransformations [as 别名]
#change path if necessary
signal_test=Sample('t#bar{t}H test',ROOT.kBlue,"../../atlas-higgs-challenge-2014-v2.root",'')
signal_train=Sample('t#bar{t}H training',ROOT.kGreen,"../../atlas-higgs-challenge-2014-v2.root",'')
background_test=Sample('t#bar{t} test',ROOT.kRed+1,"../../atlas-higgs-challenge-2014-v2.root",'')
background_train=Sample('t#bar{t} training',ROOT.kRed-1,"../../atlas-higgs-challenge-2014-v2.root",'')
#create trainer and set trainer options
trainer=Trainer(variables,addtional_variables)
#trainer.addSamples(signal_train,background_train)
trainer.addSamples(signal_train,background_train,signal_test,background_test) #add the sample defined above
trainer.setSTreeName('signal') # name of signaltree in files
trainer.setBTreeName('background') # name of backgroundtree in files
trainer.setReasonableDefaults() # set some configurations to reasonable values
trainer.setEqualNumEvents(True) # reweight events so that integral in training and testsample is the same
trainer.useTransformations(True) # faster this way
trainer.setVerbose(True) # no output during BDT training and testing
trainer.setWeightExpression('Weight')
#set BDT options
trainer.setBDTOption("NTrees=10")
trainer.setBDTOption("Shrinkage=0.01")
trainer.setBDTOption("nCuts=50")
trainer.setBDTOption("MaxDepth=2")
print trainer.best_variables
trainer.trainBDT(variables)
ROC, ksS, ksB, ROCT = trainer.evaluateLastTraining()
trainer.SetPlotFile()
trainer.SetLogFile()
trainer.OpenPDF()