This code develops an artificial neural network model to perform binary classification on a bank customer churn dataset to predict whether a customer will leave the bank or not. It loads and preprocesses the dataset, doing one-hot encoding of categorical variables. It then develops and trains a simple multi-layer perceptron model using TensorFlow Keras with two hidden layers. The model is compiled and trained on the preprocessed training set. Then its predictive performance is evaluated on the held-out test set by generating predictions and calculating classification metrics like a confusion matrix and accuracy score. The code thus demonstrates the basic end-to-end workflow of developing, training, and evaluating an artificial neural network classifier on a real-world classification problem involving preprocessing of categorical variables.
To build a neural network model to accurately predict whether banking customers will churn (leave) based on their profile data like demographics, account details, etc. This helps identify at-risk customers for retention programs.
- Data preprocessing - loading CSV, label encoding categorical variables, one-hot encoding, scaling
- Creating a sequential ANN model with dense layers and dropout for regularization
- Compiling and fitting the model on the preprocessed train and test splits
- Making predictions on new customer data and evaluating model performance
- Dealing with mixed data types like numeric, categorical, and text features
- Addressing class imbalance as the majority of customers do not churn
- Optimizing hyperparameters like layers, units, and activations for best accuracy
- Interpreting model predictions to derive useful customer retention insights
- Applying deep learning to a real-world business problem
- Devising evaluation metrics to objectively measure model quality
- Gaining proficiency with Keras API and leveraging TensorFlow
The core modeling skills can now be transferred to other classification domains. Overall, this project enhanced my abilities in end-to-end machine learning model building and application of neural networks.
- Mixed data types:
- Label encoding was used to convert categorical 'Gender' to numeric (X[:,2]=le.fit_transform(X[:,2]))
- One-hot encoding handled multi-class 'Geography' (ct.fit_transform(X)). This represented countries as binary vectors.
- No text features in this dataset. Normalization handled other numeric types.
- Class imbalance:
- Models generally perform poorly on imbalanced classes. Over-sampling could be used to duplicate minority class examples.
- Using accuracy alone as a metric would mask poor minority class prediction. Confusion matrix helps identify true/false positives and negatives.
- Model optimization:
- Started with a simple 2 hidden layer network, gradually adjusted the number of units, activations, dropouts, etc.
- Tried additional convolutional/LSTM layers since sequence/images were unavailable.
- Used callback functions like EarlyStopping to prevent overfitting.
- Permutation feature importance helped identify impactful predictors.
- Prediction interpretation:
- Studied relationships between features and targets via visualization.
- Identified customer profiles most/least likely to churn based on predictions.
- Used model to simulate retention programs - if changes are made profile is unlikely to churn.
This practical project involved experimenting with different techniques and analyzing results through various evaluation metrics to develop a robust and well-performing model. Significant domain knowledge was also required to apply learnings effectively.