5 from root_pandas
import to_root, read_root
7 from matplotlib
import pyplot
as plt
10 def train_mva_method(file_name):
11 weight_file =
"weightfile.root"
13 general_options = basf2_mva.GeneralOptions()
14 general_options.m_datafiles = basf2_mva.vector(file_name)
15 general_options.m_treename =
"tree"
16 general_options.m_identifier = weight_file
17 general_options.m_variables = basf2_mva.vector(
'A',
'B')
18 general_options.m_target_variable =
'C'
20 regression_fastbdt_options = basf2_mva.RegressionFastBDTOptions()
22 regression_fastbdt_options.setMaximalBinNumber(20)
27 basf2_mva.teacher(general_options, regression_fastbdt_options)
32 def create_random_data():
33 file_name =
"data.root"
36 df = pd.DataFrame({
"A": np.random.rand(1000),
"B": np.random.rand(1000)})
37 df[
"C"] = (df.A + df.B) / 2
39 to_root(df, file_name, store_index=
False, key=
"tree")
43 def apply_expert(file_name, weight_file):
44 output_file =
'expert.root'
45 basf2_mva.expert(basf2_mva.vector(weight_file), basf2_mva.vector(file_name),
'tree', output_file)
49 def create_plot(expert_file):
50 df = read_root(expert_file)
51 df.plot.scatter(
"weightfile__ptroot_C",
"weightfile__ptroot", ax=plt.gca())
54 plt.savefig(
"result.pdf")
57 if __name__ ==
"__main__":
58 from basf2
import conditions
60 conditions.testing_payloads = [
61 'localdb/database.txt'
65 file_name = create_random_data()
68 weight_file = train_mva_method(file_name)
71 expert_file = apply_expert(file_name, weight_file)
74 create_plot(expert_file)