add_classification_events(obj, events, labels, signal_label=None, weights=None, test=False)¶
Add classification events to a TMVA::Factory or TMVA::DataLoader from NumPy arrays.
obj : TMVA::Factory or TMVA::DataLoader
A TMVA::Factory or TMVA::DataLoader (TMVA’s interface as of ROOT 6.07/04) instance with variables already booked in exactly the same order as the columns in
events : numpy array of shape [n_events, n_variables]
A two-dimensional NumPy array containing the rows of events and columns of variables. The order of the columns must match the order in which you called
AddVariable()for each variable.
labels : numpy array of shape [n_events]
The class labels (signal or background) corresponding to each event in
signal_label : float or int, optional (default=None)
The value in
labelsfor signal events, if
labelscontains only two classes. If None, the highest value in
weights : numpy array of shape [n_events], optional
test : bool, optional (default=False)
If True, then the events will be added as test events, otherwise they are added as training events by default.
A TMVA::Factory or TMVA::DataLoader requires you to add both training and test events even if you don’t intend to call
When using MethodCuts, the first event added must be a signal event, otherwise TMVA will fail with
<FATAL> Interval : maximum lower than minimum. To place a signal event first:
# Get index of first signal event first_signal = np.nonzero(labels == signal_label) # Swap this with first event events, events[first_signal] = events[first_signal].copy(), events.copy() labels, labels[first_signal] = labels[first_signal], labels weights, weights[first_signal] = weights[first_signal], weights