Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RBatchGenerator_filters_vectors.py
Go to the documentation of this file.
1### \file
2### \ingroup tutorial_ml
3### \notebook -nodraw
4###
5### \macro_code
6### \macro_output
7### \author Dante Niewenhuis
8
9##################################################
10# This tutorial shows the usage of filters and vectors
11# when using RBatchGenerator
12##################################################
13
14import ROOT
15
16tree_name = "test_tree"
17file_name = (
19 + "/machine_learning/RBatchGenerator_filters_vectors_hvector.root"
20)
21
22chunk_size = 50 # Defines the size of the chunks
23batch_size = 5 # Defines the size of the returned batches
24block_size = 10 # Defines the size of the blocks that builds up a chunk
25
26rdataframe = ROOT.RDataFrame(tree_name, file_name)
27
28# Define filters, filters must be named
29filteredrdf = rdataframe.Filter("f1 > 30", "first_filter")\
30 .Filter("f2 < 70", "second_filter")\
31 .Filter("f3==true", "third_filter")
32
33max_vec_sizes = {"f4": 3, "f5": 2, "f6": 1}
34
35ds_train, ds_validation = ROOT.TMVA.Experimental.CreateNumPyGenerators(
36 filteredrdf,
37 batch_size,
38 chunk_size,
39 block_size,
40 validation_split=0.3,
41 max_vec_sizes=max_vec_sizes,
42 shuffle=False,
43)
44
45print(f"Columns: {ds_train.columns}")
46
47for i, b in enumerate(ds_train):
48 print(f"Training batch {i} => {b.shape}")
49
50for i, b in enumerate(ds_validation):
51 print(f"Validation batch {i} => {b.shape}")
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 ,...