13.7.1. Macro “modelerCornellLinearRegression.py”
13.7.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.7.1.2. Macro Uranie
"""
Example of linear regression model
"""
from URANIE import DataServer, Modeler
import ROOT
tds = DataServer.TDataServer()
tds.fileDataRead("cornell.dat")
tds.normalize("*", "cr") # "*" is equivalent to "x1:x2:x3:x4:x5:x6:y"
# Third field not filled implies DataServer.TDataServer.kCR
c = ROOT.TCanvas("c1", "Graph for the Macro modeler", 5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.Divide(2)
pad.cd(1)
tds.draw("y:x7")
tlin = Modeler.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:
tds = DataServer.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") # "*" is equivalent to "x1:x2:x3:x4:x5:x6:y"
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:
tlin = Modeler.TLinearRegression(tds, "x1cr:x2cr:x3cr:x4cr:x5cr:x6cr",
"ycr", "nointercept")
tlin.estimate()
13.7.1.3. Graph
Figure 13.37 Graph of the macro “modelerCornellLinearRegression.py”