Changing the prior probabilities
As mentioned in the video, you can also change the prior probabilities to obtain a decision tree. This is an indirect way of adjusting the importance of misclassifications for each class. You can specify another argument inside rpart() to include prior probabities. The argument you are looking for has the following form
parms = list(prior=c(non_default_proportion, default_proportion))
The rpart package is now already loaded in your workspace.
Den här övningen är en del av kursen
Credit Risk Modeling in R
Övningsinstruktioner
- Change the code provided such that a decision tree is constructed , including the argument
parmsand changing the proportion of non-defaults to 0.7, and of defaults to 0.3 (they should always sum up to 1). Additionally, includecontrol = rpart.control(cp = 0.001)as well. - Plot the decision tree using the function plot and the tree object name. Add a second argument "uniform=TRUE" to get equal-sized branches.
- Add labels to the tree using function
text()and the decision tree object name.
Interaktiv övning med praktiskt arbete
Testa den här övningen genom att slutföra den här exempelkoden.
# Change the code below such that a tree is constructed with adjusted prior probabilities.
tree_prior <- rpart(loan_status ~ ., method = "class",
data = training_set)
# Plot the decision tree
# Add labels to the decision tree