필터 지우기
필터 지우기

How to create readable decision trees

조회 수: 7 (최근 30일)
Awais Saeed
Awais Saeed 2022년 4월 10일
댓글: Christopher McCausland 2022년 4월 12일
I am trying to produce a binary decision tree as following:
% Dataset
r2 = [0;0;1;0;1;0;0;1];
r3 = [0;0;0;0;0;1;1;0];
r4 = [0;1;1;1;1;1;1;0];
Group = [1;1;1;1;1;2;2;3];
T = table(r2,r3,r4,Group)
T = 8×4 table
r2 r3 r4 Group __ __ __ _____ 0 0 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 1 1 2 0 1 1 2 1 0 0 3
% 'Group' is the target in dataset T
model = fitrtree(T, 'Group', 'MinParentSize', 1);
% View the model as a graph
view(model,'Mode','graph');
The decision tree that MATLAB gave me is shown in MatlabTree.png. I also produced a tree for the same dataset using Latex and that is shown in LatexTree.png.
I want MATLAB to display parent nodes same as Latex tree's parent node. For example, Matlab's tree says "r3>0.5 r3>=0.5", which is not as good to read as Latex generated tree. Can this Matlab tree be made more readable like the Latex one?

답변 (1개)

Christopher McCausland
Christopher McCausland 2022년 4월 11일
Hi Awais,
I had a similar problem with Markov chains recently. I ended up using digrapgh() to solve the problem, that being said its still a lot of work.
Kind regards,
Christopher
  댓글 수: 2
Awais Saeed
Awais Saeed 2022년 4월 12일
Thanks for the suggestion @Christopher McCausland. digrapgh() is not as easy, efficient and exact as fitrtree(). I searched on the internet and it seems that the appearance cannot be changed. Let's hope that MATLAB will offer this ability in future releases.
Christopher McCausland
Christopher McCausland 2022년 4월 12일
Hi Awis,
Digraph isn't as easy you are correct, it does look good when its finsihed though. To make it quicker you can call parameters already created in 'model' Esentially you create model, use graphplot() to generate your nodes and lines and then use digraph() and plot() to generate the new plot based on the inputs from 'model'.
I hope you can get something sorted, I will have a go myself later and see if I can get anything!
Christopher

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by