The TREESPLIT Procedure

Example 21.2 Creating a Regression Tree

This example performs an analysis in which a linear regression model is fit. You can alternatively fit a regression tree to predict the salaries of Major League Baseball players based on their performance measures from the previous season by using almost identical code. Regression trees are piecewise constant models that, for relatively small data tables such as Sashelp.Baseball, provide succinct summaries of how the predictor variables determine the predictions. These models are usually easier to interpret than linear regression models. The Sashelp.Baseball data table contains salary and performance information for Major League Baseball players (excluding pitchers) who played at least one game in both the 1986 and 1987 seasons (Time Inc. 1987). You can load the Sashelp.Baseball data set into your CAS session by naming your CAS engine libref in the first statement of the following DATA step:

data mycas.baseball;
   set sashelp.baseball;
run;

The following statements create a regression tree model:

ods graphics on;

proc treesplit data=mycas.baseball maxdepth=3;
   class league division;
   model logSalary = nAtBat nHits nHome nRuns nRBI nBB
                     yrMajor crAtBat crHits crHome crRuns crRbi
                     crBB league division nOuts nAssts nError;
   output out=mycas.treesplout;
   prune none;
run;

Because no GROW statement is specified, the tree is grown using the RSS criterion by default. Because no PRUNE statement is included, no pruning is performed. The OUTPUT statement requests generation of the data table mycas.treesplout, which contains the predicted salary from the tree model for each observation.

Much of the output for a regression tree is identical to the output for a classification tree. Where there are differences, tables and plots are displayed and discussed on the following pages.

Output 21.2.1 displays the full regression tree.

Output 21.2.1: Overview Diagram of Regression Tree

Overview Diagram of Regression Tree


The final selected tree has eight leaves. In a regression tree, the shade of the leaves represents the predicted response value, which is the average observed logSalary for the observations in that leaf. Node E has the lowest predicted response value, indicated by the lightest shade of blue, and node 7 has the highest, indicated by the dark shade.

Output 21.2.2 shows details of the first three levels of the tree, including the root node.

Output 21.2.2: Detailed Diagram of Regression Tree

Detailed Diagram of Regression Tree


As in Output 21.1.3, this diagram displays split variables and split values for the nodes, along with the exact predicted response value, which is the average observed response, in each node.

Output 21.2.3 displays the fit statistic for the final regression tree (the only fit statistic provided for a regression tree is the ASE).

Output 21.2.3: Regression Tree Performance

The TREESPLIT Procedure

Fit Statistics for Selected
Tree
 Number
of Leaves
Average
Square Error
Training80.1664


Output 21.2.4 is a partial display of the mycas.treesplout data table that is created when you specify the OUTPUT statement.

Output 21.2.4: Scored Predictor Data Table

ObsP_logSalary_DT_PredStd__LeafID__Residual_
14.65554574260.306493646814.
26.85732015160.441026691270.6427120531
34.65554574260.3064936468140.4070505006
46.85732015160.44102669127-0.145745307
55.74772516850.326910170311-0.56219311
64.65554574260.306493646814.
76.85732015160.44102669127.
84.65554574260.306493646814-0.089386386
96.85732015160.441026691270.2023084645
106.359867210.53517727058-0.260205997


The variable P_logSalary contains the predicted salaries on the log scale. Note that all observations in the same leaf have the same predicted response. The OUT= data table can contain additional variables from the DATA= data table if you specify them by using the COPYVARS= option.

Last updated: December 21, 2018