Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ml_dataloader_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 the ROOT ML dataloader
12##################################################
13
14import ROOT
15
16tree_name = "test_tree"
17file_name = ROOT.gROOT.GetTutorialDir().Data() + "/machine_learning/ml_dataloader_filters_vectors_hvector.root"
18
19batch_size = 5 # Defines the size of the returned batches
20
21rdataframe = ROOT.RDataFrame(tree_name, file_name)
22
23# Define filters, filters must be named
24filteredrdf = (
25 rdataframe.Filter("f1 > 30", "first_filter").Filter("f2 < 70", "second_filter").Filter("f3==true", "third_filter")
26)
27
28max_vec_sizes = {"f4": 3, "f5": 2, "f6": 1}
29
31 filteredrdf,
32 batch_size,
33 max_vec_sizes=max_vec_sizes,
34 shuffle=False,
35)
36
37ds_train, ds_validation = dl.train_test_split(test_size=0.3)
38
39print(f"Columns: {ds_train.columns}")
40
41for i, b in enumerate(ds_train.as_numpy()):
42 print(f"Training batch {i} => {b.shape}")
43
45 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 ,...