Final Project

Introduction

  • The focal concern at hand revolves around understanding the reasons behind customer attrition within Regork’s telecommunications service. Retaining existing customers is crucial for Regork’s financial success compared to acquiring new ones. The dataset at our disposal encompasses information on both current and former customers, offering insights into the factors influencing customer churn.

  • Leveraging the dataset provided by Regork, we undertake an examination of customer statuses. Through meticulous data analysis and wrangling processes, our approach involves employing fundamental machine learning models such as logistic regression, MARS, and decision trees to predict the likelihood of customers either remaining with or leaving Regork’s telecommunications services.

  • The outcome of this analysis aims to provide the CEO of Regork’s Telecommunications with actionable insights into the areas requiring attention. Depending on the revealed results, we will gain clarity on the key variables influencing customer status. Ultimately, our objective is to present Regork with tailored solutions to enhance customer retention based on the findings.

Package Required

The required packages are listed and followed by their use:

  1. tidyverse = Allows for data manipulation and also includes ggplot2 used for creation of graphs.

  2. tidymodels = Modeling and machine learning.

  3. gridExtra = Allows more flexibility with the graphs.

  4. baguette = Provides modeling for bagging (bootstrap aggregation).

  5. ranger = Supports implementation of random forests.

  6. vip = Used in construction of variable importance

  7. plots. scales = Cleaning up the graphs.

library(tidymodels)
library(tidyverse)
library(baguette)
library(vip)
library(pdp)
library(here)
library(kernlab)
library(ggplot2)

Data Analysis

First we plotted the proportion of customers that are current vs left by their contract type. Two year contracts have the biggest proportion of customers that are current. Monthly contracts have the largest proportion of customers that have left. This reaffirms the idea that contract type plays a large role in keeping customers.

ggplot(df, aes(x = Contract, fill = Status)) +
  geom_bar(position = "fill") +
  labs(title = "Proportion of Current and Former Customers by Contract Type",
       x = "Contract", y = "Proportion") +
  scale_fill_manual(values = c("blue", "grey"),
                    labels = c("Current", "Left"))

The rest of our analysis we wanted to explore how the different factors affect the average tenure length and then dive into demographics of the data and see if there are any insights and correaltions there.

Longer tenure with Online Security and Backup

ggplot(df, aes(x = OnlineSecurity, y = Tenure)) + 
  geom_boxplot() +
  theme_minimal() +
  labs(title = "Tenure vs Online Security")

ggplot(df, aes(x = OnlineBackup, y = Tenure)) + 
  geom_boxplot() +
  theme_minimal() +
  labs(title = "Tenure vs Online Backup")

Variance in tenure based on Internet service

ggplot(df, aes(x = InternetService, y = Tenure)) + 
  geom_boxplot() +
  theme_minimal() +
  labs(title = "Tenure vs Internet Service")

Demographics and Service Usage Analysis:

Gender differences in Device Protection and Online Backup use

  ggplot(df, aes(x = DeviceProtection, fill = Gender)) + 
  geom_bar(position = "dodge") +
  theme_minimal() +
  labs(title = "Device Protection Usage by Gender")

ggplot(df, aes(x = OnlineBackup, fill = Gender)) + 
  geom_bar(position = "dodge") +
  theme_minimal() +
  labs(title = "Online Backup Usage by Gender")

Senior Citizens prefer specific Internet and tech support services

ggplot(df, aes(x = InternetService, fill = as.factor(SeniorCitizen))) + 
  geom_bar(position = "dodge") +
  theme_minimal() +
  labs(title = "Internet Service Preference by Senior Citizen")

Marital status affects choices in StreamingTV and Security

ggplot(df, aes(x = StreamingTV, fill = Partner)) + 
  geom_bar(position = "dodge") +
  theme_minimal() +
  labs(title = "Streaming TV Usage by Marital Status")

Dependents impact service choices

ggplot(df, aes(x = OnlineSecurity, fill = Dependents)) + 
  geom_bar(position = "dodge") +
  theme_minimal() +
  labs(title = "Online Security Usage by Dependents")

Key Findings for Demographics and Service Usage:

  1. There does not seem to be a significant difference in device protection or online backup by gender,but males seem to have slightly less protection on average

  2. Senior Citizens prefer specific Internet and tech support services like DSL and Fiber optic.

  3. Marital status affects choices in Streaming TV and Security.If you have a partner you are significantly more likely to have a streaming service

  4. Dependents impact service choices.

Machine Learning

In this section our group will split our data and fit them to 3 different types of models: A logistics regression, Decision Tree Model, and a MARS model.

Logistics Regression

set.seed(123)
retention_split <- initial_split(df, prop = 0.7, strata = "Status")
retention_train <- training(retention_split)
retention_test  <- testing(retention_split)

retention_kfolds <- vfold_cv(retention_train, v = 5, strata = Status)

log_retention <- logistic_reg() %>% 
  fit_resamples(Status ~ ., retention_kfolds) %>%
  collect_metrics()

log_fit <- logistic_reg() %>% 
  fit(Status ~ ., data = retention_train)
log_fit %>% 
  predict(retention_test) %>%
  bind_cols(retention_test %>% select(Status)) %>%
  conf_mat(truth = Status, estimate = .pred_class)
##           Truth
## Prediction Current Left
##    Current    1362  225
##    Left        178  332

As evident from the AUC value of 0.845, the logistic regression model demonstrates a reasonably commendable performance in predicting whether a customer will remain with the company. Examining our decision matrix reveals a slight inclination toward false positives (predicting a customer will stay when they actually leave) over false negatives. Nevertheless, this underscores the overall accuracy of the model.

Decision Tree Model

# Step 1 
dt_mod <- decision_tree(mode = "classification") %>%
  set_engine("rpart")

# Step 2: create model recipe
model_recipe <- recipe(Status ~ ., data = retention_train)

# Step 3: fit model workflow
dt_fit <- workflow() %>%
  add_recipe(model_recipe) %>%
  add_model(dt_mod) %>%
  fit(data = retention_train)
rpart.plot::rpart.plot(dt_fit$fit$fit$fit)

# Step 4: K-fold
set.seed(123)
kfold <- vfold_cv(retention_train, v = 5)

# Train model
dt_results <- fit_resamples(dt_mod, model_recipe, kfold)

# Model results
collect_metrics(dt_results)
## # A tibble: 2 × 6
##   .metric  .estimator  mean     n std_err .config             
##   <chr>    <chr>      <dbl> <int>   <dbl> <chr>               
## 1 accuracy binary     0.785     5 0.00552 Preprocessor1_Model1
## 2 roc_auc  binary     0.803     5 0.00777 Preprocessor1_Model1
# Step 5
dt_mod <- decision_tree(
  mode = "classification",
  cost_complexity = tune(),
  tree_depth = tune(),
  min_n = tune()
) %>%
  set_engine("rpart")

# Create the hyperparameter grid
dt_hyper_grid <- grid_regular(
  cost_complexity(),
  tree_depth(),
  min_n(),
  levels = 5
)

# Train our model across the hyper parameter grid
set.seed(123)
dt_results <- tune_grid(dt_mod, model_recipe, resamples = kfold, grid = dt_hyper_grid)

# Get best results
show_best(dt_results, metric = "roc_auc", n = 5)
## # A tibble: 5 × 9
##   cost_complexity tree_depth min_n .metric .estimator  mean     n std_err
##             <dbl>      <int> <int> <chr>   <chr>      <dbl> <int>   <dbl>
## 1    0.0000000001         15    40 roc_auc binary     0.814     5 0.00780
## 2    0.0000000178         15    40 roc_auc binary     0.814     5 0.00780
## 3    0.00000316           15    40 roc_auc binary     0.814     5 0.00780
## 4    0.0000000001         11    40 roc_auc binary     0.814     5 0.00827
## 5    0.0000000178         11    40 roc_auc binary     0.814     5 0.00827
## # ℹ 1 more variable: .config <chr>
# Get best hyperparameter values
dt_best_model <- select_best(dt_results, metric = 'roc_auc')

# Put together final workflow
dt_final_wf <- workflow() %>%
  add_recipe(model_recipe) %>%
  add_model(dt_mod) %>%
  finalize_workflow(dt_best_model)

# Fit final workflow across entire training data
dt_final_fit <- dt_final_wf %>%
  fit(data = retention_train)

# Plot feature importance
dt_final_fit %>%
  extract_fit_parsnip() %>%
  vip(20)

# Step 5
dt_mod <- decision_tree(
  mode = "classification",
  cost_complexity = tune(),
  tree_depth = tune(),
  min_n = tune()
) %>%
  set_engine("rpart")

# Create the hyperparameter grid
dt_hyper_grid <- grid_regular(
  cost_complexity(),
  tree_depth(),
  min_n(),
  levels = 5
)

# Train our model across the hyper parameter grid
set.seed(123)
dt_results <- tune_grid(dt_mod, model_recipe, resamples = kfold, grid = dt_hyper_grid)

# Get best results
show_best(dt_results, metric = "roc_auc", n = 5)
## # A tibble: 5 × 9
##   cost_complexity tree_depth min_n .metric .estimator  mean     n std_err
##             <dbl>      <int> <int> <chr>   <chr>      <dbl> <int>   <dbl>
## 1    0.0000000001         15    40 roc_auc binary     0.814     5 0.00780
## 2    0.0000000178         15    40 roc_auc binary     0.814     5 0.00780
## 3    0.00000316           15    40 roc_auc binary     0.814     5 0.00780
## 4    0.0000000001         11    40 roc_auc binary     0.814     5 0.00827
## 5    0.0000000178         11    40 roc_auc binary     0.814     5 0.00827
## # ℹ 1 more variable: .config <chr>
# Get best hyperparameter values
dt_best_model <- select_best(dt_results, metric = 'roc_auc')

# Put together final workflow
dt_final_wf <- workflow() %>%
  add_recipe(model_recipe) %>%
  add_model(dt_mod) %>%
  finalize_workflow(dt_best_model)

# Fit final workflow across entire training data
dt_final_fit <- dt_final_wf %>%
  fit(data = retention_train)

# Plot feature importance

dt_final_fit %>%
  extract_fit_parsnip() %>%
  vip(20)

dt_final_fit %>%
  predict(retention_test) %>%
  bind_cols(retention_test %>% select(Status)) %>%
  conf_mat(truth = Status, estimate = .pred_class)
##           Truth
## Prediction Current Left
##    Current    1346  275
##    Left        194  282

Observing the AUC value of 0.814, the aforementioned Decision Tree model, although a reliable predictor of customer status, exhibits a slightly inferior performance compared to our Logistic Regression model. Additionally, our analysis indicates that the key response variables for this model were Tenure, Contract, and Total Charges.

MARS Model

mars_recipe <- recipe(Status ~ ., data = retention_train)

mars_mod <- mars(num_terms = tune(), prod_degree = tune()) %>%
  set_mode("classification")

mars_grid <- grid_regular(num_terms(range = c(1, 30)), prod_degree(), levels = 50)

mars_wf <- workflow() %>%
  add_recipe(mars_recipe) %>%
  add_model(mars_mod)

tuning_results <- mars_wf %>%
  tune_grid(resamples = retention_kfolds, grid = mars_grid)

tuning_results %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc") %>%
  arrange(desc(mean))
## # A tibble: 60 × 8
##    num_terms prod_degree .metric .estimator  mean     n std_err .config         
##        <int>       <int> <chr>   <chr>      <dbl> <int>   <dbl> <chr>           
##  1        18           1 roc_auc binary     0.851     5 0.00566 Preprocessor1_M…
##  2        19           1 roc_auc binary     0.851     5 0.00566 Preprocessor1_M…
##  3        20           1 roc_auc binary     0.851     5 0.00566 Preprocessor1_M…
##  4        21           1 roc_auc binary     0.851     5 0.00566 Preprocessor1_M…
##  5        22           1 roc_auc binary     0.851     5 0.00566 Preprocessor1_M…
##  6        23           1 roc_auc binary     0.851     5 0.00566 Preprocessor1_M…
##  7        24           1 roc_auc binary     0.851     5 0.00566 Preprocessor1_M…
##  8        25           1 roc_auc binary     0.851     5 0.00566 Preprocessor1_M…
##  9        26           1 roc_auc binary     0.851     5 0.00566 Preprocessor1_M…
## 10        27           1 roc_auc binary     0.851     5 0.00566 Preprocessor1_M…
## # ℹ 50 more rows
autoplot(tuning_results)

best_mars <- select_best(tuning_results, metric = "roc_auc")

final_mars_wf <- workflow() %>%
  add_recipe(mars_recipe) %>%
  add_model(mars_mod) %>%
  finalize_workflow(best_mars)

final_mars_wf %>% 
  fit(data = retention_train) %>%
  extract_fit_parsnip() %>%
  vip(type = "rss")

final_mars_fit <- final_mars_wf %>%
  fit(data = retention_train)

final_mars_fit %>%
  predict(retention_test) %>%
  bind_cols(retention_test %>% select(Status)) %>%
  conf_mat(truth = Status, estimate = .pred_class)
##           Truth
## Prediction Current Left
##    Current    1383  242
##    Left        157  315
final_mars_fit %>% 
  predict(retention_test, type = "prob") %>%
  mutate(truth = retention_test$Status) %>%
  roc_auc(truth, .pred_Current)
## # A tibble: 1 × 3
##   .metric .estimator .estimate
##   <chr>   <chr>          <dbl>
## 1 roc_auc binary         0.847

Recording an AUC of 0.851, the MARS model outperformed the other two models we developed. Our examination revealed that the pivotal variables in this model included Tenure, Total Charges, Monthly Charges, Electronic Check Payment, and Online Security. The confusion matrix underscored the robust predictive capability of our model, albeit with a subtle inclination toward false positives over false negatives. Furthermore, when applying the test data to the MARS model, we observed an AUC value of 0.847, affirming its highly effective ability to predict customer retention.

Conclusion

Most Important Predictor Variables

Executing a MARS model yielded an AUC or accuracy of 84.8%. The top five factors identified by this model that influence whether a customer will stay or leave are as follows:

  1. Tenure: The longer a customer remains with Regork, the less likely they are to leave. Prioritizing customer retention during the initial year or two is crucial for ensuring long-term loyalty.

  2. Total Charges: The cost a customer incurs for a product is a primary consideration in their decision-making process. Regork must balance maintaining a profitable margin with ensuring fair and competitive pricing to retain customers.

  3. Monthly Charges: Similar to total charges, monthly charges play a vital role in customer decision-making. Maintaining competitive pricing is essential for Regork to sustain its customer base.

  4. Payment Method: The model indicates that customers using electronic checks are more likely to stay. Encouraging customers using alternative payment methods to switch to electronic checks could enhance retention.

  5. Online Security: Customer perception of information security is crucial. If customers feel that Regork prioritizes data security, they are less likely to leave. Emphasizing data privacy and security can contribute to improved customer retention for Regork.

As business managers, we would focus on tenure out of all the facotrs the most because it has the greatest oppurtunity to maximize profits. Regork should focus on offering promotions and deals to customer with shorter tenures to make sure they do not switch to another provider. It is much harder for customers with longer tenures to switch easily to competitors, because they have become comfortable with their current services, and they are likely enjoying discounts that come with being a loyal customer. Therefore, by focusing on lower tenure customers, Regork can best maximize their promotional efforts.

Lost Customer Prediction

Examining our confusion matrix, our model forecasts that 557 customers are anticipated to leave Regork monthly without any retention initiatives. By multiplying this figure by the mean monthly charge for departing customers, which stands at $47, the projected revenue loss amounts to $41,218. Consequently, if Regork takes no proactive measures to retain these predicted lost customers, a monthly revenue shortfall of $41,218 is expected. Over a year, this translates to a forecasted revenue loss of $500,000.

Given this substantial potential revenue decline, it is imperative to implement strategies to retain these customers. For our proposed incentive scheme, we intend to target the variables identified as most influential in encouraging customers to remain within the Regork ecosystem.

Incentive Scheme

Because Tenure was the most important predictor variable, we believe that Regork would benefit greatly from trying to move some customers who are currently on month-to-month contracts onto one or two year contracts in the future. In order to do so, we think it would be beneficial to provide some sort of a discount for customers who agree to longer-term contracts. For instance, perhaps Regork could provide one month off of a one year contract for new customers, as well as two months off of a two year contract. This would increase the likelihood that customers would agree to long-term contracts, and therefore increase the chances that they would remain customers in the long run.

Conclusion Statement

In summary, Regork has clear yet fixable factors that would allow them to increase their customer retention rate. We propose that they focus heavily on promoting their two year contract so they can keep customers around for as long as possible. While they make more money via the monthly contracts, they lose a lot more customers. This would also greatly reduce the $41,218 that Regork would lose in revenue per month from the predicted 557 customers lost every month. While the initial costs may be high to start these incentives, they would pay back in significant revenue over time.