1. Determined number of Observations at 10,127 using mutate

Ran mutate to isolate Attrition table

CreditCardData1 <- CreditCardData %>%
  mutate(Attrition_Flag = as.factor(Attrition_Flag)  ,
         random = runif(10127))

2. Created Training and Validation Data Sets

Split data sets

train <- CreditCardData1 %>% 
  filter(random < .7) %>% 
  select(-random)

val <- CreditCardData1 %>% 
  filter(random >= .7) %>% 
  select(-random)

3. Random Forest Function

Algorithm used

rf <- randomForest(Attrition_Flag~. , 
                   type = 'classification' ,
                   data = train ,
                   importance = T)

4. Variable Importance

Determined to importance of the variable by using random forest, then created a table to show this

rf$importance %>% 
  data.frame() %>%
  rownames_to_column(var = "Feature") %>%
  ggplot(aes(x = fct_reorder(Feature, MeanDecreaseAccuracy), y = MeanDecreaseAccuracy)) + 
  geom_pointrange(aes(ymin = 0, ymax = MeanDecreaseAccuracy), color = "cadetblue", size = .3) + 
  theme_minimal() + 
  coord_flip() + 
  labs(x = "", y = "", title = "Variaable Importance using MeanDecreaseAccuracy")

5. The accuracy of the model, tested on the validation data

Tested the validation of data, then ran the model through a cross table to determine: the customer retention program consists of forgiving the anual fee of $100 (on average), the value of a customer is $2,300 per year (on average), customer retention programs have a 30% success rate

val$predicted_Attrition_Flag <- predict(rf , val)

CrossTable(val$Attrition_Flag , val$predicted_Attrition_Flag)
## 
##  
##    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 |               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 |                   | 
## -------------------|-------------------|-------------------|-------------------|
## 
## 

6. Answers to questions

The customer retention program consists of forgiving the anual fee of $100 (on average), the value of a customer is $2,300 per year (on average), customer retention programs have a 30% success rate

  1. 419 are predicted to leave
  2. The cost of the program is $41,900
  3. Given 419 are leaving that will cost us 2,300 x 419 = 963,700