18from xgboost
import XGBClassifier
23from tmva100_DataPreparation
import variables
26def load_data(signal_filename, background_filename):
32 x_sig = np.vstack([data_sig[var]
for var
in variables]).T
33 x_bkg = np.vstack([data_bkg[var]
for var
in variables]).T
34 x = np.vstack([x_sig, x_bkg])
37 num_sig = x_sig.shape[0]
38 num_bkg = x_bkg.shape[0]
39 y = np.hstack([np.ones(num_sig), np.zeros(num_bkg)])
42 num_all = num_sig + num_bkg
43 w = np.hstack([np.ones(num_sig) * num_all / num_sig, np.ones(num_bkg) * num_all / num_bkg])
47if __name__ ==
"__main__":
49 x, y, w = load_data(
"train_signal.root",
"train_background.root")
52 bdt = XGBClassifier(max_depth=3, n_estimators=500)
53 bdt.fit(x, y, sample_weight=w)
56 print(
"Training done on ",x.shape[0],
"events. Saving model in tmva101.root")
57 ROOT.TMVA.Experimental.SaveXGBoost(bdt,
"myBDT",
"tmva101.root", num_inputs=x.shape[1])
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...