Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn import tree
- X = [[0, 0, 0], [0, 1, 1], [1, 0, 0], [1, 1, 0], [1, 1, 1]]
- Y = [0, 1, 1, 0, 1]
- feature_names = ['x1','x2','x3']
- target_names = ['0','1']
- clf = tree.DecisionTreeClassifier()
- clf = clf.fit(X, Y)
- # exportar em formato gráfico
- import graphviz
- dot_data = tree.export_graphviz(clf, out_file=None, filled=False, rounded=True, impurity=True,
- class_names=target_names, feature_names=feature_names )
- graph = graphviz.Source(dot_data)
- graph.render("graph")
- # exportar em formato texto
- r = tree.export_text(clf,feature_names=feature_names)
- print('\n'+r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement