# Decision Forest¶

## Details¶

Given n feature vectors $$X = \{x_1 = (x_{11}, \ldots, x_{1p}), \ldots, x_n = (x_{n1}, \ldots, x_{np}) \}$$ of $$n$$ $$p$$-dimensional feature vectors and n responses $$y = (y_1, \ldots, y_n)$$, the problem is to build a decision forest classification or regression model.

### Training Stage¶

Library uses the following algorithmic framework for the training stage. Let $$S = (X, Y)$$ be the set of observations. Given a positive integer parameters, such as the number of trees $$B$$, the bootstrap parameter $$N = f*n$$, where $$f$$ is a fraction of observations used for a training of one tree, and the number of features per node $$m$$, the algorithm does the following for $$b = 1, \ldots ,B$$:

• Selects randomly with replacement the set $$D_b$$ of $$N$$ vectors from the set $$S$$. The set $$D_b$$ is called a bootstrap set.

• Trains a decision tree classifier $$T_b$$ on $$D_b$$ using parameter $$m$$ for each tree.

Decision tree $$T$$ is trained using the training set $$D$$ of size $$N$$. Each node $$t$$ in the tree corresponds to the subset $$D_t$$ of the training set $$D$$, with the root node being $$D$$ itself. Its internal nodes $$t$$ represent a binary test (split) dividing their subset $$X_t$$ in two subsets $$X_{t_L}$$ and $$X_{t_R}$$, corresponding to their children $$t_L$$ and $$t_R$$.

#### Inexact Histogram Computation Method¶

In inexact histogram method only a selected subset of splits is considered for computation of a best split. This subset is computed for each feature at the initialization stage of the algorithm. After the set of splits is computed, each value from initially provided data is substituted with the value of the corresponding bin. The bins are continuous intervals between the selected splits.

#### Split Criteria¶

The metric for measuring the best split is called impurity, $$i(t)$$. It generally reflects the homogeneity of responses within the subset $$D_t$$ in the node $$t$$. For the detailed definition of $$i(t)$$ metrics, see the description of a specific algorithm.

Let the impurity decrease in the node $$t$$ be

$\Delta i\left(t\right)=i\left(t\right)–\frac{|{D}_{t}{}_{{}_{L}}|}{|{D}_{t}|}i\left({t}_{L}\right)–\frac{|{D}_{t}{}_{{}_{R}}|}{|{D}_{t}|}i\left({t}_{R}\right).\text{ }$

#### Termination Criteria¶

The library supports the following termination criteria of decision forest training:

Minimal number of observations in a leaf node

Node $$t$$ is not processed if $$|D_t|$$ is smaller than the predefined value. Splits that produce nodes with the number of observations smaller than that value are not allowed.

Minimal number of observations in a split node

Node $$t$$ is not processed if $$|D_t|$$ is smaller than the predefined value. Splits that produce nodes with the number of observations smaller than that value are not allowed.

Minimum weighted fraction of the sum total of weights of all the input observations required to be at a leaf node

Node $$t$$ is not processed if $$|D_t|$$ is smaller than the predefined value. Splits that produce nodes with the number of observations smaller than that value are not allowed.

Maximal tree depth

Node $$t$$ is not processed if its depth in the tree reached the predefined value.

Impurity threshold

Node $$t$$ is not processed if its impurity is smaller than the predefined threshold.

Maximal number of leaf nodes

Grow trees with positive maximal number of leaf nodes in a best-first fashion. Best nodes are defined by relative reduction in impurity. If maximal number of leaf nodes equals zero, then this criterion does not limit the number of leaf nodes, and trees grow in a depth-first fashion.

#### Tree Building Strategies¶

Maximal number of leaf nodes defines the strategy of tree building: depth-first or best-first.

##### Depth-first Strategy¶

If maximal number of leaf nodes equals zero, a decision tree is built using depth-first strategy. In each terminal node $$t$$, the following recursive procedure is applied:

• Stop if the termination criteria are met.

• Choose randomly without replacement $$m$$ feature indices $$J_t \in \{0, 1, \ldots, p-1\}$$.

• For each $$j \in J_t$$, find the best split $$s_{j,t}$$ that partitions subset $$D_t$$ and maximizes impurity decrease $$\Delta i(t)$$.

• A node is a split if this split induces a decrease of the impurity greater than or equal to the predefined value. Get the best split $$s_t$$ that maximizes impurity decrease $$\Delta i$$ in all $$s_{j,t}$$ splits.

• Apply this procedure recursively to $$t_L$$ and $$t_R$$.

##### Best-first Strategy¶

If maximal number of leaf nodes is positive, a decision tree is built using best-first strategy. In each terminal node $$t$$, the following steps are applied:

• Stop if the termination criteria are met.

• Choose randomly without replacement $$m$$ feature indices $$J_t \in \{0, 1, \ldots, p-1\}$$.

• For each $$j \in J_t$$, find the best split $$s_{j,t}$$ that partitions subset $$D_t$$ and maximizes impurity decrease $$\Delta i(t)$$.

• A node is a split if this split induces a decrease of the impurity greater than or equal to the predefined value and the number of split nodes is less or equal to $$\mathrm{maxLeafNodes} – 1$$. Get the best split $$s_t$$ that maximizes impurity decrease $$\Delta i$$ in all $$s_{j,t}$$ splits.

• Put a node into a sorted array, where sort criterion is the improvement in impurity $$\Delta i(t)|D_t|$$. The node with maximal improvement is the first in the array. For a leaf node, the improvement in impurity is zero.

• Apply this procedure to $$t_L$$ and $$t_R$$ and grow a tree one by one getting the first element from the array until the array is empty.

#### Random Numbers Generation¶

To create a bootstrap set and choose feature indices in the performant way, the training algorithm requires the source of random numbers, capable to produce sequences of random numbers in parallel.

Initialization of the engine in the decision forest is based on the scheme below:

The state of the engine is updated once the training of the decision forest model is completed. The library provides support to retrieve the instance of the engine with updated state that can be used in other computations. The update of the state is engine-specific and depends on the parallelization technique used as defined earlier:

• Family: the updated state is the set of states that represent individual engines in the family.

• Leapfrog: the updated state is the state of the sequence with the rightmost position on the sequence. The example below demonstrates the idea for case of 2 subsequences (‘x’ and ‘o’) of the random number sequence:

• SkipAhead: the updated state is the state of the independent sequence with the rightmost position on the sequence. The example below demonstrates the idea for case of 2 subsequences (‘x’ and ‘o’) of the random number sequence:

### Prediction Stage¶

Given decision forest classifier and vectors $$x_1, \ldots, x_r$$, the problem is to calculate the responses for those vectors. To solve the problem for each given query vector $$x_i$$ , the algorithm finds the leaf node in a tree in the forest that gives the response by that tree. The response of the forest is based on an aggregation of responses from all trees in the forest. For the detailed definition, see the description of a specific algorithm.

### Additional Characteristics Calculated by the Decision Forest¶

Decision forests can produce additional characteristics, such as an estimate of generalization error and an importance measure (relative decisive power) of each of p features (variables).

### Out-of-bag Error¶

The estimate of the generalization error based on the training data can be obtained and calculated as follows:

• For each tree $$T_b$$ in the forest, trained on the bootstrap set $$D_b$$, the set $$\overline{D_b}=S \setminus {D}_{b}$$ is called the out-of-bag (OOB) set.

• Predict the data from $$\overline{{D}_{b}}$$ set by $$T_b$$.

• For each vector $$x_i$$ in the dataset X, predict its response $$\hat{y_i}$$ by the trees that contain $$x_i$$ in their OOB set.

• Aggregate the out-of-bag predictions in all trees and calculate the OOB error of the decision forest.

• If OOB error value per each observation is required, then calculate the prediction error for $$x_i$$.

For the detailed definition, see the description of a specific algorithm.

### Variable Importance¶

There are two main types of variable importance measures:

• Mean Decrease Impurity importance (MDI).

Importance of the $$j$$-th variable for predicting $$Y$$ is the sum of weighted impurity decreases $$p(t) \Delta i(s_t, t)$$ for all nodes $$t$$ that use $$x_j$$, averaged over all $$B$$ trees in the forest:

$MDI\left(j\right)=\frac{1}{B}\sum _{b=1}^{B} \sum _{t\in {T}_{b}:v\left({s}_{t}\right)=j}p\left(t\right)\Delta i\left({s}_{t},t\right),$

where $$p\left(t\right)=\frac{|{D}_{t}|}{|D|}$$ is the fraction of observations reaching node $$t$$ in the tree $$T_b$$, and $$v(s_t)$$ is the index of the variable used in split $$s_t$$ .

• Mean Decrease Accuracy (MDA).

Importance of the $$j$$-th variable for predicting $$Y$$ is the average increase in the OOB error over all trees in the forest when the values of the $$j$$-th variable are randomly permuted in the OOB set. For that reason, this latter measure is also known as permutation importance.

In more details, the library calculates MDA importance as follows:

• Let $$\pi (X,j)$$ be the set of feature vectors where the $$j$$-th variable is randomly permuted over all vectors in the set.

• Let $$E_b$$ be the OOB error calculated for $$T_b:$$ on its out-of-bag dataset $$\overline{D_b}$$.

• Let $$E_{b,j}$$ be the OOB error calculated for $$T_b:$$ using $$\pi \left(\overline{{X}_{b}},j\right)$$, and its out-of-bag dataset $$\overline{D_b}$$ is permuted on the $$j$$-th variable. Then

• $${\delta }_{b,j}={E}_{b}-{E}_{b,j}$$ is the OOB error increase for the tree $$T_b$$.

• $$Raw MDA\left(j\right)=\frac{1}{B}\sum _{b=1}^{B}{\delta }_{b,j}$$ is MDA importance.

• $$Scaled MDA\left(j\right)=\frac{Raw MDA\left({x}_{j}\right)}{\frac{{\sigma }_{j}}{\sqrt{B}}}$$, where $${\sigma }_{j}^{2}$$ is the variance of $$D_{b,j}$$

## Batch Processing¶

Decision forest classification and regression follows the general workflow described in Classification Usage Model.

### Training¶

At the training stage, decision forest regression has the following parameters:

Parameter

Default Value

Description

nTrees

$$100$$

The number of trees in the forest.

observationsPerTreeFraction

$$1$$

Fraction of the training set S used to form the bootstrap set for a single tree training, $$0 < \mathrm{observationsPerTreeFraction} \leq 1$$. The observations are sampled randomly with replacement.

featuresPerNode

$$0$$

The number of features tried as possible splits per node. If the parameter is set to $$0$$, the library uses the square root of the number of features, $$\sqrt{p}$$, for classification and $$\frac{p}{3}$$ features for regression.

maxTreeDepth

$$0$$

Maximal tree depth. Default is $$0$$ (unlimited).

DEPRECATED: seed

$$777$$

The seed for random number generator, which is used to choose the bootstrap set, split features in every split node in a tree, and generate permutation required in computations of MDA variable importance.

Note

This parameter is deprecated and will be removed in future releases. Use engine instead.

engine

SharePtr< engines:: mt2203:: Batch>()

Pointer to the random number generator engine.

The random numbers produced by this engine are used to choose the bootstrap set, split features in every split node in a tree, and generate permutation required in computations of MDA variable importance.

impurityThreshold

$$0$$

The threshold value used as stopping criteria: if the impurity value in the node is smaller than the threshold, the node is not split anymore.

varImportance

none

The variable importance computation mode.

Possible values:

• none – variable importance is not calculated

• MDI - Mean Decrease of Impurity, also known as the Gini importance or Mean Decrease Gini

• MDA_Raw - Mean Decrease of Accuracy (permutation importance)

• MDA_Scaled - the MDA_Raw value scaled by its standard deviation

resultsToCompute

$$0$$

The 64-bit integer flag that specifies which extra characteristics of the decision forest to compute. Provide one of the following values to request a single characteristic or use bitwise OR to request a combination of the characteristics:

• computeOutOfBagError

• computeOutOfBagErrorPerObservation

bootstrap

true

If true, the training set for a tree is a bootstrap of the whole training set. If false, the whole training set is used to build trees.

minObservationsInLeafNode

$$1$$ for classification, $$5$$ for regression

Minimum number of observations in the leaf node.

minObservationsInSplitNode

$$2$$

Minimum number of samples required to split an internal node; it can be any non-negative number.

minWeightFractionInLeafNode

$$0.0$$

Minimum weighted fraction of the sum total of weights of all the input observations required to be at a leaf node, from $$0.0$$ to $$0.5$$.

All observations have equal weights if the weights of the observations are not provided.

minImpurityDecreaseInSplitNode

$$0.0$$

Minimum amount of impurity decrease required to split a node; it can be any non-negative number.

maxLeafNodes

$$0$$

Grow trees with positive maximal number of leaf nodes in a best-first fashion. Best nodes are defined as relative reduction in impurity. If maximal number of leaf nodes equals zero, then this parameter does not limit the number of leaf nodes, and trees grow in a depth-first fashion.

### Output¶

In addition to regression or classifier output, decision forest calculates the result described below. Pass the Result ID as a parameter to the methods that access the result of your algorithm.

Result ID

Result

outOfBagError

A numeric table $$1 \times 1$$ containing out-of-bag error computed when the computeOutOfBagErroroption option is on.

Note

By default, this result is an object of the HomogenNumericTable class, but you can define the result as an object of any class derived from NumericTable.

variableImportance

A numeric table $$1 \times p$$ that contains variable importance values for each feature. If you set the varImportance parameter to none, the library returns a null pointer to the table.

Note

By default, this result is an object of the HomogenNumericTable class, but you can define the result as an object of any class derived from NumericTable except PackedTriangularMatrix and PackedSymmetricMatrix.

outOfBagErrorPerObservation

A numeric table of size $$1 \times n$$ that contains the computed out-of-bag error when the computeOutOfBagErrorPerObservation option is enabled. The value $$-1$$ in the table indicates that no OOB value was computed because this observation was not in OOB set for any of the trees in the model (never left out during the bootstrap).

Note

By default, this result is an object of the HomogenNumericTable class, but you can define the result as an object of any class derived from NumericTable.

updatedEngine

Engine instance with state updated after computations.

## Performance Considerations¶

To get the best performance of the decision forest variable importance computation, use the Mean Decrease Impurity (MDI) rather than the Mean Decrease Accuracy (MDA) method.

Optimization Notice

Intel’s compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804