-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.py
More file actions
36 lines (22 loc) · 887 Bytes
/
tree.py
File metadata and controls
36 lines (22 loc) · 887 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
from sklearn import tree
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
import sklearn.tree.export
import numpy as np
iris = load_iris()
decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)
decision_tree = decision_tree.fit(iris.data, iris.target)
r = sklearn.tree.export_text(decision_tree, feature_names=iris['feature_names'])
print(r)
from sklearn.datasets import load_iris
from sklearn import tree
X, y = load_iris(return_X_y=True)
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X, y)
print(clf)
tree.plot_tree(clf.fit(iris.data, iris.target))
dot_data = tree.export_graphviz(clf, out_file=None, feature_names=iris.feature_names,class_names=iris.target_names, filled=True,rounded=True, special_characters=True)
#graph = graphviz.Source(dot_data)
print(dot_data)
mask = np.random.rand(len(10)) < 5
print(mask)