Random Forest

Objective

Created a model predicting customer attrition using RandomForest.

##    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
## spc_tbl_ [10,127 × 21] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ CLIENTNUM               : num [1:10127] 7.69e+08 8.19e+08 7.14e+08 7.70e+08 7.09e+08 ...
##  $ Attrition_Flag          : chr [1:10127] "Existing Customer" "Existing Customer" "Existing Customer" "Existing Customer" ...
##  $ Customer_Age            : num [1:10127] 45 49 51 40 40 44 51 32 37 48 ...
##  $ Gender                  : chr [1:10127] "M" "F" "M" "F" ...
##  $ Dependent_count         : num [1:10127] 3 5 3 4 3 2 4 0 3 2 ...
##  $ Education_Level         : chr [1:10127] "High School" "Graduate" "Graduate" "High School" ...
##  $ Marital_Status          : chr [1:10127] "Married" "Single" "Married" "Unknown" ...
##  $ Income_Category         : chr [1:10127] "$60K - $80K" "Less than $40K" "$80K - $120K" "Less than $40K" ...
##  $ Card_Category           : chr [1:10127] "Blue" "Blue" "Blue" "Blue" ...
##  $ Months_on_book          : num [1:10127] 39 44 36 34 21 36 46 27 36 36 ...
##  $ Total_Relationship_Count: num [1:10127] 5 6 4 3 5 3 6 2 5 6 ...
##  $ Months_Inactive_12_mon  : num [1:10127] 1 1 1 4 1 1 1 2 2 3 ...
##  $ Contacts_Count_12_mon   : num [1:10127] 3 2 0 1 0 2 3 2 0 3 ...
##  $ Credit_Limit            : num [1:10127] 12691 8256 3418 3313 4716 ...
##  $ Total_Revolving_Bal     : num [1:10127] 777 864 0 2517 0 ...
##  $ Avg_Open_To_Buy         : num [1:10127] 11914 7392 3418 796 4716 ...
##  $ Total_Amt_Chng_Q4_Q1    : num [1:10127] 1.33 1.54 2.59 1.4 2.17 ...
##  $ Total_Trans_Amt         : num [1:10127] 1144 1291 1887 1171 816 ...
##  $ Total_Trans_Ct          : num [1:10127] 42 33 20 20 28 24 31 36 24 32 ...
##  $ Total_Ct_Chng_Q4_Q1     : num [1:10127] 1.62 3.71 2.33 2.33 2.5 ...
##  $ Avg_Utilization_Ratio   : num [1:10127] 0.061 0.105 0 0.76 0 0.311 0.066 0.048 0.113 0.144 ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   CLIENTNUM = col_double(),
##   ..   Attrition_Flag = col_character(),
##   ..   Customer_Age = col_double(),
##   ..   Gender = col_character(),
##   ..   Dependent_count = col_double(),
##   ..   Education_Level = col_character(),
##   ..   Marital_Status = col_character(),
##   ..   Income_Category = col_character(),
##   ..   Card_Category = col_character(),
##   ..   Months_on_book = col_double(),
##   ..   Total_Relationship_Count = col_double(),
##   ..   Months_Inactive_12_mon = col_double(),
##   ..   Contacts_Count_12_mon = col_double(),
##   ..   Credit_Limit = col_double(),
##   ..   Total_Revolving_Bal = col_double(),
##   ..   Avg_Open_To_Buy = col_double(),
##   ..   Total_Amt_Chng_Q4_Q1 = col_double(),
##   ..   Total_Trans_Amt = col_double(),
##   ..   Total_Trans_Ct = col_double(),
##   ..   Total_Ct_Chng_Q4_Q1 = col_double(),
##   ..   Avg_Utilization_Ratio = col_double()
##   .. )
##  - attr(*, "problems")=<externalptr>
## tibble [10,127 × 22] (S3: tbl_df/tbl/data.frame)
##  $ CLIENTNUM               : num [1:10127] 7.69e+08 8.19e+08 7.14e+08 7.70e+08 7.09e+08 ...
##  $ Attrition_Flag          : Factor w/ 2 levels "Attrited Customer",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ Customer_Age            : num [1:10127] 45 49 51 40 40 44 51 32 37 48 ...
##  $ Gender                  : chr [1:10127] "M" "F" "M" "F" ...
##  $ Dependent_count         : num [1:10127] 3 5 3 4 3 2 4 0 3 2 ...
##  $ Education_Level         : chr [1:10127] "High School" "Graduate" "Graduate" "High School" ...
##  $ Marital_Status          : chr [1:10127] "Married" "Single" "Married" "Unknown" ...
##  $ Income_Category         : chr [1:10127] "$60K - $80K" "Less than $40K" "$80K - $120K" "Less than $40K" ...
##  $ Card_Category           : chr [1:10127] "Blue" "Blue" "Blue" "Blue" ...
##  $ Months_on_book          : num [1:10127] 39 44 36 34 21 36 46 27 36 36 ...
##  $ Total_Relationship_Count: num [1:10127] 5 6 4 3 5 3 6 2 5 6 ...
##  $ Months_Inactive_12_mon  : num [1:10127] 1 1 1 4 1 1 1 2 2 3 ...
##  $ Contacts_Count_12_mon   : num [1:10127] 3 2 0 1 0 2 3 2 0 3 ...
##  $ Credit_Limit            : num [1:10127] 12691 8256 3418 3313 4716 ...
##  $ Total_Revolving_Bal     : num [1:10127] 777 864 0 2517 0 ...
##  $ Avg_Open_To_Buy         : num [1:10127] 11914 7392 3418 796 4716 ...
##  $ Total_Amt_Chng_Q4_Q1    : num [1:10127] 1.33 1.54 2.59 1.4 2.17 ...
##  $ Total_Trans_Amt         : num [1:10127] 1144 1291 1887 1171 816 ...
##  $ Total_Trans_Ct          : num [1:10127] 42 33 20 20 28 24 31 36 24 32 ...
##  $ Total_Ct_Chng_Q4_Q1     : num [1:10127] 1.62 3.71 2.33 2.33 2.5 ...
##  $ Avg_Utilization_Ratio   : num [1:10127] 0.061 0.105 0 0.76 0 0.311 0.066 0.048 0.113 0.144 ...
##  $ random                  : num [1:10127] 0.288 0.788 0.409 0.883 0.94 ...

Variable Importance

The total transaction count and the total transaction amount are viewed

as important predictors for attrited customers.

Model Summary

val$predicted_attrition <- predict(rf , val)

CrossTable(val$Attrition_Flag , val$predicted_attrition)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  2990 
## 
##  
##                    | val$predicted_attrition 
## val$Attrition_Flag | Attrited Customer | Existing Customer |         Row Total | 
## -------------------|-------------------|-------------------|-------------------|
##  Attrited Customer |               391 |                91 |               482 | 
##                    |          1548.957 |           252.436 |                   | 
##                    |             0.811 |             0.189 |             0.161 | 
##                    |             0.933 |             0.035 |                   | 
##                    |             0.131 |             0.030 |                   | 
## -------------------|-------------------|-------------------|-------------------|
##  Existing Customer |                28 |              2480 |              2508 | 
##                    |           297.686 |            48.514 |                   | 
##                    |             0.011 |             0.989 |             0.839 | 
##                    |             0.067 |             0.965 |                   | 
##                    |             0.009 |             0.829 |                   | 
## -------------------|-------------------|-------------------|-------------------|
##       Column Total |               419 |              2571 |              2990 | 
##                    |             0.140 |             0.860 |                   | 
## -------------------|-------------------|-------------------|-------------------|
## 
## 

How many did I predict will leave?

448.

Cost of program:

448*$100 = $44,800.

How many will I save?

408*.30 = 112.4.

The benefit of saves

112.4*2300= $281,520.

Net profit from the program is

$281,520 - $44,800 = $236,720.

Per customer is

$236,720/ 3,001 = 78.88.