Computing a bad rate given a fixed acceptance rate
In the video, you learned how to compute the bad rate (or, the percentage of defaults) in the loan portfolio of a bank when given:
- a specific model
- the acceptance rate
In this exercise, you will compute the bad rate that a bank can expect when using the pruned tree ptree_prior
that you fitted before, and an acceptance rate of 80%. As a reminder, the tree is plotted on your right hand side.
This is a part of the course
“Credit Risk Modeling in R”
Exercise instructions
- In the script, you are provided the code to make predictions for the probability of default using the pruned tree and
test_set
. Remember that if you use thepredict()
function for a tree, the probability of default can be found in the second column. Therefore[,2]
was pasted to thepredict()
function. - Obtain the cut-off that leads to an acceptance rate of 80%, using
prob_default_prior
. You can use the quantile()- function to do this, setting the second argument to 0.8. Assign the namecutoff_prior
. - The code to obtain the actual binary default predictions (0 or 1) is provided. ifelse() here. Name the object
bin_pred_prior_80
. - The code to select the default indicators of
test_set
for the accepted loans acording to a 80% acceptance rate is provided. - Compute the percentage of defaults (or the "bad rate") for the accepted loans. This is the number of occurences of
1
inaccepted_status_prior_80
, divided by the total number of instances in this vector. Print the solution to your R-console.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Make predictions for the probability of default using the pruned tree and the test set.
prob_default_prior <- predict(ptree_prior, newdata = test_set)[ ,2]
# Obtain the cutoff for acceptance rate 80%
# Obtain the binary predictions.
bin_pred_prior_80 <- ifelse(prob_default_prior > cutoff_prior, 1, 0)
# Obtain the actual default status for the accepted loans
accepted_status_prior_80 <- test_set$loan_status[bin_pred_prior_80 == 0]
# Obtain the bad rate for the accepted loans