TREESPLIT Procedure

Example 34.5 Tuning the Hyperparameters of a Decision Tree

(View the complete code for this example.)

This example illustrates how you can use the AUTOTUNE statement in the TREESPLIT procedure to tune the hyperparameters of a decision tree. It uses the home equity data set Hmeq, which is in the Sampsio library.

The Hmeq data set contains 5,960 observations with 13 variables. The response variable, Bad, is a binary indicator to predict which clients will default on their loan.

The following statements load the data table Hmeq into your CAS session. For this example, the statements assume that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.

data mylib.hmeq;
   set sampsio.hmeq;
run;

The following statements use PROC TREESPLIT with the AUTOTUNE statement to automatically tune the hyperparameters of a decision tree:

ods graphics on;

proc treesplit data=mylib.hmeq;
   class Bad Reason;
   model Bad = CLAge CLNo DebtInc Derog
               Loan MortDue Reason Value;
   prune off;
   autotune
      /* Tuning Parameters
      You do not need to specify any tuning parameters for the default
      tuning process. If you want to make adjustments to the default
      tuning process, uncomment the following block of code and change
      any of the tuning parameters' attributes.

      tuningParameters=(
         CRITERION   ( values=GAIN GINI GAINRATIO
                  CHAID CHISQUARE init=GAINRATIO  )
         NUMBIN      ( lb=20    ub=200   init=20  )
         MAXDEPTH    ( lb=1     ub=19    init=10  )
         MINLEAFSIZE ( values=1 5 10 20 40 80 160 320 init=5 EXCLUDE  )
      )
      */
   ;
   /* Remove this line to see all results */
   ods select BestConfiguration EvaluationHistoryPlot IterationHistoryPlot;
run;

The preceding statements produce the table and the plots shown in Output 34.5.1 through Output 34.5.3. The table in Output 34.5.1 displays the evaluation number, the values of the tuning parameters, and the error metric value for the best decision tree model that the tuner found. Note that the ODS SELECT statement limits the displayed results to a single table and two plots. You can remove this statement to display all tables and plots. For the full list of ODS tables that PROC TREESPLIT produces, see Table 5.

Output 34.5.1: Best Configuration Table

The TREESPLIT Procedure

Best Configuration
Evaluation3
Maximum Tree Levels6
Maximum Bins160
CriterionGAIN
Misclassification Error Percentage10.68


Output 34.5.2 displays a scatter plot of all configurations that the tuner tried. The objective values are shown on the Y axis, and the evaluation numbers are shown on the X axis.

Output 34.5.2: Evaluation History Plot

Evaluation History Plot


The plot in Output 34.5.3 displays how the best found objective value and the elapsed time changed with each iteration of the tuner.

Output 34.5.3: Iteration History Plot

Iteration History Plot


Last updated: September 22, 2026