# tRandomForestModel properties for Apache Spark Batch

These properties are used to configure tRandomForestModel running in the Spark Batch Job framework.

The Spark Batch tRandomForestModel component belongs to the Machine Learning family.

This component is available in Talend Platform products with Big Data and in Talend Data Fabric.

## Basic settings

| Label column | Select the input column used to provide classification labels. The records of this column<br>are used as the class names (Target in terms of classification) of the elements to be<br>classified. |
| --- | --- |
| Feature column | Select the input column used to provide features. Very often, this column is the output of<br>the feature engineering computations performed by tModelEncoder. |
| Save the model on file<br>system | Select this check box to store the model in a given file system. Otherwise, the model is<br>stored in memory. The button for browsing does not work with the Spark Local mode; if you are using the Spark Yarn<br>or the Spark Standalone mode, ensure that you have properly<br>configured the connection in a configuration component in the same Job, such as tHDFSConfiguration. |
| Number of trees in the forest | Enter the number of decision trees you want tRandomForestModel to build.<br><br>Each decision tree is trained independently using a random sample of<br>features.<br><br>Increasing this number can improve the accuracy by decreasing the<br>variance in predictions, but will increase the training time. |
| Maximum depth of each tree in the<br>forest | Enter the decision tree depth at which the training should stop adding new nodes. New<br>nodes represent further tests on features on internal nodes and possible class labels held<br>by leaf nodes.<br><br>For a tree of *n* depth, the number of internal nodes is<br>*2^n^ - 1*. For example, depth<br>*1* means *1* internal<br>node plus *2* leaf nodes.<br><br>Generally speaking, a deeper decision tree is more expressive and thus potentially more<br>accurate in predictions, but it is also more resource consuming and prone to<br>overfitting. |

## Advanced settings

| Subsampling rate | Enter the numeric value to indicate the fraction of the<br>input dataset used for training each tree in the forest. The default<br>value *1.0* is recommended, meaning to take the<br>whole dataset for test. |
| --- | --- |
| Subset strategy | Select the strategy about how many features should be<br>considered on each internal node in order to appropriately split this<br>internal node (actually the training set or subset of a feature on this<br>node) into smaller subsets. These subsets are used to build child<br>nodes.<br><br>Each strategy takes a different number of features into<br>account to find the optimal point among these features for split. This<br>point could be, for example, the age *35* of the<br>categorical feature *age*.<br><br><ul> <li> <p> <span>auto</span>: this strategy                                        is based on the number of trees you have set in the                                            <span>Number of trees in the                                            forest</span> field in the <span>Basic settings</span> view. This is                                        the default strategy to be used.</p> <p>If the number of trees is <em>1</em>, the strategy is actually <span>all</span>; if this number is                                        greater than <em>1</em>, the strategy is                                            <span>sqrt</span>.</p> </li> <li> <p> <span>all</span>: the total number                                        of features is considered for split.</p> </li> <li> <p> <span>sqrt</span>: the number of                                        features to be considered is the square root of the total                                        number of features.</p> </li> <li> <p> <span>log2</span>: the number of                                        features to be considered is the result of <em>log<sub>2</sub>(M)</em>,                                        in which <em>M</em> is the total number of                                        features.</p> </li> </ul> |
| Set Checkpoint Interval | Set the frequency of checkpoints. It is recommended to leave the default<br>value (10).<br><br>Before setting a value for this parameter, activate checkpointing and set<br>the checkpoint directory in the Spark<br>Configuration tab of the Run<br>view.<br><br>For further information about checkpointing, see<br>[Logging and checkpointing the activities of your Apache Spark Job](https://help.qlik.com/talend/en-US/components/7.3/spark-batch/logging-and-checkpointing-activities-of-your-apache-spark-job-spark-batch-component-if-you).<br><br>For further information about checkpointing the<br>activities of your Apache Spark Job, see the documentation on Talend Help Center ([https://help.talend.com](https://help.talend.com/)). |
| Max bins | Enter the numeric value to indicate the maximum number of bins used for splitting<br>features.<br><br>The continuous features are automatically transformed to ordered discrete features. |
| Min info gain | Enter the minimum number of information gain to be expected from a parent node to its<br>child nodes. When the number of information gain is less than this minimum number, node<br>split is stopped.<br><br>The default value of the minimum number of information gain is *0.0*, meaning that no further information is obtained by splitting a given node.<br>As a result, the splitting could be stopped.<br><br>For further information about how the information gain is calculated, see [Impurity and Information gain](http://spark.apache.org/docs/latest/mllib-decision-tree.html#node-impurity-and-information-gain) from the Spark documentation. |
| Min instances per node | Enter the minimum number of training instances a node should have to make it valid for<br>further splitting.<br><br>The default value is *1*, which means when a node has<br>only *1* row of training data, it stops splitting. |
| Impurity | Select the measure used to select the best split from<br>each set of splits.<br><br><ul> <li> <p> <span>gini</span>: it is about how often an element could be        incorrectly labelled in a split.</p> </li> <li> <p> <span>entropy</span>: it is about how unpredictable the information in        each split is.</p> </li> </ul><br><br>For further information about how each of the measures is calculated, see [Impurity measures](http://spark.apache.org/docs/latest/mllib-decision-tree.html#node-impurity-and-information-gain) from the Spark documentation. |
| Set a random seed | Enter the random seed number to be used for bootstrapping and choosing feature<br>subsets |

## Usage

| **Usage rule** | This component is used as an end component and requires an input link.<br><br>You can accelerate the training process by adjusting the stopping<br>conditions such as the maximum depth of each decision tree, the maximum<br>number of bins of splitting or the minimum number of information gain,<br>but note that the training that stops too early could impact its<br>performance. |
| --- | --- |
| Model evaluation | The parameters you need to set are free parameters and so their values may be provided by<br>previous experiments, empirical guesses or the like. They do not have any optimal values<br>applicable for all datasets.<br><br>Therefore, you need to train the classifier model you are generating with different sets<br>of parameter values until you can obtain the best confusion matrix. But note that you need<br>to write the evaluation code yourself to rank your model with scores.<br><br>You need to select the scores to be used depending on the algorithm you want to use to<br>train your classifier model. This allows you to build the most relevant confusion<br>matrix.<br><br>For examples about how the confusion matrix is used in a<br>Talend<br>Job for classification, see [Creating a classification model to filter spam](https://help.qlik.com/talend/en-US/components/7.3/machine-learning/classification-model).<br><br>For a general explanation about confusion matrix, see https://en.wikipedia.org/wiki/Confusion\_matrix from Wikipedia. |
| Spark Connection | In the Spark<br>Configuration tab in the Run<br>view, define the connection to a given Spark cluster for the whole Job. In<br>addition, since the Job expects its dependent jar files for execution, you must<br>specify the directory in the file system to which these jar files are<br>transferred so that Spark can access these files:<br><br><ul> <li> <div> <span>Yarn mode</span> (Yarn client or Yarn cluster):<ul> <li> <p>When using Google Dataproc, specify a bucket in the                                            <span>Google Storage staging bucket</span>                                        field in the <span>Spark configuration</span>                                        tab.</p> </li> <li> <p>When using HDInsight, specify the blob to be used for Job                                        deployment in the <span>Windows Azure Storage                                            configuration</span> area in the <span>Spark                                            configuration</span> tab.</p> </li> <li>When using Altus, specify the S3 bucket or the Azure                                    Data Lake Storage for Job deployment in the <span>Spark                                        configuration</span> tab.</li> <li>When using Qubole, add a                                        <span>tS3Configuration</span> to your Job to write                                    your actual business data in the S3 system with Qubole. Without                                        <span>tS3Configuration</span>, this business data is                                    written in the Qubole HDFS system and destroyed once you shut                                    down your cluster.</li> <li> <p>When using on-premises distributions, use the configuration component                                        corresponding to the file system your cluster is using.                                        Typically, this system is HDFS and so use <a href="https://help.qlik.com/talend/r/en-US/7.3/components/hdfs/thdfsconfiguration">tHDFSConfiguration</a>.</p> </li> </ul> </div> </li> <li> <p> <span>Standalone mode</span>: use the                            configuration component corresponding to the file system your cluster is                            using, such as <a href="https://help.qlik.com/talend/r/en-US/7.3/components/hdfs/thdfsconfiguration-properties-for-apache-spark-batch">tHDFSConfiguration Apache Spark Batch</a> or <a href="https://help.qlik.com/talend/r/en-US/7.3/components/amazon-s3/ts3configuration-properties-for-apache-spark-batch">tS3Configuration Apache Spark Batch</a>.</p> <p>If you are using Databricks without any configuration component present                            in your Job, your business data is written directly in DBFS (Databricks                            Filesystem).</p> </li> </ul><br><br>This connection is effective on a per-Job basis. |