Skip to content

Commit 096efea

Browse files
committed
Updated DT with minor graphviz knowledge before answering on stackoverflow
1 parent 3707208 commit 096efea

11 files changed

+92
-30
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Sklearn/.DS_Store

0 Bytes
Binary file not shown.

Sklearn/DecisionTrees/.DS_Store

0 Bytes
Binary file not shown.

Sklearn/DecisionTrees/.ipynb_checkpoints/DecisionTreeAnatomy-checkpoint.ipynb

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
},
259259
{
260260
"cell_type": "code",
261-
"execution_count": 10,
261+
"execution_count": 9,
262262
"metadata": {
263263
"collapsed": false
264264
},
@@ -269,7 +269,7 @@
269269
"4.5"
270270
]
271271
},
272-
"execution_count": 10,
272+
"execution_count": 9,
273273
"metadata": {},
274274
"output_type": "execute_result"
275275
}
@@ -280,7 +280,7 @@
280280
},
281281
{
282282
"cell_type": "code",
283-
"execution_count": 11,
283+
"execution_count": 10,
284284
"metadata": {
285285
"collapsed": false
286286
},
@@ -291,7 +291,7 @@
291291
"array([1])"
292292
]
293293
},
294-
"execution_count": 11,
294+
"execution_count": 10,
295295
"metadata": {},
296296
"output_type": "execute_result"
297297
}
@@ -310,7 +310,7 @@
310310
},
311311
{
312312
"cell_type": "code",
313-
"execution_count": 12,
313+
"execution_count": 11,
314314
"metadata": {
315315
"collapsed": false
316316
},
@@ -321,7 +321,7 @@
321321
"array([1, 1, 0, 2, 2, 0, 2, 1, 0, 1])"
322322
]
323323
},
324-
"execution_count": 12,
324+
"execution_count": 11,
325325
"metadata": {},
326326
"output_type": "execute_result"
327327
}
@@ -346,7 +346,7 @@
346346
},
347347
{
348348
"cell_type": "code",
349-
"execution_count": 13,
349+
"execution_count": 12,
350350
"metadata": {
351351
"collapsed": false
352352
},
@@ -361,7 +361,7 @@
361361
},
362362
{
363363
"cell_type": "code",
364-
"execution_count": 14,
364+
"execution_count": 13,
365365
"metadata": {
366366
"collapsed": false
367367
},
@@ -372,7 +372,7 @@
372372
},
373373
{
374374
"cell_type": "code",
375-
"execution_count": 15,
375+
"execution_count": 14,
376376
"metadata": {
377377
"collapsed": false
378378
},
@@ -384,7 +384,7 @@
384384
"<IPython.core.display.Image object>"
385385
]
386386
},
387-
"execution_count": 15,
387+
"execution_count": 14,
388388
"metadata": {},
389389
"output_type": "execute_result"
390390
}
@@ -394,6 +394,31 @@
394394
"Image(filename = PATH[0] + \"/dotfiles/iris_depth2_decisionTree.png\")"
395395
]
396396
},
397+
{
398+
"cell_type": "markdown",
399+
"metadata": {},
400+
"source": [
401+
"I edited the file to have text colors using nano (text editor)"
402+
]
403+
},
404+
{
405+
"cell_type": "code",
406+
"execution_count": null,
407+
"metadata": {
408+
"collapsed": true
409+
},
410+
"outputs": [],
411+
"source": []
412+
},
413+
{
414+
"cell_type": "code",
415+
"execution_count": null,
416+
"metadata": {
417+
"collapsed": true
418+
},
419+
"outputs": [],
420+
"source": []
421+
},
397422
{
398423
"cell_type": "markdown",
399424
"metadata": {},
@@ -403,7 +428,7 @@
403428
},
404429
{
405430
"cell_type": "code",
406-
"execution_count": 16,
431+
"execution_count": 15,
407432
"metadata": {
408433
"collapsed": true
409434
},
@@ -422,7 +447,7 @@
422447
},
423448
{
424449
"cell_type": "code",
425-
"execution_count": 19,
450+
"execution_count": 16,
426451
"metadata": {
427452
"collapsed": true
428453
},

Sklearn/DecisionTrees/DecisionTreeAnatomy.ipynb

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
},
259259
{
260260
"cell_type": "code",
261-
"execution_count": 10,
261+
"execution_count": 9,
262262
"metadata": {
263263
"collapsed": false
264264
},
@@ -269,7 +269,7 @@
269269
"4.5"
270270
]
271271
},
272-
"execution_count": 10,
272+
"execution_count": 9,
273273
"metadata": {},
274274
"output_type": "execute_result"
275275
}
@@ -280,7 +280,7 @@
280280
},
281281
{
282282
"cell_type": "code",
283-
"execution_count": 11,
283+
"execution_count": 10,
284284
"metadata": {
285285
"collapsed": false
286286
},
@@ -291,7 +291,7 @@
291291
"array([1])"
292292
]
293293
},
294-
"execution_count": 11,
294+
"execution_count": 10,
295295
"metadata": {},
296296
"output_type": "execute_result"
297297
}
@@ -310,7 +310,7 @@
310310
},
311311
{
312312
"cell_type": "code",
313-
"execution_count": 12,
313+
"execution_count": 11,
314314
"metadata": {
315315
"collapsed": false
316316
},
@@ -321,7 +321,7 @@
321321
"array([1, 1, 0, 2, 2, 0, 2, 1, 0, 1])"
322322
]
323323
},
324-
"execution_count": 12,
324+
"execution_count": 11,
325325
"metadata": {},
326326
"output_type": "execute_result"
327327
}
@@ -346,7 +346,7 @@
346346
},
347347
{
348348
"cell_type": "code",
349-
"execution_count": 13,
349+
"execution_count": 12,
350350
"metadata": {
351351
"collapsed": false
352352
},
@@ -361,7 +361,7 @@
361361
},
362362
{
363363
"cell_type": "code",
364-
"execution_count": 14,
364+
"execution_count": 13,
365365
"metadata": {
366366
"collapsed": false
367367
},
@@ -372,7 +372,7 @@
372372
},
373373
{
374374
"cell_type": "code",
375-
"execution_count": 15,
375+
"execution_count": 14,
376376
"metadata": {
377377
"collapsed": false
378378
},
@@ -384,7 +384,7 @@
384384
"<IPython.core.display.Image object>"
385385
]
386386
},
387-
"execution_count": 15,
387+
"execution_count": 14,
388388
"metadata": {},
389389
"output_type": "execute_result"
390390
}
@@ -394,6 +394,31 @@
394394
"Image(filename = PATH[0] + \"/dotfiles/iris_depth2_decisionTree.png\")"
395395
]
396396
},
397+
{
398+
"cell_type": "markdown",
399+
"metadata": {},
400+
"source": [
401+
"I edited the file to have text colors using nano (text editor)"
402+
]
403+
},
404+
{
405+
"cell_type": "code",
406+
"execution_count": null,
407+
"metadata": {
408+
"collapsed": true
409+
},
410+
"outputs": [],
411+
"source": []
412+
},
413+
{
414+
"cell_type": "code",
415+
"execution_count": null,
416+
"metadata": {
417+
"collapsed": true
418+
},
419+
"outputs": [],
420+
"source": []
421+
},
397422
{
398423
"cell_type": "markdown",
399424
"metadata": {},
@@ -403,7 +428,7 @@
403428
},
404429
{
405430
"cell_type": "code",
406-
"execution_count": 16,
431+
"execution_count": 15,
407432
"metadata": {
408433
"collapsed": true
409434
},
@@ -422,7 +447,7 @@
422447
},
423448
{
424449
"cell_type": "code",
425-
"execution_count": 19,
450+
"execution_count": 16,
426451
"metadata": {
427452
"collapsed": true
428453
},
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
digraph Tree {
2+
node [shape=box] ;
3+
0 [label="petal length (cm) <= 2.45\ngini = 0.665\nsamples = 112\nvalue = [38, 40, 34]\nclass = versicolor"] ;
4+
1 [label="gini = 0.0\nsamples = 38\nvalue = [38, 0, 0]\nclass = setosa"] ;
5+
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
6+
2 [label="petal length (cm) <= 4.95\ngini = 0.497\nsamples = 74\nvalue = [0, 40, 34]\nclass = versicolor"] ;
7+
0 -> 2 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
8+
3 [label="gini = 0.136\nsamples = 41\nvalue = [0, 38, 3]\nclass = versicolor"] ;
9+
2 -> 3 ;
10+
4 [label=<<FONT COLOR="#008000">node type: leaf</FONT><br/><FONT COLOR="black">gini = 0.114<br/>samples = 33<br/>value = [0, 2, 31]<br/>class = virginica</FONT>>] ;
11+
2 -> 4 ;
12+
}
219 KB
Loading

Sklearn/DecisionTrees/dotfiles/iris_depth2_decisionTreeExample.dot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ node [shape=box] ;
44
1 [label="gini = 0.0\nsamples = 38\nvalue = [38, 0, 0]\nclass = setosa"] ;
55
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
66
2 [label="petal length (cm) <= 4.95\ngini = 0.497\nsamples = 74\nvalue = [0, 40, 34]\nclass = versicolor"] ;
7-
0 -> 2 [labeldistance=2.5, labelangle=-45, headlabel="False", arrowsize=1.5, penwidth = 2.5] ;
7+
0 -> 2 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
88
3 [label="gini = 0.136\nsamples = 41\nvalue = [0, 38, 3]\nclass = versicolor"] ;
9-
2 -> 3 [labeldistance=2.5, labelangle=45, headlabel="True", arrowsize=1.5, penwidth = 2.5] ;
9+
2 -> 3 ;
1010
4 [label="gini = 0.114\nsamples = 33\nvalue = [0, 2, 31]\nclass = virginica"] ;
11-
2 -> 4 [labeldistance=2.5, labelangle=-75, headlabel="False"];
12-
}
11+
2 -> 4 ;
12+
}
-1.36 KB
Loading

Sklearn/DecisionTrees/iris_depth2_decisionTree.dot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ node [shape=box] ;
77
0 -> 2 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
88
3 [label="gini = 0.153\nsamples = 36\nvalue = [0, 33, 3]\nclass = versicolor"] ;
99
2 -> 3 ;
10-
4 [label="gini = 0.05\nsamples = 39\nvalue = [0, 1, 38]\nclass = virginica"] ;
10+
4 [label="node type: <FONT COLOR='green'>leaf/terminal</FONT>\ngini = 0.05\nsamples = 39\nvalue = [0, 1, 38]\nclass = virginica"] ;
1111
2 -> 4 ;
12-
}
12+
}

0 commit comments

Comments
 (0)