13.6.1. Macro “modelerCornellLinearRegression.C

13.6.1.1. Objective

The objective of the macro is to build a multilinear regression between the predictors related to the normalisation of the variables x1, x2, x3, x4, x5, x6, x7 and a target variable y from the database contained in the ASCII file cornell.dat:

#NAME: cornell
#TITLE: Dataset Cornell 1990
#COLUMN_NAMES: x1 | x2 | x3 | x4 | x5 | x6 | x7 | y
#COLUMN_TITLES: x_{1} | x_{2} | x_{3} | x_{4} | x_{5} | x_{6} | x_{7} | y

0.00 0.23 0.00 0.00 0.00 0.74 0.03 98.7
0.00 0.10 0.00 0.00 0.12 0.74 0.04 97.8
0.00 0.00 0.00 0.10 0.12 0.74 0.04 96.6
0.00 0.49 0.00 0.00 0.12 0.37 0.02 92.0
0.00 0.00 0.00 0.62 0.12 0.18 0.08 86.6
0.00 0.62 0.00 0.00 0.00 0.37 0.01 91.2
0.17 0.27 0.10 0.38 0.00 0.00 0.08 81.9
0.17 0.19 0.10 0.38 0.02 0.06 0.08 83.1
0.17 0.21 0.10 0.38 0.00 0.06 0.08 82.4
0.17 0.15 0.10 0.38 0.02 0.10 0.08 83.2
0.21 0.36 0.12 0.25 0.00 0.00 0.06 81.4
0.00 0.00 0.00 0.55 0.00 0.37 0.08 88.1

13.6.1.2. Macro Uranie

    TDataServer * tds = new TDataServer();

    tds->fileDataRead("cornell.dat");

    tds->normalize("*", "cr");  // ("x1:x2:x3:x4:x5:x6:y", "cr", TDataServer::kCR)
 
    TCanvas *c = new TCanvas("c1", "Graph for the Macro modeler",5,64,1270,667);
    TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
    pad->Divide(2);
    pad->cd(1);
    tds->draw("y:x7");

    TLinearRegression *tlin = new TLinearRegression(tds,"x1cr:x2cr:x3cr:x4cr:x5cr:x6cr", "ycr", "nointercept");
    tlin->estimate();  

    pad->cd(2);
    tds->draw("ycr:ycrhat");

The ASCII data file cornell.dat is loaded in the TDataServer:

    TDataServer * tds = new TDataServer();
    tds->fileDataRead("cornell.dat");

The variables are all normalised with a standardised method. The normalised attributes are created with the cr extension:

    tds->normalize("*", "cr");  // ("x1:x2:x3:x4:x5:x6:y", "cr", TDataServer::kCR)

The linear regression is initialised and characteristic values are computed for each normalised variable with the estimate method. The regression is built with no intercept:

    TLinearRegression *tlin = new TLinearRegression(tds,"x1cr:x2cr:x3cr:x4cr:x5cr:x6cr", "ycr", "nointercept");
    tlin->estimate();  

13.6.1.3. Graph

../../_images/modelerCornellLinearRegression.png

Figure 13.37 Graph of the macro “modelerCornellLinearRegression.C”