This tutorial show how you can train a machine learning model with any package reading the training data directly from ROOT files.
Using XGBoost, we illustrate how you can convert an externally trained model in a format serializable and readable with the fast tree inference engine offered by TMVA.
from xgboost import XGBClassifier
import ROOT
import numpy as np
from tmva100_DataPreparation import variables
def load_data(signal_filename, background_filename):
x_sig =
np.vstack([data_sig[var]
for var
in variables]).T
x_bkg =
np.vstack([data_bkg[var]
for var
in variables]).T
num_all = num_sig + num_bkg
return x, y, w
if __name__ == "__main__":
x, y, w =
load_data(
"train_signal.root",
"train_background.root")
print(
"Training done on ",
x.shape[0],
"events. Saving model in tmva101.root")
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Training done on 153906 events. Saving model in tmva101.root
- Date
- August 2019
- Author
- Stefan Wunsch
Definition in file tmva101_Training.py.