Manual

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 2

Decision Tree Visualization Macro
1. Macro Name: DecisionTree
2.Input: Dot. File output from [pydotplus] module
(#Warning: This tool only applies to balanced binary tree)
3.Output: DecisionTree with Lift Rate on Excel
Simple Code of pydotplus module
# Create DOT data
tree.export_graphviz(mod, out_file='tree.dot',
feature_names=data_all.columns[:-1],
class_names=None,
impurity=True,
filled=False,
proportion=None)
# Convert to png
graph = pydotplus.graphviz.graph_from_dot_file('tree.dot')
# Show graph
graph.write_png('tree.png')
2. Simple Use Case
Input: tree.dot
digraph Tree {
node [shape=box] ;
0 [label="スイーツ・お菓子 <= 2311.5\ngini = 0.031\nsamples = 199864\nvalue = [196719, 3145]"] ;
1 [label="家電 <= 97.5\ngini = 0.027\nsamples = 178648\nvalue = [176170, 2478]"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="reg_gender_cd <= 0.5\ngini = 0.022\nsamples = 145100\nvalue = [143451, 1649]"] ;
1 -> 2 ;
3 [label="gini = 0.0\nsamples = 23106\nvalue = [23104, 2]"] ;
2 -> 3 ;
4 [label="gini = 0.027\nsamples = 121994\nvalue = [120347, 1647]"] ;
2 -> 4 ;
5 [label="パソコン・周辺機器 <= 95.0\ngini = 0.048\nsamples = 33548\nvalue = [32719, 829]"] ;
1 -> 5 ;
6 [label="gini = 0.037\nsamples = 26666\nvalue = [26166, 500]"] ;
5 -> 6 ;
…………………………………
Sample output:
Proportion Lift Rate Population
reg_gender_cd <= 0.5,samples = 23106,nvalue
= 2,yprob = 0.01%
samples = 23106,nvalue = 2 0.01% 0.01 2
reg_gender_cd >= 0.5,samples = 121994,nvalue
= 1647,yprob = 1.35%
samples = 121994,nvalue = 1647 1.35% 0.86 1647
パソコン・周辺機器 <= 95.0,samples =
26666,nvalue = 500,yprob = 1.88%
samples = 26666,nvalue = 500 1.88% 1.2 500
パソコン・周辺機器 >= 95.0,samples =
6882,nvalue = 329,yprob = 4.78%
samples = 6882,nvalue = 329 4.78% 3.04 329
本・雑誌・コミック <= 539.5,samples =
10590,nvalue = 203,yprob = 1.92%
samples = 10590,nvalue = 203 1.92% 1.22 203
本・雑誌・コミック >= 539.5,samples =
3622,nvalue = 175,yprob = 4.83%
samples = 3622,nvalue = 175 4.83% 3.08 175
ダイエット・健康 <= 5060.0,samples =
3823,nvalue = 121,yprob = 3.17%
samples = 3823,nvalue = 121 3.17% 2.02 121
ダイエット・健康 >= 5060.0,samples =
3181,nvalue = 168,yprob = 5.28%
samples = 3181,nvalue = 168 5.28% 3.36 168
家電 <= 97.5,nsamples =
145100,nvalue = 1649,yprob =
1.14%
家電 >= 97.5,nsamples =
33548,nvalue = 829,yprob =
2.47%
日用品雑貨・文房具・手芸 <=
5039.0,nsamples = 14212,nvalue
= 378,yprob = 2.66%
日用品雑貨・文房具・手芸 >=
5039.0,nsamples = 7004,nvalue
= 289,yprob = 4.13%
nsamples =
199864,nvalue =
3145,yprob = 1.57%
スイーツ・お菓子 <=
2311.5,nsamples =
178648,nvalue = 2478,yprob
= 1.39%
スイーツ・お菓子 >=
2311.5,nsamples =
21216,nvalue = 667,yprob =
3.14%

Navigation menu