-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtreeVis.py
More file actions
46 lines (29 loc) · 780 Bytes
/
treeVis.py
File metadata and controls
46 lines (29 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 12 18:45:18 2019
@author: sohel
"""
import pandas as pd
import numpy as np
from sklearn import tree
# install pydotplus and graphviz
import pydotplus
from sklearn.tree import export_graphviz
from sklearn.externals.six import StringIO
from IPython.display import Image
class vis(object):
"""
This class contains visualisations for machine learning algorithms
"""
def __init__(self):
pass
def dtree_visual(self,treeClf):
dot_data = StringIO()
export_graphviz(treeClf, out_file=dot_data,
filled=True, rounded=True,
special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
return Image(graph.create_png())
def __del__(self):
pass