Skip to content

Commit

Permalink
started with decision trees
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSomen committed Jul 18, 2018
1 parent c4fa026 commit 7840457
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Decision_Trees/decision_tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#%%
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier

iris = load_iris()
X = iris['data'][:,:2]
Y = iris['target']

tree_clf = DecisionTreeClassifier(max_depth=2)
tree_clf.fit(X,Y)

#%%
from sklearn.tree import export_graphviz
export_graphviz(
tree_clf,
out_file="Decision_Trees/iris_tree.dot",
feature_names=iris['feature_names'][2:],
class_names=iris['target_names'],
rounded=True,
filled=True
)

17 changes: 17 additions & 0 deletions Decision_Trees/iris_tree.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
digraph Tree {
node [shape=box, style="filled, rounded", color="black", fontname=helvetica] ;
edge [fontname=helvetica] ;
0 [label="petal length (cm) <= 5.45\ngini = 0.6667\nsamples = 150\nvalue = [50, 50, 50]\nclass = setosa", fillcolor="#e5813900"] ;
1 [label="petal width (cm) <= 2.8\ngini = 0.2374\nsamples = 52\nvalue = [45, 6, 1]\nclass = setosa", fillcolor="#e58139d8"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="gini = 0.449\nsamples = 7\nvalue = [1, 5, 1]\nclass = versicolor", fillcolor="#39e581aa"] ;
1 -> 2 ;
3 [label="gini = 0.0435\nsamples = 45\nvalue = [44, 1, 0]\nclass = setosa", fillcolor="#e58139f9"] ;
1 -> 3 ;
4 [label="petal length (cm) <= 6.15\ngini = 0.5458\nsamples = 98\nvalue = [5, 44, 49]\nclass = virginica", fillcolor="#8139e518"] ;
0 -> 4 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
5 [label="gini = 0.5084\nsamples = 43\nvalue = [5, 28, 10]\nclass = versicolor", fillcolor="#39e5818b"] ;
4 -> 5 ;
6 [label="gini = 0.4126\nsamples = 55\nvalue = [0, 16, 39]\nclass = virginica", fillcolor="#8139e596"] ;
4 -> 6 ;
}
Binary file added Decision_Trees/iris_tree.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7840457

Please sign in to comment.