FOREST Procedure

PROC FOREST Statement

  • PROC FOREST <options>;

The PROC FOREST statement invokes the procedure. Table 2 summarizes the options in this statement.

Table 2: PROC FOREST Statement Options

Option Description
Basic Options
APPLYROWORDER Specifies that the procedure use a prespecified data distribution
BINMETHOD= Specifies how to bin interval inputs prior to training
DATA= Specifies the name of the input table
INBAGFRACTION= Specifies the fraction of the training data to use for growing each tree
INMODEL= Specifies a saved forest model to use for scoring a new table
ISOLATION Generates an isolation forest for anomaly detection instead of a forest for target prediction
LOH= Specifies the number of variables to preselect using the Loh method
NOPRINT Suppresses ODS output
NTHREADS= Specifies the number of threads to use in the computation
NTREES= Specifies the number of trees to grow in the forest model
NUMBIN= Specifies the number of bins for continuous variables
OUTMODEL= Specifies the data table to score the forest model
PRINTTARGET Create tables that contain information about columns in the output
RBAIMP Creates a variable importance table by using random branch assignment
SEED= Specifies the random number seed to use for model building
VARS_TO_TRY= Specifies the number of variables to examine at each node split
VII= Calculates the importance of the specified types of variable interactions
VOTE= Specifies the method for calculating the predicted probabilities for a nominal target
Splitting Options
ASSIGNMISSING= Specifies how to handle missing values in a predictor variable
MAXBRANCH= Specifies the maximum number of splits per node
MAXDEPTH= Specifies the maximum tree depth
MINLEAFSIZE= Specifies the minimum number of observations per leaf
MINUSEINSEARCH= Specifies the minimum number of observations to use with the USEINSEARCH policy for handling missing values
NOMSEARCH= Specifies the method to use to find a split on a nominal variable


You can specify the following options:

APPLYROWORDER

uses a data distribution and row order as determined by a previous partition action call. For more information, see the section The APPLYROWORDER Option in Chapter 2, Shared Concepts.

ASSIGNMISSING=NONE |MACSMALL |USEINSEARCH

specifies how PROC FOREST creates a default splitting rule that is used to handle missing values and unknown levels. An unknown level is a level of a categorical predictor that does not exist in the training data but is encountered during scoring.

This option controls how missing values are used in model training, and controls the creation of the default splitting rule.

The primary splitting rule for a node is created during model training. During model scoring, observations are assigned to a node in a tree based upon the primary splitting rule if the rule’s variable is not missing. If the variable is missing for the observation, then the default splitting rule is used.

The default splitting rule enables all data to be scored, even if the primary rule cannot be used on a particular observation.

You can specify one of the following values to determine the default splitting rule:

NONE

excludes observations that have any missing variables from training the forest model. In the scoring phase, this default rule assigns observations that have missing values of an interval predictor variable to the branch with the smallest predictor values, and assigns observations that have unknown and missing nominal levels to the branch with the most training observations.

MACSMALL

treats a missing value as a separate, legitimate value in the search for a split for the primary splitting rule. Missing values in interval inputs are treated as less than any other number. In the scoring phase, this default rule assigns missing interval inputs to the leftmost branch of the split, and unknown nominal levels to the largest branch in the split.

USEINSEARCH

treats a missing value as a separate, legitimate value in the search for a split for the primary splitting rule. Missing values in interval inputs are treated as a special level that is used during the split process. In the scoring phase, this default rule assigns missing interval inputs to the branch determined during forest growing, and unknown nominal levels to the largest branch in the split.

By default, ASSIGNMISSING=USEINSEARCH.

BINMETHOD=BUCKET |QUANTILE

specifies how to bin interval input variables prior to growing the forest model. The number of bins that are created is determined by the NUMBIN= option.

You can specify one of the following values:

BUCKET

bins interval input variables into fixed-width bins. The width of each bin for a particular variable is calculated by subtracting the smallest value among all observations from the largest value among all observations, and then dividing that result by the number of bins.

QUANTILE

bins interval input variables into bins according to their quantile. The width of the bins for a particular variable is not fixed, but the number of observations in each bin is approximately equal.

By default, BINMETHOD=QUANTILE.

DATA=libref.data-table

names the input data table for PROC FOREST to use. The default is the most recently created data table. libref.data-table is a two-level name, where

libref

refers to a collection of information that is defined in the LIBNAME statement and includes the library, which includes a path to the data, and a session identifier, which defaults to the active session but which can be explicitly defined in the LIBNAME statement. For more information about libref, see the section Using CAS Sessions and CAS Engine Librefs.

data-table

specifies the name of the input data table.

INBAGFRACTION=number
BOOTSTRAP=number

specifies the fraction of the random bootstrap sample of the training data to be used for growing each tree in the forest, where number is a value between 0 and 1. Observations can be duplicated in the sample. The number of distinct observations in the sample will be less than the number of observations available for training even when number is 1.

By default, INBAGFRACTION=0.6. This value can be tuned with the AUTOTUNE statement.

INMODEL=<libref.>data-table

specifies the data table that you have previously saved as a forest model by using the OUTMODEL= option in a previous run of PROC FOREST. libref.data-table is a two-level name, where libref refers to the library, and data-table specifies the name of the input data table. For more information about this two-level name, see the DATA= option and the section Using CAS Sessions and CAS Engine Librefs.

When you use the INMODEL= option, the OUTPUT statement is required and any other options in the PROC FOREST statement, except for NOPRINT and VOTE=, are ignored.

The data-table that you specify in the INMODEL= option must include the attributes that are associated with the table that the OUTMODEL= option produces, or PROC FOREST issues an error.

ISOLATION <(suboptions)>

creates an isolation forest for anomaly detection instead of creating a forest for target prediction. For more information about isolation forests, see the section Isolation Forests.

You can specify the following suboptions:

BETA=number

specifies the value to use as both inputs to the beta distribution in order to sample the random value for splitting interval variables. If you specify a number equal to 1, then PROC FOREST samples from the uniform distribution.

By default, BETA=4.

NPASSES=number

specifies the number of times to evaluate interval nodes. For each pass after the first, nodes whose splits create empty branches are reevaluated and recalculated.

By default, NPASSES=1.

SAMPLEN=number

specifies the number of observations, sampled without replacement, to use in each tree of the isolation forest.

By default, SAMPLEN=100.

When you specify the ISOLATION option, the GROW and TARGET statements are ignored, and the BINMETHOD=, INBAGFRACTION=, RBAIMP, VARS_TO_TRY=, and VII= options in the PROC FOREST statement are ignored. Fit statistics are not computed.

LOH=L

specifies a number of variables (L) that are preselected to consider for candidate splits for each node. The variables are selected using the Loh method.

If L is less than the value of the VARS_TO_TRY= option (m), then the variables are selected from among the m variables. If L is greater than or equal to m, or if no L is specified, then the Loh method is not used.

MAXBRANCH=b

specifies the maximum number of children per node in the tree. PROC FOREST tries to create this number of children unless it is impossible (for example, if a split variable does not have enough levels).

By default, MAXBRANCH=2.

MAXDEPTH=number

specifies the maximum depth of the tree to be grown. The number of levels in a tree is equal to the depth plus 1.

By default, MAXDEPTH=20.

This value can be tuned with the AUTOTUNE statement. In the ODS output that corresponds to tables that are generated using the AUTOTUNE statement, the term "MAXLEVEL" is used. The value of MAXLEVEL is equal to the value of the MAXDEPTH= option plus 1.

MINLEAFSIZE=number
LEAFSIZE=number

specifies the minimum number of observations that each child of a split must contain in the training data table in order for the split to be considered. The count of observations includes those that are excluded from training as a consequence of specifying a value less than 1 in the INBAGFRACTION= option. By default, MINLEAFSIZE=5. This value can be tuned with the AUTOTUNE statement.

MINUSEINSEARCH=number

specifies a threshold for using missing values in the split search when ASSIGNMISSING=USEINSEARCH. If the number of observations in which the splitting variable has missing values is greater than or equal to number, then PROC FOREST uses the USEINSEARCH policy to handle missing values for that variable.

By default, MINUSERINSEARCH=1.

NOMSEARCH(suboptions)

specifies search methods for splitting on a nominal variable. For more information, see the section Splitting Nominal Values. If you omit this option, the default values of the suboptions determine the search method. You can specify one or more of the following suboptions:

MAXCATEGORIES=number

specifies the maximum number of categories to use in a splitting rule. The input is eligible for splitting nodes in which no more than number categories appear. The value of number must be greater than 1.

By default, MAXCATEGORIES=128.

SHRINKAGE=number

specifies how much weight to give the average gradient when you combine it with the average gradient within a category. You use this option only when sorting the categories. The value of number must be nonnegative.

By default, SHRINKAGE=10.

SORT=number

specifies the minimum cardinality in the node of the nominal variable for using the sort method. The sort method sorts the categories and then examines binary splits that preserve the ordering. The value of number must be a nonnegative integer. If number is greater than the value of the MAXCATEGORIES=number option, then the variable is not used in the node.

By default, SORT=10.

NOPRINT

suppresses ODS output.

NTHREADS=number-of-threads

specifies the number of threads to use in the computation. The default value is the number of CPUs available on the machine.

NTREES=number

specifies the number of trees to grow in the forest model.

By default, NTREES=100. This value can be tuned with the AUTOTUNE statement.

NUMBIN=number
NBINS=number

specifies the number of bins to use for binning the interval input variables. PROC FOREST bins continuous predictors to a fixed bin size. This option controls the number of bins and thereby also the size of the bins.

By default, NUMBIN=50. This value can be tuned with the AUTOTUNE statement.

OUTMODEL=<libref.>data-table

specifies the data table to which to save the forest model. libref.data-table is a two-level name, where libref refers to the library, and data-table specifies the name of the output data table. For more information about this two-level name, see the DATA= option and the section Using CAS Sessions and CAS Engine Librefs.

The data table that results from this option contains information about each node and each tree in the forest model, including the splitting variables, the child nodes, the number of observations at each node, and the predicted response at each node. This table also has attributes attached that contain information about the input variables, the target variable, and the forest model.

PRINTTARGET

outputs tables that indicate generated columns in the OUT= table from the OUTPUT statement. For a continuous response, PROC FOREST generates an output table named PredName, which indicates the name of the predicted value column. For a categorical response, PROC FOREST generates an output table named PredIntoName, which indicates the name of the predicted value column, and also an output table named PredProbName, which indicates the names of the predicted probability columns.

RBAIMP

creates a variable importance table by using random branch assignment (RBA). This table is created in addition to the normal variable importance table that is calculated using the residual sum of squares (RSS) error. For more information about RBA and RSS variable importance, see the section Measuring Variable Importance.

SEED=number

specifies the initial seed for random number generation that is used in both selecting out-of-bag observations for the trees and selecting the subset of variables to determine splits. The value of number must be an integer. If you do not specify a seed or you specify a value less than or equal to 0, the seed is generated by reading the time of day from the computer’s clock.

VARS_TO_TRY=m
M=m

specifies the number of input variables to consider splitting on in a node, where m ranges from 1 to the number of input variables.

By default, m is the square root of the number of input variables. This value can be tuned with the AUTOTUNE statement.

VII=2 |3
INTERACTIONIMP=2 |3

calculates the variable interaction importance, which is described in the section Variable Interaction Importance. You can specify the following values:

2

calculates the importance of all two-way variable interactions.

3

calculates the importance of all three-way and all two-way variable interactions.

If you do not specify this option, then the variable interaction importance is not calculated.

VOTE=MAJORITY |PROBABILITY

specifies how to calculate the predicted probability of the target levels for a nominal target. The predicted level is the level that has the highest predicted probability. This option affects the scoring and fit statistics of the forest model. You can specify the following values:

MAJORITY

specifies that the predicted probability of each target level is equal to the number of trees in the forest that predicted that level as the target, divided by the total number of trees in the forest.

PROBABILITY

specifies that the predicted probability of each target level is equal to the probability of that level averaged over each tree in the forest.

When using the INMODEL= option, you can specify how to calculate the predicted probability of the target levels, even if the model was trained with a different value for the VOTE= option.

By default, VOTE=PROBABILITY.

Last updated: August 06, 2026