Introduction

As data scientists at Regork, our job is to view data related to customer retention related to Regork’s new telecommunication service. Understanding different customer behaviors is needed to be successful in this new industry. These models we have built, using the “customer_retention.csv” file, help visualize what demographics of customers have the best retention. Using these models can help the marketing team easily view helpful trends with customers. After viewing these, we built machine learning models, including a bag model, random forest model and a mars model to understand which variables in our data impacted customers the most. Throughout our research we did an analysis on our models to find what is best to retain customers.

Data Prep and Exploratory Analysis

library(tidymodels)
library(tidyverse)
library(baguette)
library(vip)
library(pdp)
library(here)
library(kernlab)
library(ggplot2)
library(ranger)
library(earth)
df <- read_csv('~/BANA4080/Data/customer_retention.csv')
Rows: 6999 Columns: 20
── Column specification ──────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (16): Gender, Partner, Dependents, PhoneService, MultipleLines, InternetService, OnlineSecurity, OnlineBac...
dbl  (4): SeniorCitizen, Tenure, MonthlyCharges, TotalCharges

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
df <- mutate(df, Status = factor(Status))
df <- na.omit(df)
ggplot(df, aes(Tenure)) +
  geom_bar(color='blue') +
  facet_wrap(~MultipleLines) +
  ggtitle('Customer Tenure and if they have Multiple Lines')+
  labs(x = 'Tenure Length', y = '')

As shown in the graph the more households that have multiple lines tend to have a longer tenure at the company.

ggplot(df, aes(MonthlyCharges)) +
  geom_histogram(color='red') +
  facet_wrap(~Status)+
  ggtitle("Monthly Charge and Status")+
  labs(x= 'Monthly Charge', y ='Total customers')
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

NA
NA
NA

Monthly Charge and Status: Most of Regork’s current customers have a monthly charge of around $25. The majority of the customers that left have a monthly charge of around $75.

ggplot(df, aes(x = Contract, fill = Status)) +
  geom_bar(position = "fill") +
  labs(title = "Customer Status by Contract Type",
       x = "Contract Type",
       y = "Proportion of Customers (%)") +
  scale_y_continuous(labels = percent_format()) + 
  scale_fill_manual(values = c("Current" = "red", "Left" = "blue"))

Customer Status by Contract type: Here you can see customers with a Month-to-Month contract type are much more likely to leave then those with the one and two year contract types. As the contract type gets longer the retention rate goes up.

Machine Learning

set.seed(123)
bag_split <- initial_split(df, prop = .7, strata = "Status")
bag_train <- training(log_split)
bag_test <- testing(log_split)
bag_recipe <- recipe(
  Status ~., 
  data = bag_train
)
tree_mod <- bag_tree() %>%
  set_engine('rpart', times = 5) %>%
  set_mode('classification')


set.seed(123)
kfold <- vfold_cv(bag_train, v = 5)

bag_results <- fit_resamples(tree_mod, bag_recipe, kfold)
collect_metrics(bag_results)
NA
NA
bag_mod <- bag_tree() %>%
set_engine("rpart", times = tune()) %>%
set_mode("classification")
# create the hyperparameter grid
bag_hyper_grid <- expand.grid(times = c(5, 25, 50, 100, 200, 300))
# train our model across the hyper parameter grid
set.seed(123)
bag_results2 <- tune_grid(bag_mod, bag_recipe, resamples = kfold, grid = bag_hyper_grid)
show_best(bag_results2, metric = "roc_auc")
#END Bag
#Start RF Model
rf_mod <- rand_forest(mode = 'classification')%>%
  set_engine('ranger')

rf_results <- fit_resamples(rf_mod,bag_recipe, kfold)

collect_metrics(rf_results)
rf_mod <- rand_forest(
mode = "classification",
trees = tune(),
mtry = tune(),
min_n = tune()
) %>%
set_engine("ranger", importance = "impurity")
# create the hyperparameter grid
rf_hyper_grid <- grid_regular(
mtry(c(2,50)),
min_n(c(1,20)),
trees(c(1,250)),
levels = 5
)
set.seed(123)
rf_results <- tune_grid(rf_mod, bag_recipe, resamples = kfold, grid = rf_hyper_grid)
→ A | warning: 26 columns were requested but there were 19 predictors in the data. 19 will be used.

There were issues with some computations   A: x1

                                                 
→ B | warning: 38 columns were requested but there were 19 predictors in the data. 19 will be used.
There were issues with some computations   A: x1

There were issues with some computations   A: x1   B: x1

                                                         
→ C | warning: 50 columns were requested but there were 19 predictors in the data. 19 will be used.
There were issues with some computations   A: x1   B: x1

There were issues with some computations   A: x1   B: x1   C: x1

There were issues with some computations   A: x2   B: x1   C: x1

There were issues with some computations   A: x2   B: x2   C: x1

There were issues with some computations   A: x2   B: x2   C: x2

There were issues with some computations   A: x3   B: x2   C: x2

There were issues with some computations   A: x3   B: x3   C: x2

There were issues with some computations   A: x3   B: x3   C: x3

There were issues with some computations   A: x4   B: x3   C: x3

There were issues with some computations   A: x4   B: x4   C: x3

There were issues with some computations   A: x4   B: x4   C: x4

There were issues with some computations   A: x5   B: x4   C: x4

There were issues with some computations   A: x5   B: x5   C: x4

There were issues with some computations   A: x5   B: x5   C: x5

There were issues with some computations   A: x6   B: x5   C: x5

There were issues with some computations   A: x6   B: x6   C: x5

There were issues with some computations   A: x6   B: x6   C: x6

There were issues with some computations   A: x7   B: x6   C: x6

There were issues with some computations   A: x7   B: x7   C: x6

There were issues with some computations   A: x7   B: x7   C: x7

There were issues with some computations   A: x8   B: x7   C: x7

There were issues with some computations   A: x8   B: x8   C: x7

There were issues with some computations   A: x8   B: x8   C: x8

There were issues with some computations   A: x9   B: x8   C: x8

There were issues with some computations   A: x9   B: x9   C: x8

There were issues with some computations   A: x9   B: x9   C: x9

There were issues with some computations   A: x10   B: x9   C: x9

There were issues with some computations   A: x10   B: x10   C: x9

There were issues with some computations   A: x10   B: x10   C: x10

There were issues with some computations   A: x11   B: x10   C: x10

There were issues with some computations   A: x11   B: x11   C: x10

There were issues with some computations   A: x11   B: x11   C: x11

There were issues with some computations   A: x12   B: x11   C: x11

There were issues with some computations   A: x12   B: x12   C: x11

There were issues with some computations   A: x12   B: x12   C: x12

There were issues with some computations   A: x13   B: x12   C: x12

There were issues with some computations   A: x13   B: x13   C: x12

There were issues with some computations   A: x13   B: x13   C: x13

There were issues with some computations   A: x14   B: x13   C: x13

There were issues with some computations   A: x14   B: x14   C: x13

There were issues with some computations   A: x14   B: x14   C: x14

There were issues with some computations   A: x15   B: x14   C: x14

There were issues with some computations   A: x15   B: x15   C: x14

There were issues with some computations   A: x15   B: x15   C: x15

There were issues with some computations   A: x16   B: x15   C: x15

There were issues with some computations   A: x16   B: x16   C: x15

There were issues with some computations   A: x16   B: x16   C: x16

There were issues with some computations   A: x17   B: x16   C: x16

There were issues with some computations   A: x17   B: x17   C: x16

There were issues with some computations   A: x17   B: x17   C: x17

There were issues with some computations   A: x18   B: x17   C: x17

There were issues with some computations   A: x18   B: x18   C: x17

There were issues with some computations   A: x18   B: x18   C: x18

There were issues with some computations   A: x19   B: x18   C: x18

There were issues with some computations   A: x19   B: x19   C: x18

There were issues with some computations   A: x19   B: x19   C: x19

There were issues with some computations   A: x20   B: x19   C: x19

There were issues with some computations   A: x20   B: x20   C: x19

There were issues with some computations   A: x20   B: x20   C: x20

There were issues with some computations   A: x21   B: x20   C: x20

There were issues with some computations   A: x21   B: x21   C: x20

There were issues with some computations   A: x21   B: x21   C: x21

There were issues with some computations   A: x22   B: x21   C: x21

There were issues with some computations   A: x22   B: x22   C: x21

There were issues with some computations   A: x22   B: x22   C: x22

There were issues with some computations   A: x23   B: x22   C: x22

There were issues with some computations   A: x23   B: x23   C: x22

There were issues with some computations   A: x23   B: x23   C: x23

There were issues with some computations   A: x24   B: x23   C: x23

There were issues with some computations   A: x24   B: x24   C: x23

There were issues with some computations   A: x24   B: x24   C: x24

There were issues with some computations   A: x25   B: x24   C: x24

There were issues with some computations   A: x25   B: x25   C: x24

There were issues with some computations   A: x25   B: x25   C: x25

There were issues with some computations   A: x26   B: x25   C: x25

There were issues with some computations   A: x26   B: x26   C: x25

There were issues with some computations   A: x26   B: x26   C: x26

There were issues with some computations   A: x27   B: x26   C: x26

There were issues with some computations   A: x27   B: x27   C: x26

There were issues with some computations   A: x27   B: x27   C: x27

There were issues with some computations   A: x28   B: x27   C: x27

There were issues with some computations   A: x28   B: x28   C: x27

There were issues with some computations   A: x28   B: x28   C: x28

There were issues with some computations   A: x29   B: x28   C: x28

There were issues with some computations   A: x29   B: x29   C: x28

There were issues with some computations   A: x29   B: x29   C: x29

There were issues with some computations   A: x30   B: x29   C: x29

There were issues with some computations   A: x30   B: x30   C: x29

There were issues with some computations   A: x30   B: x30   C: x30

There were issues with some computations   A: x31   B: x30   C: x30

There were issues with some computations   A: x31   B: x31   C: x30

There were issues with some computations   A: x31   B: x31   C: x31

There were issues with some computations   A: x32   B: x31   C: x31

There were issues with some computations   A: x32   B: x32   C: x31

There were issues with some computations   A: x32   B: x32   C: x32

There were issues with some computations   A: x33   B: x32   C: x32

There were issues with some computations   A: x33   B: x33   C: x32

There were issues with some computations   A: x33   B: x33   C: x33

There were issues with some computations   A: x34   B: x33   C: x33

There were issues with some computations   A: x34   B: x34   C: x33

There were issues with some computations   A: x34   B: x34   C: x34

There were issues with some computations   A: x35   B: x34   C: x34

There were issues with some computations   A: x35   B: x35   C: x34

There were issues with some computations   A: x35   B: x35   C: x35

There were issues with some computations   A: x36   B: x35   C: x35

There were issues with some computations   A: x36   B: x36   C: x35

There were issues with some computations   A: x36   B: x36   C: x36

There were issues with some computations   A: x37   B: x36   C: x36

There were issues with some computations   A: x37   B: x37   C: x36

There were issues with some computations   A: x37   B: x37   C: x37

There were issues with some computations   A: x38   B: x37   C: x37

There were issues with some computations   A: x38   B: x38   C: x37

There were issues with some computations   A: x38   B: x38   C: x38

There were issues with some computations   A: x39   B: x38   C: x38

There were issues with some computations   A: x39   B: x39   C: x38

There were issues with some computations   A: x39   B: x39   C: x39

There were issues with some computations   A: x40   B: x39   C: x39

There were issues with some computations   A: x40   B: x40   C: x39

There were issues with some computations   A: x40   B: x40   C: x40

There were issues with some computations   A: x41   B: x40   C: x40

There were issues with some computations   A: x41   B: x41   C: x40

There were issues with some computations   A: x41   B: x41   C: x41

There were issues with some computations   A: x42   B: x41   C: x41

There were issues with some computations   A: x42   B: x42   C: x41

There were issues with some computations   A: x42   B: x42   C: x42

There were issues with some computations   A: x43   B: x42   C: x42

There were issues with some computations   A: x43   B: x43   C: x42

There were issues with some computations   A: x43   B: x43   C: x43

There were issues with some computations   A: x44   B: x43   C: x43

There were issues with some computations   A: x44   B: x44   C: x43

There were issues with some computations   A: x44   B: x44   C: x44

There were issues with some computations   A: x45   B: x44   C: x44

There were issues with some computations   A: x45   B: x45   C: x44

There were issues with some computations   A: x45   B: x45   C: x45

There were issues with some computations   A: x46   B: x45   C: x45

There were issues with some computations   A: x46   B: x46   C: x45

There were issues with some computations   A: x46   B: x46   C: x46

There were issues with some computations   A: x47   B: x46   C: x46

There were issues with some computations   A: x47   B: x47   C: x46

There were issues with some computations   A: x47   B: x47   C: x47

There were issues with some computations   A: x48   B: x47   C: x47

There were issues with some computations   A: x48   B: x48   C: x47

There were issues with some computations   A: x48   B: x48   C: x48

There were issues with some computations   A: x49   B: x48   C: x48

There were issues with some computations   A: x49   B: x49   C: x48

There were issues with some computations   A: x49   B: x49   C: x49

There were issues with some computations   A: x50   B: x49   C: x49

There were issues with some computations   A: x50   B: x50   C: x49

There were issues with some computations   A: x50   B: x50   C: x50

There were issues with some computations   A: x51   B: x50   C: x50

There were issues with some computations   A: x51   B: x51   C: x50

There were issues with some computations   A: x51   B: x51   C: x51

There were issues with some computations   A: x52   B: x51   C: x51

There were issues with some computations   A: x52   B: x52   C: x51

There were issues with some computations   A: x52   B: x52   C: x52

There were issues with some computations   A: x53   B: x52   C: x52

There were issues with some computations   A: x53   B: x53   C: x52

There were issues with some computations   A: x53   B: x53   C: x53

There were issues with some computations   A: x54   B: x53   C: x53

There were issues with some computations   A: x54   B: x54   C: x53

There were issues with some computations   A: x54   B: x54   C: x54

There were issues with some computations   A: x55   B: x54   C: x54

There were issues with some computations   A: x55   B: x55   C: x54

There were issues with some computations   A: x55   B: x55   C: x55

There were issues with some computations   A: x56   B: x55   C: x55

There were issues with some computations   A: x56   B: x56   C: x55

There were issues with some computations   A: x56   B: x56   C: x56

There were issues with some computations   A: x57   B: x56   C: x56

There were issues with some computations   A: x57   B: x57   C: x56

There were issues with some computations   A: x57   B: x57   C: x57

There were issues with some computations   A: x58   B: x57   C: x57

There were issues with some computations   A: x58   B: x58   C: x57

There were issues with some computations   A: x58   B: x58   C: x58

There were issues with some computations   A: x59   B: x58   C: x58

There were issues with some computations   A: x59   B: x59   C: x58

There were issues with some computations   A: x59   B: x59   C: x59

There were issues with some computations   A: x60   B: x59   C: x59

There were issues with some computations   A: x60   B: x60   C: x59

There were issues with some computations   A: x60   B: x60   C: x60

There were issues with some computations   A: x61   B: x60   C: x60

There were issues with some computations   A: x61   B: x61   C: x60

There were issues with some computations   A: x61   B: x61   C: x61

There were issues with some computations   A: x62   B: x61   C: x61

There were issues with some computations   A: x62   B: x62   C: x61

There were issues with some computations   A: x62   B: x62   C: x62

There were issues with some computations   A: x63   B: x62   C: x62

There were issues with some computations   A: x63   B: x63   C: x62

There were issues with some computations   A: x63   B: x63   C: x63

There were issues with some computations   A: x64   B: x63   C: x63

There were issues with some computations   A: x64   B: x64   C: x63

There were issues with some computations   A: x64   B: x64   C: x64

There were issues with some computations   A: x65   B: x64   C: x64

There were issues with some computations   A: x65   B: x65   C: x64

There were issues with some computations   A: x65   B: x65   C: x65

There were issues with some computations   A: x66   B: x65   C: x65

There were issues with some computations   A: x66   B: x66   C: x65

There were issues with some computations   A: x66   B: x66   C: x66

There were issues with some computations   A: x67   B: x66   C: x66

There were issues with some computations   A: x67   B: x67   C: x66

There were issues with some computations   A: x67   B: x67   C: x67

There were issues with some computations   A: x68   B: x67   C: x67

There were issues with some computations   A: x68   B: x68   C: x67

There were issues with some computations   A: x68   B: x68   C: x68

There were issues with some computations   A: x69   B: x68   C: x68

There were issues with some computations   A: x69   B: x69   C: x68

There were issues with some computations   A: x69   B: x69   C: x69

There were issues with some computations   A: x70   B: x69   C: x69

There were issues with some computations   A: x70   B: x70   C: x69

There were issues with some computations   A: x70   B: x70   C: x70

There were issues with some computations   A: x71   B: x70   C: x70

There were issues with some computations   A: x71   B: x71   C: x70

There were issues with some computations   A: x71   B: x71   C: x71

There were issues with some computations   A: x72   B: x71   C: x71

There were issues with some computations   A: x72   B: x72   C: x71

There were issues with some computations   A: x72   B: x72   C: x72

There were issues with some computations   A: x73   B: x72   C: x72

There were issues with some computations   A: x73   B: x73   C: x72

There were issues with some computations   A: x73   B: x73   C: x73

There were issues with some computations   A: x74   B: x73   C: x73

There were issues with some computations   A: x74   B: x74   C: x73

There were issues with some computations   A: x74   B: x74   C: x74

There were issues with some computations   A: x75   B: x74   C: x74

There were issues with some computations   A: x75   B: x75   C: x74

There were issues with some computations   A: x75   B: x75   C: x75

There were issues with some computations   A: x76   B: x75   C: x75

There were issues with some computations   A: x76   B: x76   C: x75

There were issues with some computations   A: x76   B: x76   C: x76

There were issues with some computations   A: x77   B: x76   C: x76

There were issues with some computations   A: x77   B: x77   C: x76

There were issues with some computations   A: x77   B: x77   C: x77

There were issues with some computations   A: x78   B: x77   C: x77

There were issues with some computations   A: x78   B: x78   C: x77

There were issues with some computations   A: x78   B: x78   C: x78

There were issues with some computations   A: x79   B: x78   C: x78

There were issues with some computations   A: x79   B: x79   C: x78

There were issues with some computations   A: x79   B: x79   C: x79

There were issues with some computations   A: x80   B: x79   C: x79

There were issues with some computations   A: x80   B: x80   C: x79

There were issues with some computations   A: x80   B: x80   C: x80

There were issues with some computations   A: x81   B: x80   C: x80

There were issues with some computations   A: x81   B: x81   C: x80

There were issues with some computations   A: x81   B: x81   C: x81

There were issues with some computations   A: x82   B: x81   C: x81

There were issues with some computations   A: x82   B: x82   C: x81

There were issues with some computations   A: x82   B: x82   C: x82

There were issues with some computations   A: x83   B: x82   C: x82

There were issues with some computations   A: x83   B: x83   C: x82

There were issues with some computations   A: x83   B: x83   C: x83

There were issues with some computations   A: x84   B: x83   C: x83

There were issues with some computations   A: x84   B: x84   C: x83

There were issues with some computations   A: x84   B: x84   C: x84

There were issues with some computations   A: x85   B: x84   C: x84

There were issues with some computations   A: x85   B: x85   C: x84

There were issues with some computations   A: x85   B: x85   C: x85

There were issues with some computations   A: x86   B: x85   C: x85

There were issues with some computations   A: x86   B: x86   C: x85

There were issues with some computations   A: x86   B: x86   C: x86

There were issues with some computations   A: x87   B: x86   C: x86

There were issues with some computations   A: x87   B: x87   C: x86

There were issues with some computations   A: x87   B: x87   C: x87

There were issues with some computations   A: x88   B: x87   C: x87

There were issues with some computations   A: x88   B: x88   C: x87

There were issues with some computations   A: x88   B: x88   C: x88

There were issues with some computations   A: x89   B: x88   C: x88

There were issues with some computations   A: x89   B: x89   C: x88

There were issues with some computations   A: x89   B: x89   C: x89

There were issues with some computations   A: x90   B: x89   C: x89

There were issues with some computations   A: x90   B: x90   C: x89

There were issues with some computations   A: x90   B: x90   C: x90

There were issues with some computations   A: x91   B: x90   C: x90

There were issues with some computations   A: x91   B: x91   C: x90

There were issues with some computations   A: x91   B: x91   C: x91

There were issues with some computations   A: x92   B: x91   C: x91

There were issues with some computations   A: x92   B: x92   C: x91

There were issues with some computations   A: x92   B: x92   C: x92

There were issues with some computations   A: x93   B: x92   C: x92

There were issues with some computations   A: x93   B: x93   C: x92

There were issues with some computations   A: x93   B: x93   C: x93

There were issues with some computations   A: x94   B: x93   C: x93

There were issues with some computations   A: x94   B: x94   C: x93

There were issues with some computations   A: x94   B: x94   C: x94

There were issues with some computations   A: x95   B: x94   C: x94

There were issues with some computations   A: x95   B: x95   C: x94

There were issues with some computations   A: x95   B: x95   C: x95

There were issues with some computations   A: x96   B: x95   C: x95

There were issues with some computations   A: x96   B: x96   C: x95

There were issues with some computations   A: x96   B: x96   C: x96

There were issues with some computations   A: x97   B: x96   C: x96

There were issues with some computations   A: x97   B: x97   C: x96

There were issues with some computations   A: x97   B: x97   C: x97

There were issues with some computations   A: x98   B: x97   C: x97

There were issues with some computations   A: x98   B: x98   C: x97

There were issues with some computations   A: x98   B: x98   C: x98

There were issues with some computations   A: x99   B: x98   C: x98

There were issues with some computations   A: x99   B: x99   C: x98

There were issues with some computations   A: x99   B: x99   C: x99

There were issues with some computations   A: x100   B: x99   C: x99

There were issues with some computations   A: x100   B: x100   C: x99

There were issues with some computations   A: x100   B: x100   C: x100

There were issues with some computations   A: x101   B: x100   C: x100

There were issues with some computations   A: x101   B: x101   C: x100

There were issues with some computations   A: x101   B: x101   C: x101

There were issues with some computations   A: x102   B: x101   C: x101

There were issues with some computations   A: x102   B: x102   C: x101

There were issues with some computations   A: x102   B: x102   C: x102

There were issues with some computations   A: x103   B: x102   C: x102

There were issues with some computations   A: x103   B: x103   C: x102

There were issues with some computations   A: x103   B: x103   C: x103

There were issues with some computations   A: x104   B: x103   C: x103

There were issues with some computations   A: x104   B: x104   C: x103

There were issues with some computations   A: x104   B: x104   C: x104

There were issues with some computations   A: x105   B: x104   C: x104

There were issues with some computations   A: x105   B: x105   C: x104

There were issues with some computations   A: x105   B: x105   C: x105

There were issues with some computations   A: x106   B: x105   C: x105

There were issues with some computations   A: x106   B: x106   C: x105

There were issues with some computations   A: x106   B: x106   C: x106

There were issues with some computations   A: x107   B: x106   C: x106

There were issues with some computations   A: x107   B: x107   C: x106

There were issues with some computations   A: x107   B: x107   C: x107

There were issues with some computations   A: x108   B: x107   C: x107

There were issues with some computations   A: x108   B: x108   C: x107

There were issues with some computations   A: x108   B: x108   C: x108

There were issues with some computations   A: x109   B: x108   C: x108

There were issues with some computations   A: x109   B: x109   C: x108

There were issues with some computations   A: x109   B: x109   C: x109

There were issues with some computations   A: x110   B: x109   C: x109

There were issues with some computations   A: x110   B: x110   C: x109

There were issues with some computations   A: x110   B: x110   C: x110

There were issues with some computations   A: x111   B: x110   C: x110

There were issues with some computations   A: x111   B: x111   C: x110

There were issues with some computations   A: x111   B: x111   C: x111

There were issues with some computations   A: x112   B: x111   C: x111

There were issues with some computations   A: x112   B: x112   C: x111

There were issues with some computations   A: x112   B: x112   C: x112

There were issues with some computations   A: x113   B: x112   C: x112

There were issues with some computations   A: x113   B: x113   C: x112

There were issues with some computations   A: x113   B: x113   C: x113

There were issues with some computations   A: x114   B: x113   C: x113

There were issues with some computations   A: x114   B: x114   C: x113

There were issues with some computations   A: x114   B: x114   C: x114

There were issues with some computations   A: x115   B: x114   C: x114

There were issues with some computations   A: x115   B: x115   C: x114

There were issues with some computations   A: x115   B: x115   C: x115

There were issues with some computations   A: x116   B: x115   C: x115

There were issues with some computations   A: x116   B: x116   C: x115

There were issues with some computations   A: x116   B: x116   C: x116

There were issues with some computations   A: x117   B: x116   C: x116

There were issues with some computations   A: x117   B: x117   C: x116

There were issues with some computations   A: x117   B: x117   C: x117

There were issues with some computations   A: x118   B: x117   C: x117

There were issues with some computations   A: x118   B: x118   C: x117

There were issues with some computations   A: x118   B: x118   C: x118

There were issues with some computations   A: x119   B: x118   C: x118

There were issues with some computations   A: x119   B: x119   C: x118

There were issues with some computations   A: x119   B: x119   C: x119

There were issues with some computations   A: x120   B: x119   C: x119

There were issues with some computations   A: x120   B: x120   C: x119

There were issues with some computations   A: x120   B: x120   C: x120

There were issues with some computations   A: x121   B: x120   C: x120

There were issues with some computations   A: x121   B: x121   C: x120

There were issues with some computations   A: x121   B: x121   C: x121

There were issues with some computations   A: x122   B: x121   C: x121

There were issues with some computations   A: x122   B: x122   C: x121

There were issues with some computations   A: x122   B: x122   C: x122

There were issues with some computations   A: x123   B: x122   C: x122

There were issues with some computations   A: x123   B: x123   C: x122

There were issues with some computations   A: x123   B: x123   C: x123

There were issues with some computations   A: x124   B: x123   C: x123

There were issues with some computations   A: x124   B: x124   C: x123

There were issues with some computations   A: x124   B: x124   C: x124

There were issues with some computations   A: x125   B: x124   C: x124

There were issues with some computations   A: x125   B: x125   C: x124

There were issues with some computations   A: x125   B: x125   C: x125

There were issues with some computations   A: x125   B: x125   C: x125
# model results
show_best(rf_results, metric = "roc_auc")
NA

rf_best_hyperparameters <- select_best(rf_results, metric = "roc_auc")
# create final workflow object
final_rf_wf <- workflow() %>%
add_recipe(bag_recipe) %>%
add_model(rf_mod) %>%
finalize_workflow(rf_best_hyperparameters)
# fit final workflow object
rf_final_fit <- final_rf_wf %>%
fit(data = bag_train)
# plot feature importance
rf_final_fit %>%
extract_fit_parsnip() %>%
vip(num_features = 20)


#End RF

In the random forest model you can see that tenure it the most important feature in this model.

#Start Mars
mars_mod <- mars(
  mode='classification',
  num_terms = tune(), 
  prod_degree = tune())


hyper_grid <- grid_regular(
  num_terms(range = c(10, 50)),
  prod_degree(), 
  levels = 10  
 )  


results <- tune_grid(mars_mod, bag_recipe, resamples = kfold, grid = hyper_grid)  

show_best(results, metric = "roc_auc")
NA

As show above the MARS model is the best at predicting.

best_hyperparameters <- select_best(results, metric = "roc_auc")

final_wf <- workflow() %>%
   add_model(mars_mod) %>%
   add_formula(Status ~ .) %>%
   finalize_workflow(best_hyperparameters)

# plot top 20 influential variables
final_wf %>%
   fit(data = bag_train) %>% 
   extract_fit_parsnip() %>%
   vip(20)



#End Mars
confus_matrix <- logistic_reg() %>%
fit(Status ~ ., data = bag_train)

confus_matrix %>% predict(bag_test) %>% 
  bind_cols(bag_test %>% select(Status)) %>%
  conf_mat(truth = Status, estimate = .pred_class)
          Truth
Prediction Current Left
   Current    1362  225
   Left        178  332

Business Analysis and Conclusion

head(predictions)

unique(predictions$.pred_class)




predictions <- final_wf %>%
   last_fit(bag_split) %>%
   collect_predictions()

at_risk_customers <- predictions %>%
  filter(.pred_class == "Left")

print(at_risk_customers)
colnames(at_risk_customers)
 [1] "Gender"           "SeniorCitizen"    "Partner"          "Dependents"       "Tenure"          
 [6] "PhoneService"     "MultipleLines"    "InternetService"  "OnlineSecurity"   "OnlineBackup"    
[11] "DeviceProtection" "TechSupport"      "StreamingTV"      "StreamingMovies"  "Contract"        
[16] "PaperlessBilling" "PaymentMethod"    "MonthlyCharges"   "TotalCharges"     "Status...20"     
[21] ".pred_class"      ".pred_Current"    ".pred_Left"       "id"               ".row"            
[26] "Status...26"      ".config"         
test_predictions <- bind_cols(bag_test, predictions)
New names:
• `Status` -> `Status...20`
• `Status` -> `Status...26`
at_risk_customers <- test_predictions %>%
  filter(.pred_class == "Left")

predicted_loss <- at_risk_customers %>%
  summarize(total_loss = sum(MonthlyCharges, na.rm = TRUE))

print(predicted_loss)
NA
NA
NA

Conclusion

Looking at Tenure which is our most influential variable shows the importance of targeting customers who have been with the company the longest. Strategies for keeping this retention could include offering perks and promotions when customers have been with Regork for a certain amount of time. This will build the amount of loyal customers Regork has.

Another very influential factor is Contract Length. Looking at our models it is easy to see customers with longer contracts have greater retention rates then those with shorter contracts. Having ads and promotions targeted to those with shorter contracts to switch to longer contracts may be helpful in keeping these customers.

Both Total and Monthly Charges were found to be influential variables. This showed that customers who spend the most money have the most faith in Regork. It is important to us as a company to keep these loyal customers, as they are responsible for a great amount of Regork’s profits. A good way to do this would be to offer them promotions for their loyalty.

Using an Electronic Check as your payment method was also an influential aspect. This could be because of the increase in core customers trusting and having access to this technology. This is another influential demographic to focus effort on.

If nothing is done we could be looking at a loss of $37,228.65 per month meaning a yearly loss of $446,743.80 This would be a fairly large blow to the company that would only continue to snowball. So Overall we propose providing a 20% discount to customers that are at risk and also provide incentives to month to month contract customers to attempt to lock them into a longer term deal.

Limitations we face are that we only have some variables. We are lacking family statistics that could potentially show how having multiple people in a household could lead to streaming services being more relevant as well as how charges reflect the size. Other limitations faced could be timing aspects as the only timing aspect present is tenure, but our prediction could be strengthened by customers who have left over a longer time period.

LS0tDQp0aXRsZTogIkRhdGEgTWluaW5nIEZpbmFsIFByb2plY3QiDQpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sNCi0tLQ0KDQojIyMgSW50cm9kdWN0aW9uDQpBcyBkYXRhIHNjaWVudGlzdHMgYXQgUmVnb3JrLCBvdXIgam9iIGlzIHRvIHZpZXcgZGF0YSByZWxhdGVkIHRvIGN1c3RvbWVyIHJldGVudGlvbiByZWxhdGVkIHRvIFJlZ29ya+KAmXMgbmV3IHRlbGVjb21tdW5pY2F0aW9uIHNlcnZpY2UuIFVuZGVyc3RhbmRpbmcgZGlmZmVyZW50IGN1c3RvbWVyIGJlaGF2aW9ycyBpcyBuZWVkZWQgdG8gYmUgc3VjY2Vzc2Z1bCBpbiB0aGlzIG5ldyBpbmR1c3RyeS4gVGhlc2UgbW9kZWxzIHdlIGhhdmUgYnVpbHQsIHVzaW5nIHRoZSDigJxjdXN0b21lcl9yZXRlbnRpb24uY3N24oCdIGZpbGUsIG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