input:   : the training data set,
    : the number of trees,
    mtry: the size of the subspaces.
output: A random forest RF
(1) for    to    do
(2)  Draw a bagged subset of samples from .
(4)  while (stopping  criteria  is  not  met) do
(5)   Select randomly mtry features.
(6)   for    to    do
(7)    Compute the decrease in the node impurity.
(8)   Choose the feature which decreases the impurity the most and
    the node is divided into two children nodes.
(9) Combine the trees to form a random forest.
Algorithm 1: Random forest algorithm.