1from sklearn.datasets import load_iris
2from sklearn.tree import DecisionTreeClassifier
3from sklearn.tree import export_text
4iris = load_iris()
5decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)
6decision_tree = decision_tree.fit(iris.data, iris.target)
7r = export_text(decision_tree, feature_names=iris['feature_names'])
8print(r)
9
10
11
1from sklearn import tree
2X = [[0, 0], [1, 1]]
3Y = [0, 1]
4clf = tree.DecisionTreeClassifier()
5clf = clf.fit(X, Y)
1import graphviz
2dot_data = tree.export_graphviz(clf, out_file=None)
3graph = graphviz.Source(dot_data)
4graph.render("iris")
1from sklearn.datasets import load_iris
2from sklearn import tree
3X, y = load_iris(return_X_y=True)
4clf = tree.DecisionTreeClassifier()
5clf = clf.fit(X, y)