#*****************************************************************************80 # ## iris_decision_tree plots a decision tree for Iris classification. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 04 September 2020 # # Author: # # John Burkardt # cat ( date ( ), "\n" ) cat ( "\n" ) cat ( "iris_decision_tree\n" ) cat ( " ", version$version.string, "\n" ) cat ( " Plot a decision tree for the iris classification task." ) library ( igraph ) filename = "iris_decision_tree.png" png ( filename ) G <- graph.tree ( n = 1, children = 2 ) V(G)$name <- "Start" G <- G + vertices ( "setosa" ) G <- G + edge ( "Start", "setosa", label = "x3 < 2.45" ) G <- G + vertices ( "1" ) G <- G + edge ( "Start", "1", label = "2.45 <= x3" ) G <- G + vertices ( "2" ) G <- G + edge ( "1", "2", label = "x4 < 1.75" ) G <- G + vertices ( "virginica(1)" ) G <- G + edge ( "1", "virginica(1)", label = "1.75 <= x4" ) G <- G + vertices ( "3" ) G <- G + edge ( "2", "3", label = "x3 < 4.95" ) G <- G + vertices ( "virginica(2)" ) G <- G + edge ( "2", "virginica(2)", label = "4.95 <= x3" ) G <- G + vertices ( "versicolor" ) G <- G + edge ( "3", "versicolor", label = "x4 < 1.65" ) G <- G + vertices ( "virginica(3)" ) G <- G + edge ( "3", "virginica(3)", label = "1.65 <= x4" ) my_layout <- layout.reingold.tilford ( G, params = list ( root = "Start" ) ) plot ( G, layout = my_layout, vertex.size = 40, main = "Iris_decision_tree" ) cat ( ' Graphics saved as "', filename, '"\n' ) # # Terminate. # cat ( "\n" ) cat ( "iris_decision_tree:\n" ) cat ( " Normal end of execution.\n" ) quit ( )