{ "cells": [ { "cell_type": "markdown", "id": "5d5f7cb5", "metadata": { "papermill": { "duration": 0.015014, "end_time": "2022-07-11T16:31:43.173250", "exception": false, "start_time": "2022-07-11T16:31:43.158236", "status": "completed" }, "tags": [] }, "source": [ "# Churn Prediction for Customers in the Telecom Industry " ] }, { "cell_type": "markdown", "id": "b18794f0", "metadata": { "papermill": { "duration": 0.013549, "end_time": "2022-07-11T16:31:43.201061", "exception": false, "start_time": "2022-07-11T16:31:43.187512", "status": "completed" }, "tags": [] }, "source": [ "" ] }, { "cell_type": "markdown", "id": "e464582c", "metadata": { "papermill": { "duration": 0.013213, "end_time": "2022-07-11T16:31:43.227971", "exception": false, "start_time": "2022-07-11T16:31:43.214758", "status": "completed" }, "tags": [] }, "source": [ "## About the Dataset\n", "\n", "Each row represents a customer, each column contains customer’s attributes described on the column Metadata.\n", "\n", "**The data set includes information about:**\n", "\n", "**Customers who left within the last month** – the column is called Churn\n", "\n", "**Services that each customer has signed up for** – phone, multiple lines, internet, online security, online backup, device protection, tech support, and streaming TV and movies\n", "\n", "**Customer account information** – how long they’ve been a customer, contract, payment method, paperless billing, monthly charges, and total charges\n", "\n", "**Demographic info about customers** – gender, age range, and if they have partners and dependents" ] }, { "cell_type": "markdown", "id": "ed0c4a3f", "metadata": { "papermill": { "duration": 0.014192, "end_time": "2022-07-11T16:31:43.255620", "exception": false, "start_time": "2022-07-11T16:31:43.241428", "status": "completed" }, "tags": [] }, "source": [ "## The Mission\n", "\n", "Explore the Dataset and create a model to predict if a customer is going to churn or not\n", "\n", "\n", "### Let's get started" ] }, { "cell_type": "code", "execution_count": 1, "id": "1658e554", "metadata": { "execution": { "iopub.execute_input": "2022-07-11T16:31:43.285828Z", "iopub.status.busy": "2022-07-11T16:31:43.285045Z", "iopub.status.idle": "2022-07-11T16:31:44.476704Z", "shell.execute_reply": "2022-07-11T16:31:44.475368Z" }, "papermill": { "duration": 1.21, "end_time": "2022-07-11T16:31:44.479612", "exception": false, "start_time": "2022-07-11T16:31:43.269612", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "#importing Libraries\n", "\n", "import pandas as pd \n", "import numpy as np\n", "import seaborn as sns\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt " ] }, { "cell_type": "code", "execution_count": 2, "id": "ca209eca", "metadata": { "execution": { "iopub.execute_input": "2022-07-11T16:31:44.510089Z", "iopub.status.busy": "2022-07-11T16:31:44.509360Z", "iopub.status.idle": "2022-07-11T16:31:44.571504Z", "shell.execute_reply": "2022-07-11T16:31:44.570623Z" }, "papermill": { "duration": 0.079831, "end_time": "2022-07-11T16:31:44.573929", "exception": false, "start_time": "2022-07-11T16:31:44.494098", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "#reading the data \n", "\n", "cust = pd.read_csv('../input/telco-customer-churn/WA_Fn-UseC_-Telco-Customer-Churn.csv')" ] }, { "cell_type": "code", "execution_count": 3, "id": "afd11373", "metadata": { "execution": { "iopub.execute_input": "2022-07-11T16:31:44.604137Z", "iopub.status.busy": "2022-07-11T16:31:44.603102Z", "iopub.status.idle": "2022-07-11T16:31:44.645470Z", "shell.execute_reply": "2022-07-11T16:31:44.644319Z" }, "papermill": { "duration": 0.060786, "end_time": "2022-07-11T16:31:44.648798", "exception": false, "start_time": "2022-07-11T16:31:44.588012", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
| \n", " | customerID | \n", "gender | \n", "SeniorCitizen | \n", "Partner | \n", "Dependents | \n", "tenure | \n", "PhoneService | \n", "MultipleLines | \n", "InternetService | \n", "OnlineSecurity | \n", "... | \n", "DeviceProtection | \n", "TechSupport | \n", "StreamingTV | \n", "StreamingMovies | \n", "Contract | \n", "PaperlessBilling | \n", "PaymentMethod | \n", "MonthlyCharges | \n", "TotalCharges | \n", "Churn | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "7590-VHVEG | \n", "Female | \n", "0 | \n", "Yes | \n", "No | \n", "1 | \n", "No | \n", "No phone service | \n", "DSL | \n", "No | \n", "... | \n", "No | \n", "No | \n", "No | \n", "No | \n", "Month-to-month | \n", "Yes | \n", "Electronic check | \n", "29.85 | \n", "29.85 | \n", "No | \n", "
| 1 | \n", "5575-GNVDE | \n", "Male | \n", "0 | \n", "No | \n", "No | \n", "34 | \n", "Yes | \n", "No | \n", "DSL | \n", "Yes | \n", "... | \n", "Yes | \n", "No | \n", "No | \n", "No | \n", "One year | \n", "No | \n", "Mailed check | \n", "56.95 | \n", "1889.5 | \n", "No | \n", "
| 2 | \n", "3668-QPYBK | \n", "Male | \n", "0 | \n", "No | \n", "No | \n", "2 | \n", "Yes | \n", "No | \n", "DSL | \n", "Yes | \n", "... | \n", "No | \n", "No | \n", "No | \n", "No | \n", "Month-to-month | \n", "Yes | \n", "Mailed check | \n", "53.85 | \n", "108.15 | \n", "Yes | \n", "
| 3 | \n", "7795-CFOCW | \n", "Male | \n", "0 | \n", "No | \n", "No | \n", "45 | \n", "No | \n", "No phone service | \n", "DSL | \n", "Yes | \n", "... | \n", "Yes | \n", "Yes | \n", "No | \n", "No | \n", "One year | \n", "No | \n", "Bank transfer (automatic) | \n", "42.30 | \n", "1840.75 | \n", "No | \n", "
| 4 | \n", "9237-HQITU | \n", "Female | \n", "0 | \n", "No | \n", "No | \n", "2 | \n", "Yes | \n", "No | \n", "Fiber optic | \n", "No | \n", "... | \n", "No | \n", "No | \n", "No | \n", "No | \n", "Month-to-month | \n", "Yes | \n", "Electronic check | \n", "70.70 | \n", "151.65 | \n", "Yes | \n", "
5 rows × 21 columns
\n", "| \n", " | SeniorCitizen | \n", "tenure | \n", "MonthlyCharges | \n", "TotalCharges | \n", "Churn | \n", "gender_Female | \n", "gender_Male | \n", "Partner_No | \n", "Partner_Yes | \n", "Dependents_No | \n", "... | \n", "StreamingMovies_Yes | \n", "Contract_Month-to-month | \n", "Contract_One year | \n", "Contract_Two year | \n", "PaperlessBilling_No | \n", "PaperlessBilling_Yes | \n", "PaymentMethod_Bank transfer (automatic) | \n", "PaymentMethod_Credit card (automatic) | \n", "PaymentMethod_Electronic check | \n", "PaymentMethod_Mailed check | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "0 | \n", "1 | \n", "29.85 | \n", "29.85 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "1 | \n", "1 | \n", "... | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "
| 1 | \n", "0 | \n", "34 | \n", "56.95 | \n", "1889.50 | \n", "0 | \n", "0 | \n", "1 | \n", "1 | \n", "0 | \n", "1 | \n", "... | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "
| 2 | \n", "0 | \n", "2 | \n", "53.85 | \n", "108.15 | \n", "1 | \n", "0 | \n", "1 | \n", "1 | \n", "0 | \n", "1 | \n", "... | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "
| 3 | \n", "0 | \n", "45 | \n", "42.30 | \n", "1840.75 | \n", "0 | \n", "0 | \n", "1 | \n", "1 | \n", "0 | \n", "1 | \n", "... | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "1 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "
| 4 | \n", "0 | \n", "2 | \n", "70.70 | \n", "151.65 | \n", "1 | \n", "1 | \n", "0 | \n", "1 | \n", "0 | \n", "1 | \n", "... | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "
5 rows × 46 columns
\n", "| \n", " | SeniorCitizen | \n", "tenure | \n", "MonthlyCharges | \n", "TotalCharges | \n", "gender_Female | \n", "gender_Male | \n", "Partner_No | \n", "Partner_Yes | \n", "Dependents_No | \n", "Dependents_Yes | \n", "... | \n", "StreamingMovies_Yes | \n", "Contract_Month-to-month | \n", "Contract_One year | \n", "Contract_Two year | \n", "PaperlessBilling_No | \n", "PaperlessBilling_Yes | \n", "PaymentMethod_Bank transfer (automatic) | \n", "PaymentMethod_Credit card (automatic) | \n", "PaymentMethod_Electronic check | \n", "PaymentMethod_Mailed check | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "0.0 | \n", "0.000000 | \n", "0.115423 | \n", "0.001275 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "1.0 | \n", "0.0 | \n", "... | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "
| 1 | \n", "0.0 | \n", "0.464789 | \n", "0.385075 | \n", "0.215867 | \n", "0.0 | \n", "1.0 | \n", "1.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "... | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "
| 2 | \n", "0.0 | \n", "0.014085 | \n", "0.354229 | \n", "0.010310 | \n", "0.0 | \n", "1.0 | \n", "1.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "... | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "
| 3 | \n", "0.0 | \n", "0.619718 | \n", "0.239303 | \n", "0.210241 | \n", "0.0 | \n", "1.0 | \n", "1.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "... | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 4 | \n", "0.0 | \n", "0.014085 | \n", "0.521891 | \n", "0.015330 | \n", "1.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "... | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "
5 rows × 45 columns
\n", "