13 from root_pandas
import to_root, read_root
15 from matplotlib
import pyplot
as plt
18 def train_mva_method(file_name):
19 weight_file =
"weightfile.root"
21 general_options = basf2_mva.GeneralOptions()
22 general_options.m_datafiles = basf2_mva.vector(file_name)
23 general_options.m_treename =
"tree"
24 general_options.m_identifier = weight_file
25 general_options.m_variables = basf2_mva.vector(
'A',
'B')
26 general_options.m_target_variable =
'C'
28 regression_fastbdt_options = basf2_mva.RegressionFastBDTOptions()
30 regression_fastbdt_options.setMaximalBinNumber(20)
35 basf2_mva.teacher(general_options, regression_fastbdt_options)
40 def create_random_data():
41 file_name =
"data.root"
44 df = pd.DataFrame({
"A": np.random.rand(1000),
"B": np.random.rand(1000)})
45 df[
"C"] = (df.A + df.B) / 2
47 to_root(df, file_name, store_index=
False, key=
"tree")
51 def apply_expert(file_name, weight_file):
52 output_file =
'expert.root'
53 basf2_mva.expert(basf2_mva.vector(weight_file), basf2_mva.vector(file_name),
'tree', output_file)
57 def create_plot(expert_file):
58 df = read_root(expert_file)
59 df.plot.scatter(
"weightfile__ptroot_C",
"weightfile__ptroot", ax=plt.gca())
62 plt.savefig(
"result.pdf")
65 if __name__ ==
"__main__":
66 from basf2
import conditions
68 conditions.testing_payloads = [
69 'localdb/database.txt'
73 file_name = create_random_data()
76 weight_file = train_mva_method(file_name)
79 expert_file = apply_expert(file_name, weight_file)
82 create_plot(expert_file)