Path: blob/master/11_chrun_prediction/churn.ipynb
1141 views
Customer Churn Prediction Using Artificial Neural Network (ANN)
Customer churn prediction is to measure why customers are leaving a business. In this tutorial we will be looking at customer churn in telecom business. We will build a deep learning model to predict the churn and use precision,recall, f1-score to measure performance of our model
Load the data
First of all, drop customerID column as it is of no use
Quick glance at above makes me realize that TotalCharges should be float but it is an object. Let's check what's going on with this column
Ahh... it is string. Lets convert it to numbers
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
pandas\_libs\lib.pyx in pandas._libs.lib.maybe_convert_numeric()
ValueError: Unable to parse string " "
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-256-06ba430a4ba5> in <module>
----> 1 pd.to_numeric(df.TotalCharges)
~\AppData\Roaming\Python\Python38\site-packages\pandas\core\tools\numeric.py in to_numeric(arg, errors, downcast)
150 coerce_numeric = errors not in ("ignore", "raise")
151 try:
--> 152 values = lib.maybe_convert_numeric(
153 values, set(), coerce_numeric=coerce_numeric
154 )
pandas\_libs\lib.pyx in pandas._libs.lib.maybe_convert_numeric()
ValueError: Unable to parse string " " at position 488
Hmmm... some values seems to be not numbers but blank string. Let's find out such rows
Remove rows with space in TotalCharges
Data Visualization
Many of the columns are yes, no etc. Let's print unique values in object columns to see data values
Some of the columns have no internet service or no phone service, that can be replaced with a simple No
Convert Yes and No to 1 or 0
One hot encoding for categorical columns
Train test split
Build a model (ANN) in tensorflow/keras
Accuracy
Precision for 0 class. i.e. Precision for customers who did not churn
Precision for 1 class. i.e. Precision for customers who actually churned
Recall for 0 class
Exercise