Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
tmva004_RStandardScaler.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_ml
3/// \notebook -nodraw
4/// This tutorial illustrates the usage of the standard scaler as preprocessing
5/// method.
6///
7/// \macro_code
8/// \macro_output
9///
10/// \date July 2019
11/// \author Stefan Wunsch
12
13using namespace TMVA::Experimental;
14
16{
17 // Load data used to fit the parameters
18
19
20 std::string inputFile = std::string(gROOT->GetTutorialDir()) + "/machine_learning/data/tmva_class_example.root";
21 inputFile);
22 auto x = AsTensor<float>(df);
23
24 // Create standard scaler and fit to data
26 scaler.Fit(x);
27
28 // Compute transformation
29 auto y = scaler.Compute(x);
30
31 // Plot first variable scaled and unscaled
32 TH1F h1("h1", ";x_{4};N_{Events}", 20, -4, 4);
33 h2("h2", ";x_{4};N_{Events}", 20, -4, 4);
34 for (std::size_t i = 0; i < x.GetShape()[0]; i++) {
35 h1.Fill(x(i, 3));
36 y(i, 3));
37 }
40 h2.SetLineWidth(2);
41 kBlue);
42
44 auto c = new TCanvas("", "", 800, 800);
45 h2.Draw("HIST");
46 h1.Draw("HIST SAME");
47
48 TLegend legend(0.7, 0.7, 0.89, 0.89);
49 legend.SetBorderSize(0);
50 legend.AddEntry("h1", "Unscaled", "l");
51 legend.AddEntry("h2", "Scaled", "l");
52 legend.Draw();
53
54 c->DrawClone();
55}
#define c(i)
Definition RSha256.hxx:101
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:42
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:650
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3316
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3038
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition TStyle.cxx:1642
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
TH1F * h1
Definition legend1.C:5