Main Content

prune

クラス: RegressionTree

枝刈りによる回帰サブツリーのシーケンスの作成

構文

tree1 = prune(tree)
tree1 = prune(tree,Name,Value)

説明

tree1 = prune(tree) は、入力された最適な枝刈り順序を使用して、回帰木 tree のコピーを作成します。

tree1 = prune(tree,Name,Value) は、1 つの Name,Value ペア引数で指定した追加オプションを使用して、枝刈りしたツリーを作成します。Name1,Value1,…,NameN,ValueN のように、複数の名前と値のペアの引数を任意の順番で指定できます。

入力引数

tree

fitrtree で作成された回帰木。

名前と値の引数

オプションの、コンマで区切られ Name,Value 引数のペア。ここで、Name は引数名で、Value は対応する値です。Name は一重引用符 ('') で囲まなければなりません。名前と値のペアの引数は 1 つのみ指定できます。

Alpha

0 (枝刈りなし) から 1 (1 ノードまで枝刈り) までの数値スカラー。枝刈りして、(葉ノード数の Alpha 倍) とコスト (平均二乗誤差) の和を最小にします。

Level

0 (枝刈りなし) からこの木の最大枝刈りレベル max(tree.PruneList) までの数値スカラー。prune は、このレベルまで枝刈りされた木を返します。

Nodes

1 から tree.NumNodes までの要素をもつ、数値ベクトル。Nodes に列挙された tree 枝ノードは、親ノードも枝刈りしない限り、すべて tree1 の葉ノードになります。

出力引数

tree1

回帰木。

すべて展開する

carsmall データセットを読み込みます。HorsepowerWeight は予測子変数であるとします。

load carsmall;
X = [Weight Horsepower];
varNames = {'Weight' 'Horsepower'};

データセット全体を使用して回帰木を成長させます。木を表示します。

Mdl = fitrtree(X,MPG,'PredictorNames',varNames)
Mdl = 
  RegressionTree
           PredictorNames: {'Weight'  'Horsepower'}
             ResponseName: 'Y'
    CategoricalPredictors: []
        ResponseTransform: 'none'
          NumObservations: 94


  Properties, Methods

view(Mdl,'Mode','graph');

Figure Regression tree viewer contains an axes object and other objects of type uimenu, uicontrol. The axes object contains 60 objects of type line, text. One or more of the lines displays its values using only markers

この回帰木には 16 個の枝刈りレベルがあります。

枝刈りレベル 10 まで回帰木を枝刈りします。枝刈りした木を表示します。

MdlPruned = prune(Mdl,'Level',10);
view(MdlPruned,'Mode','graph');

Figure Regression tree viewer contains an axes object and other objects of type uimenu, uicontrol. The axes object contains 24 objects of type line, text. One or more of the lines displays its values using only markers

枝刈りされた木には 6 つの枝刈りレベルがあります。

または、回帰木ビューアーの枝刈りレベル フィールドを使用して、木を刈り込めます。

ヒント

  • tree1 = prune(tree) は決定木 tree1 を返します。これは完全で枝刈りされていない tree ですが、最適な枝刈り情報が追加されています。これが有益なのは、別のツリーを枝刈りして tree を作成した場合、または枝刈りを 'off' に設定して fitrtree を使用した場合のみです。最適な枝刈りをした列に沿ってツリーを複数回枝刈りする場合は、まず最適な枝刈りをした列を作成する方が効率的です。

拡張機能

参考