Ran mutate to isolate Attrition table
CreditCardData1 <- CreditCardData %>%
mutate(Attrition_Flag = as.factor(Attrition_Flag) ,
random = runif(10127))
Split data sets
train <- CreditCardData1 %>%
filter(random < .7) %>%
select(-random)
val <- CreditCardData1 %>%
filter(random >= .7) %>%
select(-random)
Algorithm used
rf <- randomForest(Attrition_Flag~. ,
type = 'classification' ,
data = train ,
importance = T)
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")
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 | |
## -------------------|-------------------|-------------------|-------------------|
##
##