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.
Este exercício faz parte do curso
Credit Risk Modeling in R
Instruções do exercício
- Change the code provided such that a decision tree is constructed , including the argument
parms
and 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.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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