Belle II Software  release-06-02-00
xgboost_default.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2_mva
12 import basf2_mva_util
13 import time
14 
15 if __name__ == "__main__":
16  from basf2 import conditions
17  # NOTE: do not use testing payloads in production! Any results obtained like this WILL NOT BE PUBLISHED
18  conditions.testing_payloads = [
19  'localdb/database.txt'
20  ]
21 
22  variables = ['M', 'p', 'pt', 'pz',
23  'daughter(0, p)', 'daughter(0, pz)', 'daughter(0, pt)',
24  'daughter(1, p)', 'daughter(1, pz)', 'daughter(1, pt)',
25  'daughter(2, p)', 'daughter(2, pz)', 'daughter(2, pt)',
26  'chiProb', 'dr', 'dz',
27  'daughter(0, dr)', 'daughter(1, dr)',
28  'daughter(0, dz)', 'daughter(1, dz)',
29  'daughter(0, chiProb)', 'daughter(1, chiProb)', 'daughter(2, chiProb)',
30  'daughter(0, kaonID)', 'daughter(0, pionID)',
31  'daughterInvariantMass(0, 1)', 'daughterInvariantMass(0, 2)', 'daughterInvariantMass(1, 2)']
32 
33  general_options = basf2_mva.GeneralOptions()
34  general_options.m_datafiles = basf2_mva.vector("train.root")
35  general_options.m_treename = "tree"
36  general_options.m_identifier = "XGBoost"
37  general_options.m_variables = basf2_mva.vector(*variables)
38  general_options.m_target_variable = "isSignal"
39 
40  specific_options = basf2_mva.PythonOptions()
41  specific_options.m_steering_file = 'mva/examples/python/xgboost_default.py'
42  specific_options.m_framework = "xgboost"
43  param = ('{"max_depth": 3, "eta": 0.1, "silent": 1, "objective": "binary:logistic",'
44  '"subsample": 0.5, "nthread": 1, "nTrees": 100}')
45  specific_options.m_config = param
46 
47  test_data = ["test.root"] * 10
48  training_start = time.time()
49  basf2_mva.teacher(general_options, specific_options)
50  training_stop = time.time()
51  training_time = training_stop - training_start
52  method = basf2_mva_util.Method(general_options.m_identifier)
53  inference_start = time.time()
54  p, t = method.apply_expert(basf2_mva.vector(*test_data), general_options.m_treename)
55  inference_stop = time.time()
56  inference_time = inference_stop - inference_start
58  print("XGBoost", training_time, inference_time, auc)
def calculate_roc_auc(p, t)