Advertisement
toweber

decision_tree_gini

Aug 15th, 2022
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. from sklearn import tree
  2.  
  3. X = [[0, 0, 0], [0, 1, 1], [1, 0, 0], [1, 1, 0], [1, 1, 1]]
  4. Y = [0, 1, 1, 0, 1]
  5.  
  6. feature_names = ['x1','x2','x3']
  7. target_names = ['0','1']
  8.  
  9. clf = tree.DecisionTreeClassifier()
  10. clf = clf.fit(X, Y)
  11.  
  12. # exportar em formato gráfico
  13. import graphviz
  14. dot_data = tree.export_graphviz(clf, out_file=None, filled=False, rounded=True, impurity=True,
  15.                                 class_names=target_names, feature_names=feature_names )
  16.  
  17. graph = graphviz.Source(dot_data)
  18. graph.render("graph")
  19.  
  20. # exportar em formato texto
  21. r = tree.export_text(clf,feature_names=feature_names)
  22. print('\n'+r)
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement