• Show All Code
  • Hide All Code

Customer Churn Risk Analytics in Telecommunication

Deep Learning with Keras + LIME + ShinyApp + Rstudio

Written by DK WC

2019-12-25

Load data and model

load("data/customer_churn.RData")
model_keras = load_model_hdf5("model/customer_churn.hdf5", compile = FALSE)

Customer scorecard inputs

main_vars = c("tenure", "Contract", "InternetService", "MonthlyCharges", "OnlineBackup", 
    "OnlineSecurity", "DeviceProtection", "TechSupport", "StreamingMovies", "PhoneService")

commercial_vars = c("InternetService", "OnlineBackup", "OnlineSecurity", "DeviceProtection", 
    "TechSupport", "StreamingMovies", "PhoneService")

financial_vars = c("PaymentMethod")

customer_feature_vars = c(main_vars, commercial_vars, financial_vars) %>% unique

Transform original datasset

churn_data_raw = read_csv("data/WA_Fn-UseC_-Telco-Customer-Churn.csv") %>% mutate(tenure_range = case_when(tenure < 
    12 ~ "< 1 Yr", tenure < 24 ~ "1-2 Yrs", tenure < 36 ~ "2-3 Yrs", tenure >= 36 ~ 
    "Over 3 Yrs", TRUE ~ "NA"), monthly_charge_range = case_when(MonthlyCharges < 
    20 ~ "< 20 per Month", MonthlyCharges < 50 ~ "20-50 per Month", MonthlyCharges < 
    100 ~ "50-100 per Month", MonthlyCharges >= 100 ~ "Over 100 per Month", TRUE ~ 
    "NA"))

churn_data_tbl = churn_data_raw %>% drop_na() %>% select(Churn, everything())

Set-up model with Keras + LIME

assign("model_type.keras.engine.sequential.Sequential", envir = globalenv(), function(x, 
    ...) {
    "classification"
})

Predict model with Keras + LIME

assign("predict_model.keras.engine.sequential.Sequential", envir = globalenv(), function(x, 
    newdata, type, ...) {
    pred = predict_proba(object = x, x = as.matrix(newdata))
    data.frame(Yes = pred, No = 1 - pred)
})

Customer Churn Risk Analytics

https://heatwave2019.shinyapps.io/customer_churnAABBRmd/