Create a Decision Tree

Now that we have explored the IRIS dataset, let us create a decision tree.

We will go through this script line-by-line. Type each line in the R console as you encounter it.
  • Step 1: Load the party package.
    > library(party)
    You will see the ‘party’ package and a list of dependent packages loading.

  • Step 2: Let us now load the IRIS dataset that is available in R.
    > data(iris)
    You will see the IRIS dataset is loaded in the Environment and Workspace area.

  • Step 3: Let us create the input data frame and assign the IRIS dataset to it.
    > input = iris
    You will see the input dataframe is loaded in the Environment and Workspace area. The following command will give you the data structure of the variable.
    class(input)
    [1] “data.frame”

  • Step 4: Create the decision tree.
    > output.tree <- ctree(Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, data=iris)
    The decision tree model is now created.
    Here, Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width tells R that Species (the class of the flowers) is dependent on the attributes Sepal.Length, Sepal.Width, Petal.Length and Petal.Width.

  • Step 5: Plot the tree
    > plot(output.tree,type="simple")
    You should be able to see the following plot in the “Files and Plots” area of the IDE.

  • > print(output.tree) This will give you the following verbose output of the tree.

FUN: Want a quick random password to satisfy the annoying Sign-ups?                                                                                           
> random_password(length = 12, replace = FALSE, extended = TRUE)

results matching ""

    No results matching ""