EXERCISE 5.1: CHURN PREDICTION MODEL
Objective: Use the churn_data to train a logistic regression model that predicts customer churn.
Tasks:
- Split the “churn_data.csv” dataset into training and validation sets.
- Train a logistic regression model to predict the binary dependent variable churn.
- Make predictions and evaluate the model.
Steps:
- Importing Required Libraries:
1. import pandas as pd
2. from sklearn.model_selection import train_test_split
3. from sklearn.linear_model import LogisticRegression
4. from sklearn.metrics import classification_report
- pandas is used for data manipulation and analysis.
- train_test_split from sklearn.model_selection is a utility to split datasets into training and test sets.
- LogisticRegression from sklearn.linear_model is a machine learning model for classification tasks.
- classification_report from sklearn.metrics provides a way to evaluate the quality of predictions from a classification algorithm.
- Loading the Dataset:
5. churn_data = pd.read_csv('/data/churn_data.csv')
- We load the churn dataset from a CSV file into a pandas DataFrame. The dataset contains features that describe customer behavior and a target variable that indicates whether the customer has churned.
- Defining Features and Target:
6. X = churn_data.drop('churn', axis=1)
7. y = churn_data['churn']
- We separate the features (X) and the target (y). The features include all columns except the target column ‘churn’, which we want to predict. The target is the ‘churn’ column, ...
Get Mastering Marketing Data Science now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.