15if __name__ ==
"__main__":
16 from basf2
import conditions, find_file
18 conditions.testing_payloads = [
19 'localdb/database.txt'
22 train_file = find_file(
"mva/train_D0toKpipi.root",
"examples")
23 test_file = find_file(
"mva/test_D0toKpipi.root",
"examples")
25 training_data = basf2_mva.vector(train_file)
26 testing_data = basf2_mva.vector(test_file)
49 'daughter(0, chiProb)',
50 'daughter(1, chiProb)',
51 'daughter(2, chiProb)',
52 'daughter(0, kaonID)',
53 'daughter(0, pionID)',
59 general_options = basf2_mva.GeneralOptions()
60 general_options.m_datafiles = training_data
61 general_options.m_treename =
"tree"
62 general_options.m_identifier =
"MVADatabaseIdentifier"
63 general_options.m_variables = basf2_mva.vector(*variables)
64 general_options.m_target_variable =
"isSignal"
66 fastbdt_options = basf2_mva.FastBDTOptions()
67 fastbdt_options.m_nTrees = 100
68 fastbdt_options.m_nCuts = 10
69 fastbdt_options.m_nLevels = 3
70 fastbdt_options.m_shrinkage = 0.2
71 fastbdt_options.m_randRatio = 0.5
73 fastbdt_pt_options = basf2_mva.FastBDTOptions()
74 fastbdt_pt_options.m_nTrees = 100
75 fastbdt_pt_options.m_nCuts = 10
76 fastbdt_pt_options.m_nLevels = 3
77 fastbdt_pt_options.m_shrinkage = 0.2
78 fastbdt_pt_options.m_randRatio = 0.5
79 fastbdt_pt_options.m_purityTransformation =
True
82 for label, options
in [(
"FastBDT", fastbdt_options), (
"FastBDT_PT", fastbdt_pt_options)]:
83 training_start = time.time()
84 general_options.m_identifier = label
85 basf2_mva.teacher(general_options, options)
86 training_stop = time.time()
87 training_time = training_stop - training_start
89 inference_start = time.time()
90 p, t = method.apply_expert(testing_data, general_options.m_treename)
91 inference_stop = time.time()
92 inference_time = inference_stop - inference_start
94 print(label, training_time, inference_time, auc)
95 stats.append((label, training_time, inference_time, auc))
def calculate_auc_efficiency_vs_background_retention(p, t, w=None)