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
scaler.Fit(x);
// 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));
}
h1.SetLineWidth(2);
h1.SetLineColor(kRed);
h2.SetLineWidth(2);
h2.SetLineColor(kBlue);
auto c = new TCanvas("", "", 800, 800);
h2.Draw("HIST");
h1.Draw("HIST SAME");
TLegend legend(0.7, 0.7, 0.89, 0.89);
legend.SetBorderSize(0);
legend.AddEntry("h1", "Unscaled", "l");
legend.AddEntry("h2", "Scaled", "l");
legend.Draw();
c->DrawClone();
}
Date
July 2019
Author
Stefan Wunsch

Definition in file tmva004_RStandardScaler.C.

c
#define c(i)
Definition: RSha256.hxx:119
TPave::SetBorderSize
virtual void SetBorderSize(Int_t bordersize=4)
Definition: TPave.h:79
x
Double_t x[n]
Definition: legend1.C:17
ROOT::RDataFrame
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
Definition: RDataFrame.hxx:42
h1
TH1F * h1
Definition: legend1.C:5
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TMVA::Experimental::RStandardScaler::Compute
std::vector< T > Compute(const std::vector< T > &x)
Definition: RStandardScaler.hxx:83
TLegend::AddEntry
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:330
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3274
y
Double_t y[n]
Definition: legend1.C:17
kRed
@ kRed
Definition: Rtypes.h:66
TStyle::SetOptStat
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:1592
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
TCanvas
Definition: TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
TMVA::Experimental
Definition: Classification.h:127
TMVA::Experimental::RStandardScaler
Definition: RStandardScaler.hxx:16
kBlue
@ kBlue
Definition: Rtypes.h:66
TLegend::Draw
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:423
TMVA::Experimental::RStandardScaler::Fit
void Fit(const RTensor< T > &x)
Definition: RStandardScaler.hxx:52
TLegend
Definition: TLegend.h:23
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997