Other tree options and the construction of confusion matrices

Credit Risk Modeling in R

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

Other interesting rpart() - arguments

  • In rpart()
    • weights: include case weights
  • In the control argument of rpart() (rpart.control)
    • minsplit: minimum number of observations for split attempt
    • minbucket: minimum number of observations in leaf node
Credit Risk Modeling in R
pred_undersample_class = predict(ptree_undersample, newdata = test_set, type ="class")
1     2     3    ...   29073 29079 29084 29090 29091
0     0     0    ...     1     0     0     0     0

OR

pred_undersample = predict(ptree_undersample, newdata = test_set)
          0         1
1     0.7382920 0.2617080
2     0.5665138 0.4334862
3     0.5992366 0.4007634
          ...          ... 
29084 0.7382920 0.2617080
29090 0.7382920 0.2617080
29091 0.7382920 0.2617080
Credit Risk Modeling in R

Constructing a confusion matrix

table(test_set$loan_status, pred_undersample_class)
pred_undersample_class
       0    1
  0 8314  346
  1  964   73
Credit Risk Modeling in R

Let's practice!

Credit Risk Modeling in R

Preparing Video For Download...