For this lab and in the next lessons we will build a model on customer churn binary classification problem. You will be using files_for_lab/Customer-Churn.csv
file.
You are working as an analyst with this internet service provider. You are provided with this historical data about your company's customers and their churn trends. Your task is to build a machine learning model that will help the company identify customers that are more likely to default/churn and thus prevent losses from such customers.
In this lab, we will first take a look at the degree of imbalance in the data and correct it using the techniques we learned on the class.
Here is the list of steps to be followed (building a simple model without balancing the data):
- Import the required libraries and modules that you would need.
- Read that data into Python and call the dataframe
churnData
. - Check the datatypes of all the columns in the data. You would see that the column
TotalCharges
is object type. Convert this column into numeric type usingpd.to_numeric
function. - Check for null values in the dataframe. Replace the null values.
- Use the following features:
tenure
,SeniorCitizen
,MonthlyCharges
andTotalCharges
:- Scale the features either by using normalizer or a standard scaler.
- Split the data into a training set and a test set.
- Fit a logistic regression model on the training data.
- Check the accuracy on the test data.
Note: So far we have not balanced the data.
Managing imbalance in the dataset
- Check for the imbalance.
- Use the resampling strategies used in class for upsampling and downsampling to create a balance between the two classes.
- Each time fit the model and see how the accuracy of the model is.