A Random Forest is a classifier containing multiple decision trees. Its output is the mode of the classes from the individual trees.
Component configuration
You can configure the parameters for the Random Forest component by using one of the following methods.
Method 1: GUI
Configure the component parameters on the pipeline page in Machine Learning Designer.
|
Tab |
Parameter |
Description |
|
field settings |
feature columns |
By default, all columns are used except the label and weight columns. |
|
excluded columns |
This parameter cannot be used with feature columns. |
|
|
Force conversion columns |
The parsing rules are as follows:
Note
To parse a BIGINT column as CATEGORICAL, use the forceCategorical parameter. |
|
|
weight column |
The column used to weigh each sample row. Only numeric types are supported. |
|
|
label column |
The label column of the input table. STRING and numeric types are supported. |
|
|
parameter settings |
Number of trees |
Valid values: 1 to 1000. |
|
Algorithm distribution |
Specifies how different tree algorithms are distributed in the forest. If a forest has N trees and you set this parameter to algorithmTypes=[a,b], the algorithms are allocated as follows:
For example, in a forest with five trees, if you set the parameter to [2,4], tree 1 uses the ID3 algorithm, trees 2 and 3 use the CART algorithm, and trees 4 and 5 use the C4.5 algorithm. If you enter None, the algorithms are distributed evenly across the forest. |
|
|
Number of random features per tree |
Valid values: [1,N], where N is the total number of features. |
|
|
Minimum samples per leaf node |
Must be a positive integer. The default value is 2. |
|
|
Minimum sample ratio per leaf node |
The minimum ratio of samples in a leaf node relative to its parent node. Valid values: [0,1]. The default value is 0. |
|
|
Maximum tree depth |
Valid values: [1,+∞). The default value is unlimited. |
|
|
Number of random input samples per tree |
Valid values: (1000,1000000]. The default value is 100000. |
Method 2: PAI command
Use a PAI command to configure the component parameters. You can run the PAI command by using the SQL script component. For more information, see SQL script.
PAI -name randomforests
-project algo_public
-DinputTableName="pai_rf_test_input"
-DmodelName="pai_rf_test_model"
-DforceCategorical="f1"
-DlabelColName="class"
-DfeatureColNames="f0,f1"
-DmaxRecordSize="100000"
-DminNumPer="0"
-DminNumObj="2"
-DtreeNum="3";
|
Parameter |
Required |
Description |
Default |
|
inputTableName |
Yes |
The input table. |
N/A |
|
inputTablePartitions |
No |
The input table partitions for training. Supported formats:
Note
To specify multiple partitions, separate them with commas (,). |
All partitions |
|
labelColName |
Yes |
The name of the label column in the input table. |
N/A |
|
modelName |
Yes |
The name of the output model. |
N/A |
|
treeNum |
Yes |
The number of trees in the forest. Valid values: 1 to 1000. |
100 |
|
excludedColNames |
No |
This parameter cannot be used with featureColNames. |
Empty |
|
weightColName |
No |
The name of the weight column in the input table. |
N/A |
|
featureColNames |
No |
The names of the feature columns used for training. |
All columns except those specified for labelColName and weightColName. |
|
forceCategorical |
No |
The parsing rules are as follows:
Note
To parse a BIGINT column as CATEGORICAL, use the forceCategorical parameter. |
INT is treated as a continuous type. |
|
algorithmTypes |
No |
Specifies how different tree algorithms are distributed in the forest. If a forest has N trees and algorithmTypes=[a,b]:
For example, in a forest with five trees, with a setting of [2,4], tree 1 uses the ID3 algorithm, trees 2 and 3 use the CART algorithm, and trees 4 and 5 use the C4.5 algorithm. If you enter None, the algorithms are distributed evenly across the forest. |
The algorithms are evenly distributed. |
|
randomColNum |
No |
The number of random features to consider at each split when building a decision tree. Valid values: [1,N], where N is the total number of features. |
log2N |
|
minNumObj |
No |
The minimum number of samples required in a leaf node. Must be a positive integer. |
2 |
|
minNumPer |
No |
The minimum ratio of samples in a leaf node relative to its parent node. Valid values: [0,1]. |
0.0 |
|
maxTreeDeep |
No |
The maximum depth of a single tree. Valid values: [1,+∞). |
Unlimited |
|
maxRecordSize |
No |
The number of random samples used to build a single tree. Valid values: (1000,1000000]. |
100000 |
Example
-
Use the following SQL statement to generate training data:
create table pai_rf_test_input as select * from ( select 1 as f0,2 as f1, "good" as class union all select 1 as f0,3 as f1, "good" as class union all select 1 as f0,4 as f1, "bad" as class union all select 0 as f0,3 as f1, "good" as class union all select 0 as f0,4 as f1, "bad" as class )tmp; -
Use the following PAI command to submit the Random Forest component parameters:
PAI -name randomforests -project algo_public -DinputTableName="pai_rf_test_input" -DmodelName="pai_rf_test_model" -DforceCategorical="f1" -DlabelColName="class" -DfeatureColNames="f0,f1" -DmaxRecordSize="100000" -DminNumPer="0" -DminNumObj="2" -DtreeNum="3"; -
View the model in Predictive Model Markup Language (PMML).
<?xml version="1.0" encoding="utf-8"?> <PMML xmlns="http://www.dmg.org/PMML-4_2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.2" xsi:schemaLocation="http://www.dmg.org/PMML-4_2 http://www.dmg.org/v4-2/pmml-4-2.xsd"> <Header copyright="Copyright (c) 2014, Alibaba Inc." description=""> <Application name="ODPS/PMML" version="0.1.0"/> <Timestamp>Tue, 12 Jul 2016 07:04:48 GMT</Timestamp> </Header> <DataDictionary numberOfFields="2"> <DataField name="f0" optype="continuous" dataType="integer"/> <DataField name="f1" optype="continuous" dataType="integer"/> <DataField name="class" optype="categorical" dataType="string"> <Value value="bad"/> <Value value="good"/> </DataField> </DataDictionary> <MiningModel modelName="xlab_m_random_forests_1_75078_v0" functionName="classification" algorithmName="RandomForests"/> <MiningSchema> <MiningField name="f0" usageType="active"/> <MiningField name="f1" usageType="active"/> <MiningField name="class" usageType="target"/> </MiningSchema> <Segmentation multipleModelMethod="majorityVote"> <Segment id="0"> <True/> <TreeModel modelName="xlab_m_random_forests_1_75078_v0" functionName="classification" algorithmName="RandomForests"> <MiningSchema> <MiningField name="f0" usageType="active"/> <MiningField name="f1" usageType="active"/> <MiningField name="class" usageType="target"/> </MiningSchema> <Node id="1"> <True/> <ScoreDistribution value="bad" recordCount="2"/> <ScoreDistribution value="good" recordCount="3"/> <Node id="2" score="good"> <SimplePredicate field="f1" operator="equal" value="2"/> <ScoreDistribution value="good" recordCount="1"/> </Node> <Node id="3" score="good"> <SimplePredicate field="f1" operator="equal" value="3"/> <ScoreDistribution value="good" recordCount="2"/> </Node> <Node id="4" score="bad" <SimplePredicate field="f1" operator="equal" value="4"/> <ScoreDistribution value="bad" recordCount="2"/> </Node> </Node> </TreeModel> </Segment> <Segment id="1"> <True/> <TreeModel modelName="xlab_m_random_forests_1_75078_v0" functionName="classification" algorithmName="RandomForests"> <MiningSchema> <MiningField name="f0" usageType="active"/> <MiningField name="f1" usageType="active"/> <MiningField name="class" usageType="target"/> </MiningSchema> <Node id="1"> <True/> <ScoreDistribution value="bad" recordCount="2"/> <ScoreDistribution value="good" recordCount="3"/> <Node id="2" score="good"> <SimpleSetPredicate field="f1" booleanOperator="isIn"> <Array n="2" type="integer"2 3</Array> </SimpleSetPredicate> <ScoreDistribution value="good" recordCount="3"/> </Node> <Node id="3" score="bad"> <SimpleSetPredicate field="f1" booleanOperator="isNotIn"> <Array n="2" type="integer"2 3</Array> </SimpleSetPredicate> <ScoreDistribution value="bad" recordCount="2"/> </Node> </Node> </TreeModel> </Segment> <Segment id="2"> <True/> <TreeModel modelName="xlab_m_random_forests_1_75078_v0" functionName="classification" algorithmName="RandomForests"> <MiningSchema> <MiningField name="f0" usageType="active"/> <MiningField name="f1" usageType="active"/> <MiningField name="class" usageType="target"/> </MiningSchema> <Node id="1"> <True/> <ScoreDistribution value="bad" recordCount="2"/> <ScoreDistribution value="good" recordCount="3"/> <Node id="2" score="bad"> <SimplePredicate field="f0" operator="lessOrEqual" value="0.5"/> <ScoreDistribution value="bad" recordCount="1"/> <ScoreDistribution value="good" recordCount="1"/> </Node> <Node id="3" score="good"> <SimplePredicate field="f0" operator="greaterThan" value="0.5"/> <ScoreDistribution value="bad" recordCount="1"/> <ScoreDistribution value="good" recordCount="2"/> </Node> </Node> </TreeModel> </Segment> </Segmentation> </MiningModel> </PMML> -
View the visualized output of the model.