Code for case study – Customer Churn with Keras/TensorFlow and H2O

This is code that accompanies a book chapter on customer churn that I have written for the German dpunkt Verlag. The book is in German and will probably appear in February: https://www.dpunkt.de/buecher/13208/9783864906107-data-science.html.

The code you find below can be used to recreate all figures and analyses from this book chapter. Because the content is exclusively for the book, my descriptions around the code had to be minimal. But I’m sure, you can get the gist, even without the book. 😉

Thank you to the following people for providing excellent code examples about customer churn:

All analyses are done in R using RStudio. For detailed session information including R version, operating system and package versions, see the sessionInfo() output at the end of this document.

All figures are produced with ggplot2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Load libraries
library(tidyverse) # for tidy data analysis
library(readr) # for fast reading of input files
library(caret) # for convenient splitting
library(mice) # mice package for Multivariate Imputation by Chained Equations (MICE)
library(keras) # for neural nets
library(lime) # for explaining neural nets
library(rsample) # for splitting training and test data
library(recipes) # for preprocessing
library(yardstick) # for evaluation
library(ggthemes) # for additional plotting themes
library(corrplot) # for correlation

theme_set(theme_minimal())
1
2
3
# Install Keras if you have not installed it before
# follow instructions if you haven't installed TensorFlow
install_keras()

Related