Get startedGet started for free

Visualizing classification trees

Due to government rules to prevent illegal discrimination, lenders are required to explain why a loan application was rejected.

The structure of classification trees can be depicted visually, which helps to understand how the tree makes its decisions. The model loan_model that you fit in the last exercise is available to use.

This exercise is part of the course

Supervised Learning in R: Classification

View Course

Exercise instructions

  • Type loan_model to see a text representation of the classification tree.
  • Load the rpart.plot package.
  • Apply the rpart.plot() function to the loan model to visualize the tree.
  • See how changing other plotting parameters impacts the visualization by running the supplied command.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Examine the loan_model object


# Load the rpart.plot package


# Plot the loan_model with default settings


# Plot the loan_model with customized settings
rpart.plot(loan_model, type = 3, box.palette = c("red", "green"), fallen.leaves = TRUE)
Edit and Run Code