load("data/customer_churn.RData")
model_keras = load_model_hdf5("model/customer_churn.hdf5", compile = FALSE)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) %>%
uniquechurn_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())assign("model_type.keras.engine.sequential.Sequential", envir = globalenv(), function(x,
...) {
"classification"
})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)
})