Main Content

このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。

view

構文

view(tree)
view(tree,Name,Value)

説明

view(tree) は、決定木 tree のテキスト説明を返します。

view(tree,Name,Value) では、1 つ以上の Name,Value の引数ペアで指定された追加オプションを使用して、tree を記述します。

入力引数

tree

関数 fitctree または compact を使用して作成された分類木またはコンパクト分類木。

名前と値の引数

オプションの引数のペアを Name1=Value1,...,NameN=ValueN として指定します。ここで Name は引数名、Value は対応する値です。名前と値の引数は他の引数の後ろにする必要がありますが、ペアの順序は関係ありません。

R2021a より前では、名前と値をそれぞれコンマを使って区切り、Name を引用符で囲みます。

Mode

tree の表示を記述する値。'graph' または 'text' のいずれかです。'graph' は、木を照会するためのコントロールが含まれている、tree の表示用のユーザー インターフェイスを起動します。'text' は、出力をコマンド ウィンドウに送信して tree を記述します。

既定値: 'text'

すべて展開する

学習済み分類木をテキストおよびグラフィックで表示します。

フィッシャーのアヤメのデータセットを読み込みます。

load fisheriris

すべての測定値を使用して分類木に学習をさせます。

Mdl = fitctree(meas,species);

学習済み分類木をテキストで表示します。

view(Mdl)
Decision tree for classification
1  if x3<2.45 then node 2 elseif x3>=2.45 then node 3 else setosa
2  class = setosa
3  if x4<1.75 then node 4 elseif x4>=1.75 then node 5 else versicolor
4  if x3<4.95 then node 6 elseif x3>=4.95 then node 7 else versicolor
5  class = virginica
6  if x4<1.65 then node 8 elseif x4>=1.65 then node 9 else versicolor
7  class = virginica
8  class = versicolor
9  class = virginica

学習済み分類木をグラフィックで表示します。

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

{"String":"Figure Classification tree viewer contains an axes object and other objects of type uimenu, uicontrol. The axes object contains 18 objects of type line, text.","Tex":[],"LaTex":[]}

フィッシャーのアヤメのデータセットを読み込みます。

load fisheriris

すべての測定値を使用して 100 本の分類の bag of trees を成長させます。

rng(1) % For reproducibility
Mdl = TreeBagger(100,meas,species);

または、fitcensembleを使用して分類の bag of trees を成長させることもできます。

MdlTreeBaggerモデル オブジェクトです。Mdl.Trees は、100 本の学習済み分類 bag of trees を 100 行 1 列の cell 配列に格納します。つまり、Mdl.Trees の各セルに CompactClassificationTree モデル オブジェクトが格納されます。

bag 内の 10 番目の分類木のグラフを表示します。

Tree10 = Mdl.Trees{10};
view(Tree10,'Mode','graph');

{"String":"Figure Classification tree viewer contains an axes object and other objects of type uimenu, uicontrol. The axes object contains 27 objects of type line, text.","Tex":[],"LaTex":[]}

既定の設定では、bag of trees に対して木を深く成長させます。

フィッシャーのアヤメのデータセットを読み込みます。

load fisheriris

すべての測定値を使用して 100 本の分類木のアンサンブルをブースティングします。弱学習器として木の切り株を指定します。

t = templateTree('MaxNumSplits',1);
Mdl = fitcensemble(meas,species,'Method','AdaBoostM2','Learners',t);

MdlClassificationEnsembleモデル オブジェクトです。Mdl.Trained は、100 本の学習済み分類木から成るアンサンブルを 100 行 1 列の cell 配列に格納します。つまり、Mdl.Trained の各セルに CompactClassificationTree モデル オブジェクトが格納されます。

アンサンブル内の 10 番目の分類木のグラフを表示します。

Tree10 = Mdl.Trained{10};
view(Tree10,'Mode','graph');

{"String":"Figure Classification tree viewer contains an axes object and other objects of type uimenu, uicontrol. The axes object contains 9 objects of type line, text.","Tex":[],"LaTex":[]}

アンサンブルの弱学習器として切り株を指定したので、このグラフは木の切り株を示します。ただし、この動作は fitcensemble の既定ではありません。既定の設定では、fitcensemble は木のブースティング アンサンブルに対して浅い木を成長させます。つまり、'Learners'templateTree('MaxNumSplits',10) になります。

ヒント

木のアンサンブルの木 t を表示するには、次のコードのいずれかを入力します。

view(Ens.Trained{t})
view(Bag.Trees{t})

  • Ens は、fitcensemble によって返された完全なアンサンブルまたは compact によって返されたコンパクトなアンサンブルです。

  • Bag は、TreeBagger によって返された完全な bag of trees または compact によって返されたコンパクトな bag of trees です。

コマンド ウィンドウで tree を保存するには、関数 findall および setdiff を使用して Figure のハンドルを取得し、関数 saveas を使用して tree を保存します。

before = findall(groot,'Type','figure'); % Find all figures
view(Mdl,'Mode','graph')
after = findall(groot,'Type','figure');
h = setdiff(after,before); % Get the figure handle of the tree viewer
saveas(h,'a.png')

拡張機能