ランダムフォレストは、複数の決定木を含む分類器です。その出力は、個々のツリーからのクラスの最頻値です。
コンポーネントの設定
ランダムフォレストコンポーネントのパラメーターは、以下のいずれかの方法で設定できます。
方法1:GUI
ビジュアルモデリングのパイプラインページでコンポーネントのパラメーターを設定します。
|
タブ |
パラメーター |
説明 |
|
[フィールド設定] |
特徴列 |
デフォルトでは、ラベル列と重み列を除くすべての列が使用されます。 |
|
[除外列] |
このパラメーターは [特徴列] と併用できません。 |
|
|
[強制変換列] |
解析ルールは以下の通りです:
説明
BIGINT 列を CATEGORICAL として解析するには、forceCategorical パラメーターを使用します。 |
|
|
[重み列] |
各サンプル行の重み付けに使用される列。数値型のみがサポートされます。 |
|
|
ラベル列 |
入力テーブルのラベル列。STRING 型と数値型がサポートされます。 |
|
|
[パラメーター設定] |
[ツリー数] |
有効値:1~1000。 |
|
アルゴリズムディストリビューション |
フォレスト内で異なるツリーアルゴリズムをどのように分散させるかを指定します。フォレストに N 個のツリーがあり、このパラメーターを algorithmTypes=[a,b] と設定した場合、アルゴリズムは次のように割り当てられます:
例えば、5つのツリーを持つフォレストで、パラメーターを [2,4] と設定した場合、ツリー 1 は ID3 アルゴリズムを使用し、ツリー 2 と 3 は CART アルゴリズムを使用し、ツリー 4 と 5 は C4.5 アルゴリズムを使用します。None を入力すると、アルゴリズムはフォレスト全体に均等に分散されます。 |
|
|
[ツリーごとのランダム特徴数] |
有効値:[1,N]。N は総特徴数です。 |
|
|
[リーフノードあたりの最小サンプル数] |
正の整数である必要があります。デフォルト値は 2 です。 |
|
|
[リーフノードあたりの最小サンプル比率] |
親ノードに対するリーフノード内のサンプルの最小比率。有効値:[0,1]。デフォルト値は 0 です。 |
|
|
最大のツリーの深さ |
有効値:[1,+∞)。デフォルト値は無制限です。 |
|
|
[ツリーごとのランダム入力サンプル数] |
有効値:(1000,1000000]。デフォルト値は 100000 です。 |
方法2:PAI コマンド
PAI コマンドを使用して、コンポーネントのパラメーターを設定します。SQL スクリプトコンポーネントを使用して PAI コマンドを実行できます。詳細については、「SQL スクリプト」をご参照ください。
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";
|
パラメーター |
必須 |
説明 |
デフォルト |
|
inputTableName |
はい |
入力テーブル。 |
N/A |
|
inputTablePartitions |
いいえ |
トレーニング用の入力テーブルパーティション。サポートされているフォーマット:
説明
複数のパーティションを指定するには、コンマ (,) で区切ります。 |
すべてのパーティション |
|
labelColName |
はい |
入力テーブルのラベル列の名前。 |
N/A |
|
modelName |
はい |
出力モデルの名前。 |
N/A |
|
treeNum |
はい |
フォレスト内のツリー数。有効値:1~1000。 |
100 |
|
excludedColNames |
いいえ |
このパラメーターは featureColNames と併用できません。 |
空 |
|
weightColName |
いいえ |
入力テーブルの重み列の名前。 |
N/A |
|
featureColNames |
いいえ |
トレーニングに使用される特徴列の名前。 |
labelColName と weightColName に指定された列を除くすべての列。 |
|
forceCategorical |
いいえ |
解析ルールは以下の通りです:
説明
BIGINT 列を CATEGORICAL として解析するには、forceCategorical パラメーターを使用します。 |
INT は連続型として扱われます。 |
|
algorithmTypes |
いいえ |
フォレスト内で異なるツリーアルゴリズムをどのように分散させるかを指定します。フォレストに N 個のツリーがあり、algorithmTypes=[a,b] の場合:
例えば、5つのツリーを持つフォレストで、[2,4] と設定した場合、ツリー 1 は ID3 アルゴリズムを使用し、ツリー 2 と 3 は CART アルゴリズムを使用し、ツリー 4 と 5 は C4.5 アルゴリズムを使用します。None を入力すると、アルゴリズムはフォレスト全体に均等に分散されます。 |
アルゴリズムは均等に分散されます。 |
|
randomColNum |
いいえ |
決定木を構築する際に、各分岐で考慮するランダムな特徴の数。有効値:[1,N]。N は総特徴数です。 |
log2N |
|
minNumObj |
いいえ |
リーフノードに必要なサンプルの最小数。正の整数である必要があります。 |
2 |
|
minNumPer |
いいえ |
親ノードに対するリーフノード内のサンプルの最小比率。有効値:[0,1]。 |
0.0 |
|
maxTreeDeep |
いいえ |
単一ツリーの最大深度。有効値:[1,+∞)。 |
無制限 |
|
maxRecordSize |
いいえ |
単一ツリーの構築に使用されるランダムサンプルの数。有効値:(1000,1000000]。 |
100000 |
例
-
次の SQL ステートメントを使用してトレーニングデータを生成します:
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; -
次の PAI コマンドを使用して、ランダムフォレストコンポーネントのパラメーターを送信します:
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"; -
モデルを 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> -
モデルの視覚化された出力を表示します。