Logo ROOT  
Reference Guide
tmva004_RStandardScaler.C File Reference

Detailed Description

View in nbviewer Open in SWAN
This tutorial illustrates the usage of the standard scaler as preprocessing method.

using namespace TMVA::Experimental;
void tmva004_RStandardScaler()
// Load data used to fit the parameters
ROOT::RDataFrame df("TreeS", "http://root.cern/files/tmva_class_example.root");
auto x = AsTensor<float>(df);
// Create standard scaler and fit to data
// Compute transformation
auto y = scaler.Compute(x);
// Plot first variable scaled and unscaled
TH1F h1("h1", ";x_{4};N_{Events}", 20, -4, 4);
TH1F h2("h2", ";x_{4};N_{Events}", 20, -4, 4);
for (std::size_t i = 0; i < x.GetShape()[0]; i++) {
h1.Fill(x(i, 3));
h2.Fill(y(i, 3));
auto c = new TCanvas("", "", 800, 800);
h1.Draw("HIST SAME");
TLegend legend(0.7, 0.7, 0.89, 0.89);
legend.AddEntry("h1", "Unscaled", "l");
legend.AddEntry("h2", "Scaled", "l");
#define c(i)
Definition: RSha256.hxx:101
@ kRed
Definition: Rtypes.h:66
@ kBlue
Definition: Rtypes.h:66
R__EXTERN TStyle * gStyle
Definition: TStyle.h:427
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Definition: RDataFrame.hxx:40
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:577
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3338
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition: TH1.cxx:3060
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:23
void Fit(const RTensor< T > &x)
std::vector< T > Compute(const std::vector< T > &x)
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:1594
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
TH1F * h1
Definition: legend1.C:5
July 2019
Stefan Wunsch

Definition in file tmva004_RStandardScaler.C.