Random Forest

Data Summary: Using data about credit card customers to predict customer attrition

The variables: customer attrition, education level, marital status, and card category are continuous but should be categorical

##    CLIENTNUM         Attrition_Flag      Customer_Age      Gender         
##  Min.   :708082083   Length:10127       Min.   :26.00   Length:10127      
##  1st Qu.:713036770   Class :character   1st Qu.:41.00   Class :character  
##  Median :717926358   Mode  :character   Median :46.00   Mode  :character  
##  Mean   :739177606                      Mean   :46.33                     
##  3rd Qu.:773143533                      3rd Qu.:52.00                     
##  Max.   :828343083                      Max.   :73.00                     
##  Dependent_count Education_Level    Marital_Status     Income_Category   
##  Min.   :0.000   Length:10127       Length:10127       Length:10127      
##  1st Qu.:1.000   Class :character   Class :character   Class :character  
##  Median :2.000   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :2.346                                                           
##  3rd Qu.:3.000                                                           
##  Max.   :5.000                                                           
##  Card_Category      Months_on_book  Total_Relationship_Count
##  Length:10127       Min.   :13.00   Min.   :1.000           
##  Class :character   1st Qu.:31.00   1st Qu.:3.000           
##  Mode  :character   Median :36.00   Median :4.000           
##                     Mean   :35.93   Mean   :3.813           
##                     3rd Qu.:40.00   3rd Qu.:5.000           
##                     Max.   :56.00   Max.   :6.000           
##  Months_Inactive_12_mon Contacts_Count_12_mon  Credit_Limit  
##  Min.   :0.000          Min.   :0.000         Min.   : 1438  
##  1st Qu.:2.000          1st Qu.:2.000         1st Qu.: 2555  
##  Median :2.000          Median :2.000         Median : 4549  
##  Mean   :2.341          Mean   :2.455         Mean   : 8632  
##  3rd Qu.:3.000          3rd Qu.:3.000         3rd Qu.:11068  
##  Max.   :6.000          Max.   :6.000         Max.   :34516  
##  Total_Revolving_Bal Avg_Open_To_Buy Total_Amt_Chng_Q4_Q1 Total_Trans_Amt
##  Min.   :   0        Min.   :    3   Min.   :0.0000       Min.   :  510  
##  1st Qu.: 359        1st Qu.: 1324   1st Qu.:0.6310       1st Qu.: 2156  
##  Median :1276        Median : 3474   Median :0.7360       Median : 3899  
##  Mean   :1163        Mean   : 7469   Mean   :0.7599       Mean   : 4404  
##  3rd Qu.:1784        3rd Qu.: 9859   3rd Qu.:0.8590       3rd Qu.: 4741  
##  Max.   :2517        Max.   :34516   Max.   :3.3970       Max.   :18484  
##  Total_Trans_Ct   Total_Ct_Chng_Q4_Q1 Avg_Utilization_Ratio
##  Min.   : 10.00   Min.   :0.0000      Min.   :0.0000       
##  1st Qu.: 45.00   1st Qu.:0.5820      1st Qu.:0.0230       
##  Median : 67.00   Median :0.7020      Median :0.1760       
##  Mean   : 64.86   Mean   :0.7122      Mean   :0.2749       
##  3rd Qu.: 81.00   3rd Qu.:0.8180      3rd Qu.:0.5030       
##  Max.   :139.00   Max.   :3.7140      Max.   :0.9990

Data Summary: Now with categorical variables as factors, and a random variable for splitting the data

The Credit Card data set has 10127 observations

##    CLIENTNUM                   Attrition_Flag  Customer_Age  
##  Min.   :708082083   Attrited Customer:1627   Min.   :26.00  
##  1st Qu.:713036770   Existing Customer:8500   1st Qu.:41.00  
##  Median :717926358                            Median :46.00  
##  Mean   :739177606                            Mean   :46.33  
##  3rd Qu.:773143533                            3rd Qu.:52.00  
##  Max.   :828343083                            Max.   :73.00  
##                                                              
##     Gender          Dependent_count      Education_Level  Marital_Status
##  Length:10127       Min.   :0.000   College      :1013   Divorced: 748  
##  Class :character   1st Qu.:1.000   Doctorate    : 451   Married :4687  
##  Mode  :character   Median :2.000   Graduate     :3128   Single  :3943  
##                     Mean   :2.346   High School  :2013   Unknown : 749  
##                     3rd Qu.:3.000   Post-Graduate: 516                  
##                     Max.   :5.000   Uneducated   :1487                  
##                                     Unknown      :1519                  
##  Income_Category     Card_Category  Months_on_book  Total_Relationship_Count
##  Length:10127       Blue    :9436   Min.   :13.00   Min.   :1.000           
##  Class :character   Gold    : 116   1st Qu.:31.00   1st Qu.:3.000           
##  Mode  :character   Platinum:  20   Median :36.00   Median :4.000           
##                     Silver  : 555   Mean   :35.93   Mean   :3.813           
##                                     3rd Qu.:40.00   3rd Qu.:5.000           
##                                     Max.   :56.00   Max.   :6.000           
##                                                                             
##  Months_Inactive_12_mon Contacts_Count_12_mon  Credit_Limit  
##  Min.   :0.000          Min.   :0.000         Min.   : 1438  
##  1st Qu.:2.000          1st Qu.:2.000         1st Qu.: 2555  
##  Median :2.000          Median :2.000         Median : 4549  
##  Mean   :2.341          Mean   :2.455         Mean   : 8632  
##  3rd Qu.:3.000          3rd Qu.:3.000         3rd Qu.:11068  
##  Max.   :6.000          Max.   :6.000         Max.   :34516  
##                                                              
##  Total_Revolving_Bal Avg_Open_To_Buy Total_Amt_Chng_Q4_Q1 Total_Trans_Amt
##  Min.   :   0        Min.   :    3   Min.   :0.0000       Min.   :  510  
##  1st Qu.: 359        1st Qu.: 1324   1st Qu.:0.6310       1st Qu.: 2156  
##  Median :1276        Median : 3474   Median :0.7360       Median : 3899  
##  Mean   :1163        Mean   : 7469   Mean   :0.7599       Mean   : 4404  
##  3rd Qu.:1784        3rd Qu.: 9859   3rd Qu.:0.8590       3rd Qu.: 4741  
##  Max.   :2517        Max.   :34516   Max.   :3.3970       Max.   :18484  
##                                                                          
##  Total_Trans_Ct   Total_Ct_Chng_Q4_Q1 Avg_Utilization_Ratio     random         
##  Min.   : 10.00   Min.   :0.0000      Min.   :0.0000        Min.   :0.0000653  
##  1st Qu.: 45.00   1st Qu.:0.5820      1st Qu.:0.0230        1st Qu.:0.2531897  
##  Median : 67.00   Median :0.7020      Median :0.1760        Median :0.4945483  
##  Mean   : 64.86   Mean   :0.7122      Mean   :0.2749        Mean   :0.4976151  
##  3rd Qu.: 81.00   3rd Qu.:0.8180      3rd Qu.:0.5030        3rd Qu.:0.7433762  
##  Max.   :139.00   Max.   :3.7140      Max.   :0.9990        Max.   :0.9999414  
## 

Data Split: 70/30 into training and validation datasets

Random Forest

##                 Length Class  Mode     
## call                5  -none- call     
## type                1  -none- character
## predicted        7137  factor numeric  
## err.rate         1500  -none- numeric  
## confusion           6  -none- numeric  
## votes           14274  matrix numeric  
## oob.times        7137  -none- numeric  
## classes             2  -none- character
## importance         80  -none- numeric  
## importanceSD       60  -none- numeric  
## localImportance     0  -none- NULL     
## proximity           0  -none- NULL     
## ntree               1  -none- numeric  
## mtry                1  -none- numeric  
## forest             14  -none- list     
## y                7137  factor numeric  
## test                0  -none- NULL     
## inbag               0  -none- NULL     
## terms               3  terms  call

Variable Importance

The accuracy of the model tested on the validation data

## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  2990 
## 
##  
##                    | val$predicted_Attrition_Flag 
## val$Attrition_Flag | Attrited Customer | Existing Customer |         Row Total | 
## -------------------|-------------------|-------------------|-------------------|
##  Attrited Customer |               390 |                92 |               482 | 
##                    |          1544.620 |           251.031 |                   | 
##                    |             0.809 |             0.191 |             0.161 | 
##                    |             0.933 |             0.036 |                   | 
##                    |             0.130 |             0.031 |                   | 
## -------------------|-------------------|-------------------|-------------------|
##  Existing Customer |                28 |              2480 |              2508 | 
##                    |           296.853 |            48.244 |                   | 
##                    |             0.011 |             0.989 |             0.839 | 
##                    |             0.067 |             0.964 |                   | 
##                    |             0.009 |             0.829 |                   | 
## -------------------|-------------------|-------------------|-------------------|
##       Column Total |               418 |              2572 |              2990 | 
##                    |             0.140 |             0.860 |                   | 
## -------------------|-------------------|-------------------|-------------------|
## 
## 

Financial Impact of the Model

  1. The credit card company forgave the $100 annual fee for 418 customers that were predicted to leave, totaling 41,800 dollars.
  2. The value of a customer is 2,300 dollars per year (on average).
  3. With a success rate of 30%, the credit card company should retain 30% of the predicted attrited customers which is 390. This calculates to approximately 117 customers.
  4. 117 * 2,300 = 269,100 dollars per year.
  5. Net = 269,100 - 41,800 = 227,300 dollars.
  6. 227,300/2990 = 76.02 dollar profit per customer predicted.