You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2109 lines
3.2 MiB

2 years ago
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'><img src='../Pierian_Data_Logo.png'/></a>\n",
"___\n",
"<center><em>Copyright by Pierian Data Inc.</em></center>\n",
"<center><em>For more information, visit us at <a href='http://www.pieriandata.com'>www.pieriandata.com</a></em></center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Supervised Learning Capstone Project - Tree Methods Focus - SOLUTIONS\n",
"\n",
"\n",
"\n",
"## Make sure to review the introduction video to understand the 3 ways of approaching this project exercise!\n",
"\n",
"----\n",
"\n",
"**Ways to approach the project:**\n",
" 1. Open a new notebook, read in the data, and then analyze and visualize whatever you want, then create a predictive model.\n",
" 2. Use this notebook as a general guide, completing the tasks in bold shown below.\n",
" 3. Skip to the solutions notebook and video, and treat project at a more relaxing code along walkthrough lecture series.\n",
"\n",
"------\n",
"------\n",
"\n",
"## GOAL: Create a model to predict whether or not a customer will Churn .\n",
"\n",
"----\n",
"----\n",
"\n",
"\n",
"## Complete the Tasks in Bold Below!\n",
"\n",
"## Part 0: Imports and Read in the Data\n",
"\n",
"**TASK: Run the filled out cells below to import libraries and read in your data. The data file is \"Telco-Customer-Churn.csv\"**"
]
},
{
"cell_type": "code",
"execution_count": 132,
"metadata": {},
"outputs": [],
"source": [
"# RUN THESE CELLS TO START THE PROJECT!\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns"
]
},
{
"cell_type": "code",
"execution_count": 133,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('../DATA/Telco-Customer-Churn.csv')"
]
},
{
"cell_type": "code",
"execution_count": 134,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>customerID</th>\n",
" <th>gender</th>\n",
" <th>SeniorCitizen</th>\n",
" <th>Partner</th>\n",
" <th>Dependents</th>\n",
" <th>tenure</th>\n",
" <th>PhoneService</th>\n",
" <th>MultipleLines</th>\n",
" <th>InternetService</th>\n",
" <th>OnlineSecurity</th>\n",
" <th>...</th>\n",
" <th>DeviceProtection</th>\n",
" <th>TechSupport</th>\n",
" <th>StreamingTV</th>\n",
" <th>StreamingMovies</th>\n",
" <th>Contract</th>\n",
" <th>PaperlessBilling</th>\n",
" <th>PaymentMethod</th>\n",
" <th>MonthlyCharges</th>\n",
" <th>TotalCharges</th>\n",
" <th>Churn</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>7590-VHVEG</td>\n",
" <td>Female</td>\n",
" <td>0</td>\n",
" <td>Yes</td>\n",
" <td>No</td>\n",
" <td>1</td>\n",
" <td>No</td>\n",
" <td>No phone service</td>\n",
" <td>DSL</td>\n",
" <td>No</td>\n",
" <td>...</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>Month-to-month</td>\n",
" <td>Yes</td>\n",
" <td>Electronic check</td>\n",
" <td>29.85</td>\n",
" <td>29.85</td>\n",
" <td>No</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>5575-GNVDE</td>\n",
" <td>Male</td>\n",
" <td>0</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>34</td>\n",
" <td>Yes</td>\n",
" <td>No</td>\n",
" <td>DSL</td>\n",
" <td>Yes</td>\n",
" <td>...</td>\n",
" <td>Yes</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>One year</td>\n",
" <td>No</td>\n",
" <td>Mailed check</td>\n",
" <td>56.95</td>\n",
" <td>1889.50</td>\n",
" <td>No</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3668-QPYBK</td>\n",
" <td>Male</td>\n",
" <td>0</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>2</td>\n",
" <td>Yes</td>\n",
" <td>No</td>\n",
" <td>DSL</td>\n",
" <td>Yes</td>\n",
" <td>...</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>Month-to-month</td>\n",
" <td>Yes</td>\n",
" <td>Mailed check</td>\n",
" <td>53.85</td>\n",
" <td>108.15</td>\n",
" <td>Yes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>7795-CFOCW</td>\n",
" <td>Male</td>\n",
" <td>0</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>45</td>\n",
" <td>No</td>\n",
" <td>No phone service</td>\n",
" <td>DSL</td>\n",
" <td>Yes</td>\n",
" <td>...</td>\n",
" <td>Yes</td>\n",
" <td>Yes</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>One year</td>\n",
" <td>No</td>\n",
" <td>Bank transfer (automatic)</td>\n",
" <td>42.30</td>\n",
" <td>1840.75</td>\n",
" <td>No</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>9237-HQITU</td>\n",
" <td>Female</td>\n",
" <td>0</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>2</td>\n",
" <td>Yes</td>\n",
" <td>No</td>\n",
" <td>Fiber optic</td>\n",
" <td>No</td>\n",
" <td>...</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>Month-to-month</td>\n",
" <td>Yes</td>\n",
" <td>Electronic check</td>\n",
" <td>70.70</td>\n",
" <td>151.65</td>\n",
" <td>Yes</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 21 columns</p>\n",
"</div>"
],
"text/plain": [
" customerID gender SeniorCitizen Partner Dependents tenure PhoneService \\\n",
"0 7590-VHVEG Female 0 Yes No 1 No \n",
"1 5575-GNVDE Male 0 No No 34 Yes \n",
"2 3668-QPYBK Male 0 No No 2 Yes \n",
"3 7795-CFOCW Male 0 No No 45 No \n",
"4 9237-HQITU Female 0 No No 2 Yes \n",
"\n",
" MultipleLines InternetService OnlineSecurity ... DeviceProtection \\\n",
"0 No phone service DSL No ... No \n",
"1 No DSL Yes ... Yes \n",
"2 No DSL Yes ... No \n",
"3 No phone service DSL Yes ... Yes \n",
"4 No Fiber optic No ... No \n",
"\n",
" TechSupport StreamingTV StreamingMovies Contract PaperlessBilling \\\n",
"0 No No No Month-to-month Yes \n",
"1 No No No One year No \n",
"2 No No No Month-to-month Yes \n",
"3 Yes No No One year No \n",
"4 No No No Month-to-month Yes \n",
"\n",
" PaymentMethod MonthlyCharges TotalCharges Churn \n",
"0 Electronic check 29.85 29.85 No \n",
"1 Mailed check 56.95 1889.50 No \n",
"2 Mailed check 53.85 108.15 Yes \n",
"3 Bank transfer (automatic) 42.30 1840.75 No \n",
"4 Electronic check 70.70 151.65 Yes \n",
"\n",
"[5 rows x 21 columns]"
]
},
"execution_count": 134,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 1: Quick Data Check\n",
"\n",
"**TASK: Confirm quickly with .info() methods the datatypes and non-null values in your dataframe.**"
]
},
{
"cell_type": "code",
"execution_count": 135,
"metadata": {},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 136,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 7032 entries, 0 to 7031\n",
"Data columns (total 21 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 customerID 7032 non-null object \n",
" 1 gender 7032 non-null object \n",
" 2 SeniorCitizen 7032 non-null int64 \n",
" 3 Partner 7032 non-null object \n",
" 4 Dependents 7032 non-null object \n",
" 5 tenure 7032 non-null int64 \n",
" 6 PhoneService 7032 non-null object \n",
" 7 MultipleLines 7032 non-null object \n",
" 8 InternetService 7032 non-null object \n",
" 9 OnlineSecurity 7032 non-null object \n",
" 10 OnlineBackup 7032 non-null object \n",
" 11 DeviceProtection 7032 non-null object \n",
" 12 TechSupport 7032 non-null object \n",
" 13 StreamingTV 7032 non-null object \n",
" 14 StreamingMovies 7032 non-null object \n",
" 15 Contract 7032 non-null object \n",
" 16 PaperlessBilling 7032 non-null object \n",
" 17 PaymentMethod 7032 non-null object \n",
" 18 MonthlyCharges 7032 non-null float64\n",
" 19 TotalCharges 7032 non-null float64\n",
" 20 Churn 7032 non-null object \n",
"dtypes: float64(2), int64(2), object(17)\n",
"memory usage: 1.1+ MB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Get a quick statistical summary of the numeric columns with .describe() , you should notice that many columns are categorical, meaning you will eventually need to convert them to dummy variables.**"
]
},
{
"cell_type": "code",
"execution_count": 137,
"metadata": {},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 138,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>SeniorCitizen</th>\n",
" <th>tenure</th>\n",
" <th>MonthlyCharges</th>\n",
" <th>TotalCharges</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>7032.000000</td>\n",
" <td>7032.000000</td>\n",
" <td>7032.000000</td>\n",
" <td>7032.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>0.162400</td>\n",
" <td>32.421786</td>\n",
" <td>64.798208</td>\n",
" <td>2283.300441</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>0.368844</td>\n",
" <td>24.545260</td>\n",
" <td>30.085974</td>\n",
" <td>2266.771362</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>0.000000</td>\n",
" <td>1.000000</td>\n",
" <td>18.250000</td>\n",
" <td>18.800000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>0.000000</td>\n",
" <td>9.000000</td>\n",
" <td>35.587500</td>\n",
" <td>401.450000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>0.000000</td>\n",
" <td>29.000000</td>\n",
" <td>70.350000</td>\n",
" <td>1397.475000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>0.000000</td>\n",
" <td>55.000000</td>\n",
" <td>89.862500</td>\n",
" <td>3794.737500</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>1.000000</td>\n",
" <td>72.000000</td>\n",
" <td>118.750000</td>\n",
" <td>8684.800000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" SeniorCitizen tenure MonthlyCharges TotalCharges\n",
"count 7032.000000 7032.000000 7032.000000 7032.000000\n",
"mean 0.162400 32.421786 64.798208 2283.300441\n",
"std 0.368844 24.545260 30.085974 2266.771362\n",
"min 0.000000 1.000000 18.250000 18.800000\n",
"25% 0.000000 9.000000 35.587500 401.450000\n",
"50% 0.000000 29.000000 70.350000 1397.475000\n",
"75% 0.000000 55.000000 89.862500 3794.737500\n",
"max 1.000000 72.000000 118.750000 8684.800000"
]
},
"execution_count": 138,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.describe()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Part 2: Exploratory Data Analysis\n",
"\n",
"## General Feature Exploration\n",
"\n",
"**TASK: Confirm that there are no NaN cells by displaying NaN values per feature column.**"
]
},
{
"cell_type": "code",
"execution_count": 139,
"metadata": {},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 140,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"customerID 0\n",
"gender 0\n",
"SeniorCitizen 0\n",
"Partner 0\n",
"Dependents 0\n",
"tenure 0\n",
"PhoneService 0\n",
"MultipleLines 0\n",
"InternetService 0\n",
"OnlineSecurity 0\n",
"OnlineBackup 0\n",
"DeviceProtection 0\n",
"TechSupport 0\n",
"StreamingTV 0\n",
"StreamingMovies 0\n",
"Contract 0\n",
"PaperlessBilling 0\n",
"PaymentMethod 0\n",
"MonthlyCharges 0\n",
"TotalCharges 0\n",
"Churn 0\n",
"dtype: int64"
]
},
"execution_count": 140,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.isna().sum()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK:Display the balance of the class labels (Churn) with a Count Plot.**"
]
},
{
"cell_type": "code",
"execution_count": 141,
"metadata": {},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 142,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:xlabel='Churn', ylabel='count'>"
]
},
"execution_count": 142,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEGCAYAAACUzrmNAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMA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Xt3mAk4E17bUReDfcc9PCs4BnAMcAZ43f1FCSNLzBwqKqbq2qz7fpbwM3ACuB9cCmttom4JQ2vR64sEY+CxyS5AjgRGBzVe1qt0nfDJw0VN+SpPtakHMWSVYzev7F54DDq+rWtug24PA2vRK4ZWyzba02V12StEAGD4skDwc+BLyqqv53fFlVFVDz9Dkbk8wkmdm5c+d87FKS1AwaFkkezCgo3ldVH27lb7TDS7T3Ha2+HThybPNVrTZX/V6q6ryqWldV61asWDG/P4gkLXFDXg0V4Hzghqp629iiS4HZK5o2AJeM1V/Wroo6FrizHa66DDghyfJ2YvuEVpMkLZAhH436TOClwJeSXN1qfwa8Gbg4yRnA14BT27JPAM8GtgLfBU6H0fO+k7wRuKqtd3Z7BrgkaYEMFhZV9Rkgcyw+fi/rF3DmHPu6ALhg/rqTJN0fQ44sJA3g62f/wrRb0CJ01Ou/NOj+vd2HJKnLsJAkdRkWkqQuw0KS1GVYSJK6DAtJUpdhIUnqMiwkSV2GhSSpy7CQJHUZFpKkLsNCktRlWEiSugwLSVKXYSFJ6jIsJEldhoUkqcuwkCR1GRaSpC7DQpLUZVhIkroMC0lSl2EhSeoyLCRJXYaFJKnLsJAkdRkWkqQuw0KS1GVYSJK6DAtJUpdhIUnqGiwsklyQZEeSa8dqhybZnOSm9r681ZPknUm2JrkmydP
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"sns.countplot(data=df,x='Churn')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src='fig1.png' >"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Explore the distrbution of TotalCharges between Churn categories with a Box Plot or Violin Plot.**"
]
},
{
"cell_type": "code",
"execution_count": 143,
"metadata": {},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 144,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:xlabel='Churn', ylabel='TotalCharges'>"
]
},
"execution_count": 144,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZEAAAEKCAYAAADTgGjXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAA9BElEQVR4nO3dd3hc9Zn3//c9M+rdttxtbFwgNhgMxrQQWigGEiAQlv0lG8Jm4XnSnt1nk2eB0AIBkhBIgGw2CSRsKCGBDd2AjYMNwRBj3HA3Nm6SLdmyujTS1Pv3x5yRZSzJKnPmqNyv69LF6MyZObcvJH3mW873K6qKMcYY0xs+rwswxhgzcFmIGGOM6TULEWOMMb1mIWKMMabXLESMMcb0moWIMcaYXnMtRETkcRHZLyLr2x0bJiKLRGSr898S57iIyCMisk1E1orISe1ec51z/lYRua7d8ZNFZJ3zmkdERNz6txhjjOmYmy2RPwAXf+rYzcBbqjoNeMv5HmAeMM35uhH4NSRCB7gTOBWYC9yZDB7nnBvave7T1zLGGOMy10JEVf8G1Hzq8OXAE87jJ4Ar2h1/UhOWAcUiMga4CFikqjWqWgssAi52nitU1WWauFvyyXbvZYwxJk0Cab7eKFWtcB5XAqOcx+OAsnbnlTvHujpe3sHxIxoxYoROmjSpx4UbY8xQtXLlygOqWtrRc+kOkTaqqiKSljVXRORGEt1kTJw4kRUrVqTjssYYMyiIyK7Onkv37Kx9TlcUzn/3O8f3ABPanTfeOdbV8fEdHO+Qqj6qqnNUdU5paYdhaowxphfSHSKvAMkZVtcBL7c7/jVnltZpQL3T7bUQuFBESpwB9QuBhc5zDSJymjMr62vt3ssYY0yauNadJSJ/As4BRohIOYlZVj8BnhORbwC7gGuc018HLgG2AUHgegBVrRGRHwEfOufdrarJwfpvkZgBlgO84XwZY4xJIxlqS8HPmTNHbUzEGGO6T0RWquqcjp6zO9aNMcb0moWIMcaYXrMQMc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g4gWIrVbjHQsR0qbKykng83tbCOCIR4lmFlJeXu1uYMZ9y4MABAErahUjysXVnucdCxHQp2aLQbrZEAKKZ+ZRZiJg06yhEMv2Qnym2r4iLLERMl5Itinh298ZEADS7kIqKCpvma9IqudBicdahP3fFmfG2gDGpZyFiulReXo74M7o1vTcpnlVINBKxfmiTVsnWRnHmoSFSmBGh1loirrEQMV3as2dPYjykG9N7k5LTfJM3KRqTDrW1tfgE8jIO3YqgKFOprraWiFssREyXdu3eTbQH4yFg03yNN+rq6ijMkrYbDZMKM+PU19d7U9QQYCFiOhUOh9m/b19by6K7ktN8rSVi0qmuro78wOELeRdkKC2tIUKhkAdVDX4WIqZTFRUVqGqPQwQR4tlFFiImrRrq6ynoIETyMxJjJA0NDekuaUiwEDGdalt4sYfdWQDRzEJ27tqd6pKM6VRdXW1bYLSX74yRWIi4w0LEdKotRHraEiExLlK1fx+RSOTIJxuTAo2NDYcNqoO1RNxmIWI6VVZWhmTmQiCzx6+NZxcRj8fZa3s5mDRQVZqamskLdBAiAWuJuMlCxHRq166ez8xKsmm+Jp1aW1uJRGPkddCdleu0ThobG9Nd1pBgIWI6tWv37sQS8L1gIWLSKRkQHbVE8gKJYGlqakprTUOFhYjpUENDA02NDb0aDwEgkIlk5lqImLRIBkRHYyLZfvCJtUTcYiFiOnRwzaxehggQzSpg926boWXclwyI3A5aIiKQlykWIi6xEDEdSkWIxLKK2G0tEZMGyUHzjqb4QqKby0LEHRYipkO7d+8GETQrv9fvEc8uoqG+3n55jevaurM6aIkkjkft59AlFiKmQ+Xl5ZBdCD5/r99DbQ0tkyZtA+s
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"sns.violinplot(data=df,x='Churn',y='TotalCharges')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src='fig2.png' >"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Create a boxplot showing the distribution of TotalCharges per Contract type, also add in a hue coloring based on the Churn class.**"
]
},
{
"cell_type": "code",
"execution_count": 145,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 146,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x2d1eb25c100>"
]
},
"execution_count": 146,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAB+MAAALaCAYAAADqX/GDAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAB7CAAAewgFu0HU+AACimElEQVR4nOz9e5zdVX0v/r/WJNlkyOQqJIAiKhdF8NdajLZWUKzfqtXWmIDagkIr9YZy7PF2rOKprdZTtRdBbLV4oSYKSmJQ0WpbraBVjFRboYCAWKJIEm5JBgZ2JrN+f8xOGcZJJjPZs2cm83w+HvuxP5f1Xvs9xBHNa6/1KbXWAAAAAAAAAADt0zXZDQAAAAAAAADA/kYYDwAAAAAAAABtJowHAAAAAAAAgDYTxgMAAAAAAABAmwnjAQAAAAAAAKDNhPEAAAAAAAAA0GbCeAAAAAAAAABoM2E8AAAAAAAAALSZMB4AAAAAAAAA2kwYDwAAAAAAAABtJowHAAAAAAAAgDYTxgMAAAAAAABAmwnjAQAAAAAAAKDNhPEAAAAAAAAA0GbCeAAAAAAAAABoM2E8AAAAAAAAALTZ7MlugP1HKeWAJE9onW5JsnMS2wEAAAAAACbXrCQHt45/WGt9YDKbAeg0YTzt9IQkGya7CQAAAAAAYMpZnuR7k90EQCfZph4AAAAAAAAA2szKeNppy66D7373uzn00EMnsxcAAAAAAGAS/fznP8+Tn/zkXadb9jQWYH8kjKed/ucZ8Yceemge8YhHTGYvAAAAAADA1LFz9CEA+xfb1AMAAAAAAABAmwnjAQAAAAAAAKDNhPEAAAAAAAAA0GbCeAAAAAA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"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,4),dpi=200)\n",
"sns.boxplot(data=df,y='TotalCharges',x='Contract',hue='Churn')\n",
"plt.legend(loc=(1.1,0.5))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src='fig3.png' >"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Create a bar plot showing the correlation of the following features to the class label. Keep in mind, for the categorical features, you will need to convert them into dummy variables first, as you can only calculate correlation for numeric features.**\n",
"\n",
" ['gender', 'SeniorCitizen', 'Partner', 'Dependents','PhoneService', 'MultipleLines', \n",
" 'OnlineSecurity', 'OnlineBackup', 'DeviceProtection', 'TechSupport', 'InternetService',\n",
" 'StreamingTV', 'StreamingMovies', 'Contract', 'PaperlessBilling', 'PaymentMethod']\n",
"\n",
"***Note, we specifically listed only the features above, you should not check the correlation for every feature, as some features have too many unique instances for such an analysis, such as customerID***"
]
},
{
"cell_type": "code",
"execution_count": 147,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 148,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['customerID', 'gender', 'SeniorCitizen', 'Partner', 'Dependents',\n",
" 'tenure', 'PhoneService', 'MultipleLines', 'InternetService',\n",
" 'OnlineSecurity', 'OnlineBackup', 'DeviceProtection', 'TechSupport',\n",
" 'StreamingTV', 'StreamingMovies', 'Contract', 'PaperlessBilling',\n",
" 'PaymentMethod', 'MonthlyCharges', 'TotalCharges', 'Churn'],\n",
" dtype='object')"
]
},
"execution_count": 148,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "code",
"execution_count": 149,
"metadata": {},
"outputs": [],
"source": [
"corr_df = pd.get_dummies(df[['gender', 'SeniorCitizen', 'Partner', 'Dependents','PhoneService', 'MultipleLines', 'InternetService',\n",
" 'OnlineSecurity', 'OnlineBackup', 'DeviceProtection', 'TechSupport','StreamingTV', 'StreamingMovies', 'Contract', 'PaperlessBilling',\n",
" 'PaymentMethod','Churn']]).corr()"
]
},
{
"cell_type": "code",
"execution_count": 150,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Contract_Two year -0.301552\n",
"StreamingMovies_No internet service -0.227578\n",
"StreamingTV_No internet service -0.227578\n",
"TechSupport_No internet service -0.227578\n",
"DeviceProtection_No internet service -0.227578\n",
"OnlineBackup_No internet service -0.227578\n",
"OnlineSecurity_No internet service -0.227578\n",
"InternetService_No -0.227578\n",
"PaperlessBilling_No -0.191454\n",
"Contract_One year -0.178225\n",
"OnlineSecurity_Yes -0.171270\n",
"TechSupport_Yes -0.164716\n",
"Dependents_Yes -0.163128\n",
"Partner_Yes -0.149982\n",
"PaymentMethod_Credit card (automatic) -0.134687\n",
"InternetService_DSL -0.124141\n",
"PaymentMethod_Bank transfer (automatic) -0.118136\n",
"PaymentMethod_Mailed check -0.090773\n",
"OnlineBackup_Yes -0.082307\n",
"DeviceProtection_Yes -0.066193\n",
"MultipleLines_No -0.032654\n",
"MultipleLines_No phone service -0.011691\n",
"PhoneService_No -0.011691\n",
"gender_Male -0.008545\n",
"gender_Female 0.008545\n",
"PhoneService_Yes 0.011691\n",
"MultipleLines_Yes 0.040033\n",
"StreamingMovies_Yes 0.060860\n",
"StreamingTV_Yes 0.063254\n",
"StreamingTV_No 0.128435\n",
"StreamingMovies_No 0.130920\n",
"Partner_No 0.149982\n",
"SeniorCitizen 0.150541\n",
"Dependents_No 0.163128\n",
"PaperlessBilling_Yes 0.191454\n",
"DeviceProtection_No 0.252056\n",
"OnlineBackup_No 0.267595\n",
"PaymentMethod_Electronic check 0.301455\n",
"InternetService_Fiber optic 0.307463\n",
"TechSupport_No 0.336877\n",
"OnlineSecurity_No 0.342235\n",
"Contract_Month-to-month 0.404565\n",
"Name: Churn_Yes, dtype: float64"
]
},
"execution_count": 150,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"corr_df['Churn_Yes'].sort_values().iloc[1:-1]"
]
},
{
"cell_type": "code",
"execution_count": 151,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABo0AAAUYCAYAAAB9eJuxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdebgsVXk37N8Dh1kQIygqBI2KYpSI4jxhMBpFI0aNGvMpCGKMRozzkLwxiZJEX17FOCSOYIxTNEoEHOIAzgJO0QgiKgQcEQXhyMz6/qjanmK7h95D7959uO/rqqtXda2u9ezu3n32qV+vqmqtBQAAAAAAgOu2LSZdAAAAAAAAAJMnNAIAAAAAAEBoBAAAAAAAgNAIAAAAAACACI0AAAAAAACI0AgAAAAAAIAIjQAAAAAAAIjQCAAAAAAAgAiNAAAAAAAAiNAIAAAAAACACI0AAAAAAACI0AgAAAAAAIAIjQAAAAAAAIjQCAAAAAAAgAiNAAAAAAAAiNAIAAAAAACACI0AAAAAAACI0AgAAAAAAIAIjQAAAAAAAIjQCAAA4NdUVZtZJl3LQqrq4EGtx0y6HlhrVbX/4HfgpEnXAwAw7YRGAADrSFWdNDxYvYRl/0nXzuRU1Z2q6kVV9bGq+nZV/byqrqiq86vq61V1bFU9uapuMOla4bqiqt41+Iw+s6q2W+LjDx08/oqqusO4ap0Un10AAOuP0AgAgDVXVccMDoYePOl6plVV3a2qPpbkS0leluSAJLdKsnOSrZLskuT2SZ6Q5A1JflhVb6mq3SdTMQsxa2h0VXX24Lm6+aTrmcefJ/lp3751kr8Z9YFVdZMk/3dw18taa19fxdomymcXAMD6tWHSBQAAMK9Tk5wyYt/vj7MQ1p+qelaSV+TaXwS7It175vtJLkp34HWPJHdKsmWSbZIckuSxSbZfy3rhuqa1dn5V/XmSd/Z3Pauq3tNaO22Eh782XYCSJP+d5MgxlDgRPrsAANY3oREAwPp1YmvtJZMug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bj5C/0XHmNXnyv72NUmuN6vfVkm2GNfzO+LP/yeDfbV0F5Bfzffe1tkUILT+Z3zAHP0emC4Ymen3pSRbjfB+vjLdQdy/nN0/yTbr7TUZPtcLPGdPSvL0JDdboM8+6cKrmf395QJ9Dx70O2bE123Rx6zBa3tZukD5WUk2zOq3R7pwaqbvJ1bp/Xr2YJ+Lfh70j3nd4DFXpQtgtpjV59ZJThv0u2jU/S+h9o8N9v+pdIHq1f36NUnuO897bVjTYXO9NulmBp036Pu8Ofo8fLD9B0nutkCtv53kH5LcdQU/77g/u/af9V5s6QKY287qV/1rPqzl157rOfZ50oh1jPKZMRz7ynQh3UFz9Bt+Jg7f65elCzj/JEnN8VoNX/u3rObzbLFYLBaL5bqzuKYRAMD69ZD+mhuLLbNPB/WydLM3kuTVrbUnttZ+OHvnrbUfpwuCPtHfdYckj5qrkNbaC1tr/95a+8U821tr7YPpgqMZf76En3U92JDkTa21p7dZF2dv3UXYZ76tv+rP74huPmhfk7lnZ63E49PNLEi6g5m/31r7tdNRte6aIg9Jd9A96b6x/7gR9r8hyV+11l7aWrvWt+jbHNdtGTxm3b4mrbW3tNZe01r7/gJ9/jvd7IAf9Xf9Wc26ls0aGPdru02SP2ut/b/W2lXDDa21c/t9tP6u/atqxbNXlqqqbpnuujozjmitHd1mzcJprX073anYzu7v2inJ/1nlcg5LsrFv3yfJh7PpesOva619ati5qnZMclS/ekWSB7bW3jT79yhJWmufTFf/Zf1dz+tnWA3dZ9D+P621L85XaGvtf1prL2itrWTm580H7XF8dg1tk2423u+21q4
"text/plain": [
"<Figure size 2000x800 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,4),dpi=200)\n",
"sns.barplot(x=corr_df['Churn_Yes'].sort_values().iloc[1:-1].index,y=corr_df['Churn_Yes'].sort_values().iloc[1:-1].values)\n",
"plt.title(\"Feature Correlation to Yes Churn\")\n",
"plt.xticks(rotation=90);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src='figbar.png'>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"---\n",
"\n",
"# Part 3: Churn Analysis\n",
"\n",
"**This section focuses on segementing customers based on their tenure, creating \"cohorts\", allowing us to examine differences between customer cohort segments.**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: What are the 3 contract types available?**"
]
},
{
"cell_type": "code",
"execution_count": 152,
"metadata": {},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 153,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['Month-to-month', 'One year', 'Two year'], dtype=object)"
]
},
"execution_count": 153,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Contract'].unique()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Create a histogram displaying the distribution of 'tenure' column, which is the amount of months a customer was or has been on a customer.**"
]
},
{
"cell_type": "code",
"execution_count": 154,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 155,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:xlabel='tenure', ylabel='Count'>"
]
},
"execution_count": 155,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABqUAAALaCAYAAAC4dVmkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAB7CAAAewgFu0HU+AABmvUlEQVR4nOz9e5hlVX0n/r8/gNCIEC8oRBAv2AyYNAlfgShe0OiYMcYRI9FoEiVixEQwOtGoQRNNwjheMqMy0S+KRp18o2NUxDHwi5dEVNCIjpEkCN3gDS8geAsCDTas3x9nF705VNWp6q5dt/N6Pc95ztpnr/3Z6zS9qerzPmvtaq0FAAAAAAAAhrTLSg8A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AAAGJxQCgAAAAAAgMEJpQAAAAAAABicUAoAAAAAAIDBCaUAAAAAAAAYnFAKAAAAAACAwQmlAAAAAAAAGJxQCgAAAAAAgMEJpQAAAAAAABicUAoAAAAAAIDBCaUAAAAAAAAYnFAKAAAAAACAwQmlAAAAAAAAGJxQCgAAAAAAgMEJpQAAAAAAABicUAoAAAAAAIDBCaUAAAAAAAAYnFAKAAAAAACAwQmlAAAAAAAAGJxQCgAAAAAAgMEJpQAAAAAAABicUAoAAAAAAIDBCaUAAAAAAAAYnFAKAAAAAACAwQmlAAAAAAAAGJxQCgAAAAAAgMEJpQAAAAAAABicUAoAAAAAAIDBCaUAAAAAAAAYnFAKAAAAAACAwQmlAAAAAAAAGJxQCgAAAAAAgMEJpQAAAAAAABicUAoAAAAAAIDBCaUAAAAAAAAYnFAKAAAAAACAwQm
"text/plain": [
"<Figure size 2000x800 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,4),dpi=200)\n",
"sns.histplot(data=df,x='tenure',bins=60)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"fig5.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Now use the seaborn documentation as a guide to create histograms separated by two additional features, Churn and Contract.**"
]
},
{
"cell_type": "code",
"execution_count": 156,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 157,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Figure size 2000x600 with 0 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABDAAAALICAYAAACJhQBYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAABUn0lEQVR4nO3debhsZ10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eimf+5vSPKHST7ZWvty1/aBJD9V9cD8KU8eev43d0H1j2Ywao51JMBYQN231j+Q5LtqcOqonRkMm/rShLv+RpI/qKpLMkhZN0Rr7e4MOol/2V2/OcnLk1yU5NNJLm2tTZ0gt9ZuSfLiJL9bg1NHXZXk32XQYb4yyVOr6vIMJiVa8U1ca+2OJH9bgwmUfmfMKucl2bd7jFdl0FmnG/J3epL3VNWnMxglkQxGLvxAzXDiotba11prr+7247A/TvKw7vCMd2RwjOQ3HrqFXZyV5PJ6cBLPaR5/dB+9N8nlGbx2Fyb5pdbapN/F5bZ9VwZDo9/VPY/7Mxj1sZKZ72PYXfrph2xvb+mnT0vyzd1r/g8ZDC0+bcLzuTuDb5Jf3dW1I8vP2P/WDOa2eNtQ248kOa27784MvkVMBvv1XVV1aZLb1/RsoKf0sQ/Z3t7Sx47W+o0MDon+eNf0kQzCkiu666/MFM+9tXZpkq+mC4c7v5nBnCCXd79fSxM0/3EGYdGnM5hzzqiLdbY0uRP0Xjdk69rW2ps3uBQAxtBPz1cNzqp0cmvtRze6FmD96WPno6oOT/LBJE9YOgSQ/jIHBgBAz1X
"text/plain": [
"<Figure size 1080x720 with 6 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,3),dpi=200)\n",
"sns.displot(data=df,x='tenure',bins=70,col='Contract',row='Churn');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"fig6.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Display a scatter plot of Total Charges versus Monthly Charges, and color hue by Churn.**"
]
},
{
"cell_type": "code",
"execution_count": 158,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 159,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['customerID', 'gender', 'SeniorCitizen', 'Partner', 'Dependents',\n",
" 'tenure', 'PhoneService', 'MultipleLines', 'InternetService',\n",
" 'OnlineSecurity', 'OnlineBackup', 'DeviceProtection', 'TechSupport',\n",
" 'StreamingTV', 'StreamingMovies', 'Contract', 'PaperlessBilling',\n",
" 'PaymentMethod', 'MonthlyCharges', 'TotalCharges', 'Churn'],\n",
" dtype='object')"
]
},
"execution_count": 159,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "code",
"execution_count": 160,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:xlabel='MonthlyCharges', ylabel='TotalCharges'>"
]
},
"execution_count": 160,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABrcAAALaCAYAAACbLghxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOz9d5Rl113nf7/3CTfHqlu5qnNUqyW1smzJwgHbOGDAmJmfMeCBMTwebH5ODMMw2PMMDwsGMAM/DwwOP7AJA5ixDbbliKOiFVqh1TlWDvfWzeHck/bzxy2Vq1udJLfckvr7WquWz73nnH32OXVVXut++vvdSmuNEEIIIYQQQgghhBBCCCGEEC8ExuWegBBCCCGEEEIIIYQQQgghhBAXS8ItIYQQQgghhBBCCCGEEEII8YIh4ZYQQgghhBBCCCGEEEIIIYR4wZBwSwghhBBCCCGEEEIIIYQQQrxgSLglhBBCCCGEEEIIIYQQQgghXjAk3BJCCCGEEEIIIYQQQgghhBAvGBJuCSGEEEIIIYQQQgghhBBCiBcMCbeEEEIIIYQQQgghhBBCCCHEC4aEW0IIIYQQQgghhBBCCCGEEOIFQ8ItIYQQQgghhBBCCCGEEEII8YIh4ZYQQgghhBBCCCGEEEIIIYR4wZBwSwghhBBCCCGEEEIIIYQQQrxgSLglhBBCCCGEEEIIIYQQQgghXjAk3BJCCCGEEEIIIYQQQgghhBAvGBJ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czMzJzznLe//e0opdiwYcN5x/7kJz+JUgql1FnXCNuwYQNKKd7+9rcD8Mgjj/D
"text/plain": [
"<Figure size 2000x800 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,4),dpi=200)\n",
"sns.scatterplot(data=df,x='MonthlyCharges',y='TotalCharges',hue='Churn', linewidth=0.5,alpha=0.5,palette='Dark2')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src='fig7.png'>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Creating Cohorts based on Tenure\n",
"\n",
"**Let's begin by treating each unique tenure length, 1 month, 2 month, 3 month...N months as its own cohort.**\n",
"\n",
"**TASK: Treating each unique tenure group as a cohort, calculate the Churn rate (percentage that had Yes Churn) per cohort. For example, the cohort that has had a tenure of 1 month should have a Churn rate of 61.99%. You should have cohorts 1-72 months with a general trend of the longer the tenure of the cohort, the less of a churn rate. This makes sense as you are less likely to stop service the longer you've had it.**"
]
},
{
"cell_type": "code",
"execution_count": 161,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 162,
"metadata": {},
"outputs": [],
"source": [
"no_churn = df.groupby(['Churn','tenure']).count().transpose()['No']\n",
"yes_churn = df.groupby(['Churn','tenure']).count().transpose()['Yes']"
]
},
{
"cell_type": "code",
"execution_count": 163,
"metadata": {},
"outputs": [],
"source": [
"churn_rate = 100 * yes_churn / (no_churn+yes_churn)"
]
},
{
"cell_type": "code",
"execution_count": 164,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tenure\n",
"1 61.990212\n",
"2 51.680672\n",
"3 47.000000\n",
"4 47.159091\n",
"5 48.120301\n",
" ... \n",
"68 9.000000\n",
"69 8.421053\n",
"70 9.243697\n",
"71 3.529412\n",
"72 1.657459\n",
"Name: customerID, Length: 72, dtype: float64"
]
},
"execution_count": 164,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"churn_rate.transpose()['customerID']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Now that you have Churn Rate per tenure group 1-72 months, create a plot showing churn rate per months of tenure.**"
]
},
{
"cell_type": "code",
"execution_count": 165,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 166,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABpQAAALaCAYAAAA/RLCiAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdd3hcxdn+8XvUre5uyZIsF1wx7gabYkwgQOgESIBQQgmkkF8KKaT3kPCGlzcJodcQegkJNRBcwAX33i3LlmzZlmyr9935/aG1vGfVpd2zKt/Pde21O8/OOeexY0zw7Zkx1loBAAAAAAAAAAAALYkIdwMAAAAAAAAAAADo3giUAAAAAAAAAAAA0CoCJQAAAAAAAAAAALSKQAkAAAAAAAAAAACtIlACAAAAAAAAAABAqwiUAAAAAAAAAAAA0CoCJQAAAAAAAAAAALSKQAkAAAAAAAAAAACtIlACAAAAAAAAAABAqwiUAAAAAAAAAAAA0CoCJQAAAAAAAAAAALSKQAkAAAAAAAAAAACtIlACAAAAAAAAAABAqwiUAAAAAAAAAAAA0CoCJQAAAAAAAAAAALSKQAkAAAAAAAAAAACtigp3A+gaY0yspMm+YaEkTxjbAQAAAAAAAAAA4RUpabDv80ZrbU0wbkqg1PNNlrQy3E0AAAAAAAAAAIBuZ5akVcG4EVveAQAAAAAAAAAAoFWsUOr5Co9/WLFihdLS0sLZCwAAAAAAAAAACKOCggLNnj37+LCwtbkdQaDU8zWemZSWlqaMjIxw9gIAAAAAAAAAALoPT9tT2oct7wAAAAAAAAAAANAqAiUAAAAAAAAAAAC0ikAJAAAAAAAAAAAArSJQAgAAAAA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AAAAAA
"text/plain": [
"<Figure size 2000x800 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,4),dpi=200)\n",
"churn_rate.iloc[0].plot()\n",
"plt.ylabel('Churn Percentage');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src='fig9.png'>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Broader Cohort Groups\n",
"**TASK: Based on the tenure column values, create a new column called Tenure Cohort that creates 4 separate categories:**\n",
" * '0-12 Months'\n",
" * '24-48 Months'\n",
" * '12-24 Months'\n",
" * 'Over 48 Months' "
]
},
{
"cell_type": "code",
"execution_count": 167,
"metadata": {},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 168,
"metadata": {},
"outputs": [],
"source": [
"def cohort(tenure):\n",
" if tenure < 12:\n",
" return '0-12 Months'\n",
" elif tenure < 24:\n",
" return '12-24 Months'\n",
" elif tenure < 48:\n",
" return '24-48 Months'\n",
" else:\n",
" return \"Over 48 Months\""
]
},
{
"cell_type": "code",
"execution_count": 169,
"metadata": {},
"outputs": [],
"source": [
"df['Tenure Cohort'] = df['tenure'].apply(cohort)"
]
},
{
"cell_type": "code",
"execution_count": 170,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>tenure</th>\n",
" <th>Tenure Cohort</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>0-12 Months</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>34</td>\n",
" <td>24-48 Months</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2</td>\n",
" <td>0-12 Months</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>45</td>\n",
" <td>24-48 Months</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2</td>\n",
" <td>0-12 Months</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>8</td>\n",
" <td>0-12 Months</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>22</td>\n",
" <td>12-24 Months</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>10</td>\n",
" <td>0-12 Months</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>28</td>\n",
" <td>24-48 Months</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>62</td>\n",
" <td>Over 48 Months</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" tenure Tenure Cohort\n",
"0 1 0-12 Months\n",
"1 34 24-48 Months\n",
"2 2 0-12 Months\n",
"3 45 24-48 Months\n",
"4 2 0-12 Months\n",
"5 8 0-12 Months\n",
"6 22 12-24 Months\n",
"7 10 0-12 Months\n",
"8 28 24-48 Months\n",
"9 62 Over 48 Months"
]
},
"execution_count": 170,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head(10)[['tenure','Tenure Cohort']]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Create a scatterplot of Total Charges versus Monthly Charts,colored by Tenure Cohort defined in the previous task.**"
]
},
{
"cell_type": "code",
"execution_count": 171,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 172,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:xlabel='MonthlyCharges', ylabel='TotalCharges'>"
]
},
"execution_count": 172,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABrcAAALaCAYAAACbLghxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdd5ydZZ3//9d1l1On90nvBZIABqRJUWygKCq2lW5l1VVXVxd1Rdf1u/4W17WwugorKLqurmJFBKS3GDoJ6ZlJMr3PmdPvcl2/P+7JZJJMCiQYYj7Px2PMmbnv+zrXKQk+zns+n48yxiCEEEIIIYQQQgghhBBCCCHE0cA60hsQQgghhBBCCCGEEEIIIYQQ4mBJuCWEEEIIIYQQQgghhBBCCCGOGhJuCSGEEEIIIYQQQgghhBBCiKOGhFtCCCGEEEIIIYQQQgghhBDiqCHhlhBCCCGEEEIIIYQQQgghhDhqSLglhBBCCCGEEEIIIYQQQgghjhoSbgkhhBBCCCGEEEIIIYQQQoijhoRbQgghhBBCCCGEEEIIIYQQ4qgh4ZYQQgghhBBCCCGEEEIIIYQ4aki4JYQQQgghhBBCCCGEEEIIIY4aEm4JIYQQQgghhBBCCCGEEEKIo4aEW0IIIYQQQgghhBBCCCGEEOKoIeGWEEIIIYQQQgghhBBCCCGEOGpIuCWEEEIIIYQQQgghhBBCCCGOGhJuCSGEEEIIIYQQQgghhBBCiKOGhFtCCCGEEEIIIYQQQgghhBDiqOEc6Q2Ivx5KqTiwfPzbASA8gtsRQgghhBBCCCGEEEIIIcSRZQON47fXGGPKh2NRCbfE4bQceOxIb0IIIYQQQgghhBBCCCGEEC85pwCPH46FpC2hEEIIIYQQQgghhBBCCCGEOGpI5ZY4nAZ23li9ejWtra1Hci9CCCGEEEIIIYQQQgghhDiCenp6ePnLX77z24H9nft8SLglDqeJGVutra3MmDHjSO5FCCGEEEIIIYQQQgghhBAvHeGBTzk40pZQCC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eTybB161b+8Ic/cNttt9Hd3c3HP/5xCbeEEEIIIYQQQgghhDhEJgjxNwzgPdUFgDOjGuNrwo5Rgm3DGD/EqowTDuZxZtTgLmrEbqki7B4DY8CKKr4Ix9sCagCD7sliJV1URRwzXJi4P5V0UVVxTDkg7M0S9uXwN/bj/XkHKEX8FXNxFjXitFRimisItg7BgYIrS0Vf4pBJuCXES4TruixbtuyA56XT6YM6Txxed999N+973/vQWpNOp7n55pu5+OKL9zrvla98Je973/vYtm0b//iP/8gf//jHI7BbIYQQQgghhBBCCCH+ehhtCDYP4j3WgUo42C2V+JsG8Nf0YsaiqilVmyQcLRJsGSR4tofy6h3Ez5iNu7wVU/BRlkJnS1AOwRhUKgYGTNknHMjhzGvA2BaEGpWKwi7dlyPszaLidnRuKQDLQtkKPZSn9MchrJok8TPn4CxqJNg0sN+Ay0q50VrikEm4JYQQB1AoFLjkkkvQWmNZFrfddhvnnHPOfq+ZM2cO//u//8uPfvSjv9AuhRBCCCGEEEIIIYR4adNegBktQTDe/s+1saqTqNj+Ax89UsB7rg9shd1ahfd0N/5TnVHLQYhmbrk2Yc/YxM/McIHy/W2YsTLO8hZU0sWZURMFUIDxQ0g4mFyZsDeH3VyFSroYL0BVxAn7sujuMQCcRS2gQPfnUAkHqzIe3YkXovtzlP60mcRrFuHMrSPYMjT1g3AsnHn1WAn3UJ5CMe75TTsTQrykPfnkk3zoQx9i8eLFVFRUkE6nWbx4MVdffTWbNm3a53U333wzSimUUmzbtg2tNd///vc544wzqK2tJZ1Os2LFCr7yla9QKBT2uc6cOXNQSh2wDd8VV1yBUoo5c+bsdWzbtm0Te7n
"text/plain": [
"<Figure size 2000x800 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,4),dpi=200)\n",
"sns.scatterplot(data=df,x='MonthlyCharges',y='TotalCharges',hue='Tenure Cohort', linewidth=0.5,alpha=0.5,palette='Dark2')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src='fig10.png'>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Create a count plot showing the churn count per cohort.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 295,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABrcAAALaCAYAAACbLghxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAB7CAAAewgFu0HU+AACL9klEQVR4nOzdedReVXk34N8dQgIEkFmQoKiIjG2RwVpUsFqHihOlDnUAZbDWWaQWx4q1rVCt1mpBQIFqnUUF8XNElMGCKBZBQFQUUGRSZohJ9vfHexIeXt8pyTud5LrWOuvZ5zn73Od+QlxZq7/ufaq1FgAAAAAAAOiDOTPdAAAAAAAAAEyUcAsAAAAAAIDeEG4BAAAAAADQG8ItAAAAAAAAekO4BQAAAAAAQG8ItwAAAAAAAOgN4RYAAAAAAAC9IdwCAAAAAACgN4RbAAAAAAAA9IZwCwAAAAAAgN4QbgEAAAAAANAbwi0AAAAAAAB6Q7gFAAAAAABAbwi3AAAAAAAA6A3hFgAAAAAAAL0h3AIAAAAAAKA35s50A6w+qmp+kl270xuSLJnBdgAAAAAAgJm1VpLNu/HFrbV7JqOocIvJtGuSC2a6CQAAAAAAYNbZM8n3JqOQbQkBAAAAAADoDSu3mEw3LBucf/752WqrrWayFwAAAAAAYAb9+te/zl577bXs9Iax5q4I4RaTafk7trbaaqssXLhwJnsBAAAAAABmjyXjT5kY2xICAAAAAADQG8ItAAAAAAAAekO4BQAAAAAAQG8ItwAAAAAAAOgN4RYAAAAAAAC9IdwCAAAAAACgN4RbAAAAAAAA9IZwCwAAAAAAgN4QbgEAAAAAANAbwi0AAAAAAAB6Y+5MNwAAAAAAAEyvu+++O7/73e9y5513ZsmSJTPdDrPUWmutlXnz5mXDDTfM+uuvnzlzZseaKeEWAAAAAACsIVpr+fWvf51bbrllpluhBxYvXpx77rknt912W6oqW2+9dTbYYIOZbku4BQAAAAAAa4qbbrrpD4KtuXNFBYxsyZIlaa0lGQpGr7322lkRcPkbCwAAAAAAa4BFixblhhtuWH6+xRZbZKONNspaa601g10xm7XWcuedd+bmm2/O7bffvjzg2n777Wd0i8LZsTkiAAAAAAAwpW6//fbl40033TSbbrqpYIsxVVUWLFiQhQsXZv31108yFHgN/l2aCcItAAAAAABYA9xxxx3LxxtuuOEMdkLfVFU22WST5ee33nrrDHYj3AIAAAAAgDXCokWLkgwFFfPnz5/hbuib9dZbL1WV5N6/SzNFuAUAAAAAAGuApUuXJknWWmut5SEFTFRVLd/GcsmSJTPai3ALAAAAAACA3hBuAQAAAAAA0BvCLQAAAAAAAHpDuAUAAAAAAEBvCLcAAAAAAADoDeEWAAAAAADQO1dddVWqKlWVk046aabbYRoJtwAAAAAAgBmzaNGifPzjH8+LXvSi7LDDDtl0002z9tprZ7PNNsvuu++el73sZfn617+epUuXznSrzBJzZ7oBAAAAAABgzfS5z30uhx9+eK666qo/uHbTTTflpptuyve///0ce+yx2X777fOe97wnT33qU6e/UWYV4RYAAAAAsEba/YhTZroF1hAXHvOimW5hVnrHO96Rt771rcvP/+Iv/iJPf/rTs9NOO2WjjTbKzTffnMsvvzynnXZavva1r+WKK67Im970JuEWwi0AAAAAAGB6feQjH1kebG2xxRb51Kc+lX322ecP5j3hCU/Iy1/+8vzoRz/Ka1/72txwww3T3SqzkHALAAAAAACYNtdee21e8YpXJEkWLFiQs846KzvssMOY9+yyyy75yle+kv/5n/+ZjhaZ5ebMdAMAAAAAAMCa49///d9z5513JkmOOuqocYOtZebMmZMXvOAFY8752te+lqc97WnZcsstM3/+/Dz4wQ/Oy172slxzzTWj3nPQQQelqrLtttuOWfukk05KVaWqRnxH2LbbbpuqykEHHZQkufDCC3PQQQflwQ9+cObPn5+qGnXu5ZdfnkMPPTTbbrtt5s+fn/vf//551rOele9+97tj9rSmsnILAAAAAACYFq21nHzyyUmGVm0deuihk1b7yCOPzL/+67/e57urrroqxx57bD772c/mrLPOyo477jhpzxvLsccem1e+8pVZvHjxuHNPPfXUvOAFL1ge+CXJ9ddfn89//vM57bTT8rGPfSzPec5zprLd3hFuAQAAAAAA0+KSSy7JjTfemCR5zGMekw022GBS6h5//PE599xzs88+++SlL31ptt9++/zud7/LKaecklNOOSU33HBDXvKSl+S8886blOeN5YILLshHP/rRbLPNNnn961+fPfbYI4sXL853vvOdP5h78cUX55Of/GS22mqrHH744dljjz3SWstXvvKV/Ou//mvuvvvuHHbYYfnzP//zbL755lPee18ItwAAAAAAgGnxwx/+cPl49913n7S65557bg499NAcd9xx99n+7/GPf3zmzZuXE044Id/97nfzgx/8ILvtttukPXckl156aXbdddd8+9vfzkYbbbT8+7333vsP5n7/+9/P7rvvnm9+85vZcMMNl3//p3/6p9luu+3yghe8ILfeems++tGP5rWvfe2U9t0n3rkFAAAAAABMi5tuumn5eIsttpi0ultttVXe//733yfYWub1r3/98vFIq6emwgc+8IH7BFtj+fCHP3yfYGuZv/mbv8kDHvCAJNPXd18ItwAAAAAAgGlx2223LR8vWLBg0uoecMABmT9//ojXHv7wh2f99ddPkvzsZz+btGeOZptttsljHvOYCc3ddddd80d/9EcjXquq5avMpqPvPhFuAQAAAAAA02LwHVt33HHHpNXdYYcdxry+8cYbJ7lvuDZVRgurRjJe35tsskmS6em7T4RbAAAAAADAtNh0002Xj3/zm99MWt311ltvzOtz5gzFIUuWLJm0Z45mWZA2EbOp7z4RbgEAAAAAANPij//4j5ePv//9789gJ1NnrbXWmukWVnvCLQAAAAAAYFrsvPPO2WyzzZIk3/nOd3LrrbfOcEf3ro5aunTpmPMmcxtFVs0aG25V1R5V9daq+mpVXVNV91TV7VV1RVV9pKoevYL1nlJVpw7UuqY7f8oK1JhbVX9bVd+pqhuq6q6q+mlVHVdVO69Anc2q6qiq+r+qurU7/q/7btPxKwAAAAAAwOSrqhx44IFJhsKiE044YYY7uvc9YL/73e/GnHfFFVdMQzdMxBoZblXVt5NckOTtSf4iydZJ5iVZkORhSQ5K8p2qOrmq5o1Ta05VnZDkjCTPHKi1dXd+RlUdX1Vj/llX1WZJzk3yX0kenWSzJOskeUiSw5JcWFWHTOC3PTLJxUnekmTXJBt0x67ddxdX1V7j1QEAAAAAgKnw2te+dvm7pt761rfmsssum9B9S5cuzcc+9rFJ7+fBD35wkuS2227L5ZdfPuKcRYsW5bOf/eykP5uVs0aGW0ke0H3+Ksn7khyQZK8kj0ryuiTXdtdflOSkcWq9M8nB3fgHSZ7X1Xped54khyT5p9EKVNVaSU5Nsmf31eeSPCXJI5O8Ksn1SeYnOW6slWBVtU2S05JsmWRxkqOTPLY7ju6+2yrJaVW1cJzfBQAAAAAAk27rrbfOf/7nfyYZWr21zz775KyzzhrznksvvTRPfvKTc8wxx0x6P/vss8/y8bvf/e4R57zuda/LtddeO+I1pt/cmW5ghlyW5I1JPttaWzLs2ner6r+TnJNk+yTPq6pjW2vfHl6kqrZP8vru9HtJHttau6s7v6CqvpjkrCR7JDmiqj7cWrtyhH4OzNBqrST5YGvt5QPXzq+qLye5MMmGSf6jqnZsrS0eoc47k2zejf+mtfbpgWvfqaoLk3wyyRYZCtsOGqEGAAAAAABMqRe/+MW55ppr8ta3vjXXX3999t133zzxiU/MM57xjOy4447ZaKONcvPNN+eKK67Il770pfy///f/smTJkvzxH//xpPey22675VGPelTOO++8HH/88Vm0aFEOPPDA3O9+98tPfvKTfOhDH8o3v/nN/Nmf/VnOPffcSX8+K26
"text/plain": [
"<Figure size 2000x800 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,4),dpi=200)\n",
"sns.countplot(data=df,x='Tenure Cohort',hue='Churn')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src='cplot.png'>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Create a grid of Count Plots showing counts per Tenure Cohort, separated out by contract type and colored by the Churn hue.**"
]
},
{
"cell_type": "code",
"execution_count": 174,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 175,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<seaborn.axisgrid.FacetGrid at 0x2d1e3caafd0>"
]
},
"execution_count": 175,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"text/plain": [
"<Figure size 2000x800 with 0 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABHYAAAFuCAYAAADkjJ/RAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAyJElEQVR4nO3debglVXn3/e9PWkVERaWDjGmiGB9EBek4oygOaBJBRQVRBk2Iz6s4oxgTQHxMNMSoOAaVSYmAOICGgIRBMcrUCDRD0BYRISiIOKARAe/3j1oHNocz9el9zu7q8/1c1766atWqVavW2efep+9aVTtVhSRJkiRJkvrnXqPugCRJkiRJkmbHxI4kSZIkSVJPmdiRJEmSJEnqKRM7kiRJkiRJPWViR5IkSZIkqadM7EiSJEmSJPWUiR3NmSQPS3Jskh8kWZbk5CSPnGVbb0qyzpD6tSTJK4bU1pFJfpvkAQNlH0pSSdafZZt7JdloYP3qmbQ1zDFaVePHuJ3TR0fZJ0mTWyDxOkn+Lsn3k3wvyZlJHj2MtiVpJtb0WJvkY0kuSnJ5kv9tyxcl2WUY/ZQ0ORM7mhNJAnwZOKuqHl5V2wLvBDaYZZNvAib88Eqy1kq2tQQYyn8UmhXATq0v9wKeBVy3Cu3tBWw0XaUJvIlJxmgEljDcMZY0RxZQvH4d8BTgcVX1SOAfgZOSrD2k9ocqyaJR90HS8CyEWFtV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X9Hji21ZUkSZIkSVrwRvmMnVcD/9GWNwZ+PLDt2lY2Wfk9JNknyQVJLrjxxhvnoLuStLAZZyVpbhlnJUmzMZLETpJ3AbcDxwyrzao6rKqWVtXSxYsXD6tZSVJjnJWkuWWclSTNxqL5PmCSvYC/AHa
"text/plain": [
"<Figure size 1132x360 with 3 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,4),dpi=200)\n",
"sns.catplot(data=df,x='Tenure Cohort',hue='Churn',col='Contract',kind='count')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src='fig11.png'>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"-----\n",
"\n",
"# Part 4: Predictive Modeling\n",
"\n",
"**Let's explore 4 different tree based methods: A Single Decision Tree, Random Forest, AdaBoost, Gradient Boosting. Feel free to add any other supervised learning models to your comparisons!**\n",
"\n",
"\n",
"## Single Decision Tree"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK : Separate out the data into X features and Y label. Create dummy variables where necessary and note which features are not useful and should be dropped.**"
]
},
{
"cell_type": "code",
"execution_count": 178,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 181,
"metadata": {},
"outputs": [],
"source": [
"X = df.drop(['Churn','customerID'],axis=1)\n",
"X = pd.get_dummies(X,drop_first=True)"
]
},
{
"cell_type": "code",
"execution_count": 182,
"metadata": {},
"outputs": [],
"source": [
"y = df['Churn']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Perform a train test split, holding out 10% of the data for testing. We'll use a random_state of 101 in the solutions notebook/video.**"
]
},
{
"cell_type": "code",
"execution_count": 183,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 184,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "code",
"execution_count": 185,
"metadata": {},
"outputs": [],
"source": [
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=101)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Decision Tree Perfomance. Complete the following tasks:**\n",
" 1. Train a single decision tree model (feel free to grid search for optimal hyperparameters).\n",
" 2. Evaluate performance metrics from decision tree, including classification report and plotting a confusion matrix.\n",
" 2. Calculate feature importances from the decision tree.\n",
" 4. OPTIONAL: Plot your tree, note, the tree could be huge depending on your pruning, so it may crash your notebook if you display it with plot_tree."
]
},
{
"cell_type": "code",
"execution_count": 222,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.tree import DecisionTreeClassifier"
]
},
{
"cell_type": "code",
"execution_count": 223,
"metadata": {},
"outputs": [],
"source": [
"dt = DecisionTreeClassifier(max_depth=6)"
]
},
{
"cell_type": "code",
"execution_count": 224,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DecisionTreeClassifier(max_depth=6)"
]
},
"execution_count": 224,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dt.fit(X_train,y_train)"
]
},
{
"cell_type": "code",
"execution_count": 225,
"metadata": {},
"outputs": [],
"source": [
"preds = dt.predict(X_test)"
]
},
{
"cell_type": "code",
"execution_count": 226,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.metrics import accuracy_score,plot_confusion_matrix,classification_report"
]
},
{
"cell_type": "code",
"execution_count": 227,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" No 0.87 0.89 0.88 557\n",
" Yes 0.55 0.49 0.52 147\n",
"\n",
" accuracy 0.81 704\n",
" macro avg 0.71 0.69 0.70 704\n",
"weighted avg 0.80 0.81 0.81 704\n",
"\n"
]
}
],
"source": [
"print(classification_report(y_test,preds))"
]
},
{
"cell_type": "code",
"execution_count": 228,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay at 0x2d1e9601d90>"
]
},
"execution_count": 228,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAUIAAAEGCAYAAAAQZJzmAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAd4UlEQVR4nO3de5he473/8fcn5xARkbCDBKngh02oOraq0W6CitqU0tYme6NFtX5tUftCdXNVi2i24peWStCDQ1uHxvmw0ZZISLOJIhXHhByFSERm5vv7Y90TT8Yc1kyeZ555Zn1e17WuWetep3syl6/7Xvda91cRgZlZkfWodgXMzKrNgdDMCs+B0MwKz4HQzArPgdDMCq9XtSvQXkMG94ythveudjWsHV6ctV61q2Dt9B5LF0XE0I6ef+Dn1o/FS+pzHTtj1qp7I+Kgjt6rHGouEG41vDfT7h1e7WpYOxy42ehqV8Ha6YG49dV1OX/xknqm3Tsi17E9h700ZF3uVQ41FwjNrOsLoIGGalcjNwdCMyu7IFgd+brGXYEDoZlVhFuEZlZoQVBfQ5/vOhCaWUU04EBoZgUWQL0DoZkVnVuEZlZoAaz2M0IzK7Ig3DU2s4ILqK+dOOhAaGbll31ZUjscCM2sAkQ9qnYlcnMgNLOyywZLHAjNrMCy9wgdCM2s4BrcIjSzInOL0MwKLxD1NZQJxIHQzCrCXWMzK7RAfBg9q12N3Gqn7WpmNSN7obpHriUvST0lPSPprrR9vaS5kmamZXQql6SJkuZImiVpt7au7RahmVVEBQZLzgCeBwaWlH0vIm5tctxYYFRa9gSuTj9b5BahmZVdhKiPHrmWPCRtARwC/DLH4eOAKZF5AhgkaVhrJzgQmllFNKBcCzBE0vSS5aRmLncF8H0+/gnzRan7O0FS31S2OfB6yTFvpLIWuWtsZmWXDZbkDi+LImL3lnZKOhRYEBEzJO1fsusc4C2gDzAJOAu4sCP1dSA0s7JrHCwpk32BwyQdDPQDB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rRrpKtzcPf1liZmXniVnNzHAgNLOCa3yPsFY4EJpZRdTSe4QOhGZWdhFQl3PS1a7AgdDMKsJdYzMrND8jNDMDwoHQzIrOgyVmVmgRtfWMsHaGdcyshoj6hh65ljavJPWTNE3S3yQ9J+mHqfx6SXMlzUzL6FQuSRNTgvdZknZr6x5uEZpZRZTxGeEqYExELJfUG3hc0t1p3/ci4tYmx48FRqVlT+Dq9LNFDoRmVnbl/NY4JV5anjZ7p6W1abPGAVPSeU9IGiRpWETMb+kEd43NrPwie06YZyEleC9ZTmp6OUk9Jc0EFgD3R8STaddFqfs7QVLfVLYmwXtSmvy9WW4RmllFtGPUuNUE7wARUQ+MljQI+IOknYBzgLeAPmSpPM4CLuxIXd0iNLOyizIOlqx13Yh3yPIZHxQR8yOzimxy5z3SYY0J3huVJn9vlgOhmVVEO7rGrZI0NLUEkdQf+ALwd0nDUpmAw4Fn0yl3AF9Po8d7Actaez4I7hqbWYWUcdR4GDBZUk+yxtvNEXFXyoc+FBAwEzglHT8VOBiYA6wATmjrBg6EZlZ2WWuvbKPGs4BdmylvNsVHGi0+tT33cCA0s4qopS9LHAjNrCI6IUFm2TgQmlnZBaLBE7OaWdHVUIPQgdDMKqCMgyWdwYHQzCqjhpqEDoRmVhHdokUo6b9pJaZHxLcqUiMzq3kBNDR0g0AITO+0WphZ9xJAd2gRRsTk0m1J60XEispXycy6g1p6j7DNF30k7S1pNvD3tL2LpKsqXjMzq22Rc+kC8rzxeAVwILAYICL+BuxXwTqZWc0TEfmWriDXqHFEvJ7NdLNGfWWqY2bdRhdp7eWRJxC+LmkfIFLilDOA5ytbLTOraQFRQ6PGebr
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plot_confusion_matrix(dt,X_test,y_test)"
]
},
{
"cell_type": "code",
"execution_count": 229,
"metadata": {},
"outputs": [],
"source": [
"imp_feats = pd.DataFrame(data=dt.feature_importances_,index=X.columns,columns=['Feature Importance']).sort_values(\"Feature Importance\")"
]
},
{
"cell_type": "code",
"execution_count": 230,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAACRoAAAYjCAYAAACSohEUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdebh153w38O/vyZOZmIKEIIYiRUwRgkiCUkJNL1J9a6ig5paaqu9LJ1qqFby0VZWooWhrnqfEFEkQYyIRQ8xkJAmZ7/ePtY5n5Tj7rH2mfZ7kfD7Xta619lr3uu/f2Wft/aTOt/ddrbUAAAAAAAAAAAAsZtN6FwAAAAAAAAAAAGz9BI0AAAAAAAAAAIBRgkYAAAAAAAAAAMAoQSMAAAAAAAAAAGCUoBEAAAAAAAAAADBK0AgAAAAAAAAAABglaAQAAAAAAAAAAIwSNAIAAAAAAAAAAEYJGgEAAAAAAAAAAKMEjQAAAAAAAAAAgFGCRgAAAAAAAAAAwChBIwAAAAAAAAAAYJSgEQAAAAAAAAAAMErQCAAAAAAAAAAAGCVoBAAAAAAAAAAAjBI0AgAAAAAAAAAARgkaAQAAAAAAAAAAowSNAAAAAAAAAACAUYJGAAAAAAAAAADAKEEjAAAAANjKVNVDq+o9VfXDqrqgqlq/HbnetbF8VXXgrH6XVXX4YKxHr+VYAAAAbByCRgAAAKyKqjpy8AfNpWwHrnftrL15f1xv610PbK2q86Ykb0tyvyTXSbLd+la1ekb+rTi/qn5aVd+sqk9X1Sur6tFVdf31rputV/+MLOe/P/y3CQAAwDIIGgEAAMASmCGCy7OqeuHg+X3hetfDgh7Rb3OOTXJ4kv/Xb+9Yh5pmZfsk10pykyR3SfKUJK9P8p2qel9V3Xs9iwMAAACSzetdAAAAAFdIx6X74/g0friWhQBczvzh4PgFrbW/WrdK1t78fys2JblKkqsmuUWSGwzO3zfJfavq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K39dMqfeb6575ckefLg/P9b7Kat4LlaD2/PlqBRpfu+evf8RlW1c5IPJbnL4PS3knwhyVnpQkF3SXKddN8xr6yqXVprL5o0cFUdku45HM6wdXKS45P8PN336i36bVO679Elq6qn57Kzj52e7vn7cZLW137zdN89CwWRljrew9M973N9XZLk00lOSffZ3z/d+5Qkj0hyw6q6e2vt/Cn6fnSS1/QvT0ry+XSfp5une/8r3bP/7qraq7X285X+PKvozklemO73fUa6f1tPT/ffDrcdNlzt74y1eH4BAABWTWvNZrPZbDabzWaz2Wy2FW/p/rDd+u2Fy+xjtyQ/HfRzRJLdF2h37ST/M2j3lSTbTOjzxelmNNplwvVKcv90AYq5/u66SI2HD9o9esqf67uDe/acov3oGPPaXNTvX5XkSvPabZtk01q9v0v43R446K9N+Rydny4o8qS5n2HQ7oAk5w7aPi9dCOnnSR6yQL8PSxeWmGt/twnj7zloc2G/Pz3JvRZoe/9+vLn2H1zk53r28Ofvn8vtFnj+PzTv93rHCf09eoHf/5ELPV9Jth8cv3Bw31Sf0yR3TPK3SW65SJtrpQtgzPX90SmfhfP7/bFJbr7AZ/Pp8963BX9vffu/m9f2lUmuMaHtvv3zf4sFrt0iyS/7Pi5N8tIkV12g3Y2SfGow3vtX8hkZ9Dv6Odnanqsl/nxHLvUZnHf/TrnsZ/lFE9odMWhzUpIDF2izTZInDp7Di5PsN6G/26YLj8z1+cVF3sfdkvxZkmePPP9HLnB9c5LTBm2em2TbCeNcPcljFhqnv374oJ9HT2hz43TfnXPtjklyk3ltNiV5RroA0ly7V0zzDPfv7c+S/O4C7e6Wy36H/t/V+Ayt5Lmb1+6idN8BfzH/d5DLfq+u+nfGaj+/NpvNZrPZbDabzba
"text/plain": [
"<Figure size 2800x1200 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(14,6),dpi=200)\n",
"sns.barplot(data=imp_feats.sort_values('Feature Importance'),x=imp_feats.sort_values('Feature Importance').index,y='Feature Importance')\n",
"plt.xticks(rotation=90)\n",
"plt.title(\"Feature Importance for Decision Tree\");"
]
},
{
"cell_type": "code",
"execution_count": 231,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.tree import plot_tree"
]
},
{
"cell_type": "code",
"execution_count": 233,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABZEAAAOnCAYAAABRRAhMAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAABcSAAAXEgFnn9JSAAEAAElEQVR4nOzdd7hcVdmG8fuFNJJA6EWaSlHEQkdABBEFFJAq0otixYa9+1mwIhZEBJTeBSyAFAsdO4hUFUEQpCdAOkne74+145wAJ6Scc9aU+3ddXrpnJ2ceMJnZ887az4rMRJIkSZIkSZKkZ7NI7QCSJEmSJEmSpPblEFmSJEmSJEmS1C+HyJIkSZIkSZKkfjlEliRJkiRJkiT1yyGyJEmSJEmSJKlfDpElSZIkSZIkSf1yiCxJkiRJkiRJ6pdDZEmSJEmSJElSvxwiS5IkSZIkSZL65RBZkiRJkiRJktQvh8iSJEmSJEmSpH45RJYkSZIkSZIk9cshsiRJkiRJkiSpXw6RJUmSJEmSJEn9cogsSZIkSZIkSeqXQ2RJkiRJkiRJUr8cIkuSJEmSJEmS+uUQWZIkSZIkSZLUL4fIkiRJkiRJkqR+OUSWJEmSJEmSJPXLIbIkSZIkSZIkqV8OkSVJkiRJkiRJ/XKILEmSJEmSJEnql0NkSZIkSZIkSVK/HCJLkiRJkiRJkvrlEFmSJEmSJEmS1C+HyJIkSZIkSZKkfjlEliRJkiRJkiT1yyGyJEmSJEmSJKlfDpElSZIkSZIkSf1yiCxJkiRJkiRJ6pdDZEmSJEmSJElSvxwiS5IkSZIkSZL65RBZkiRJkiRJktQvh8iSJEmSJEmSpH45RJYkSZIkSZIk9cshsiRJkiRJkiSpXw6RJUmSJE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"<Figure size 1800x1200 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(12,8),dpi=150)\n",
"plot_tree(dt,filled=True,feature_names=X.columns);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src='hugetree.png'>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Random Forest\n",
"\n",
"**TASK: Create a Random Forest model and create a classification report and confusion matrix from its predicted results on the test set.**"
]
},
{
"cell_type": "code",
"execution_count": 259,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 260,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.ensemble import RandomForestClassifier"
]
},
{
"cell_type": "code",
"execution_count": 266,
"metadata": {},
"outputs": [],
"source": [
"rf = RandomForestClassifier(n_estimators=100)"
]
},
{
"cell_type": "code",
"execution_count": 267,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RandomForestClassifier()"
]
},
"execution_count": 267,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rf.fit(X_train,y_train)"
]
},
{
"cell_type": "code",
"execution_count": 268,
"metadata": {},
"outputs": [],
"source": [
"preds = rf.predict(X_test)"
]
},
{
"cell_type": "code",
"execution_count": 269,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" No 0.86 0.89 0.87 557\n",
" Yes 0.52 0.44 0.48 147\n",
"\n",
" accuracy 0.80 704\n",
" macro avg 0.69 0.67 0.68 704\n",
"weighted avg 0.79 0.80 0.79 704\n",
"\n"
]
}
],
"source": [
"print(classification_report(y_test,preds))"
]
},
{
"cell_type": "code",
"execution_count": 270,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay at 0x2d1e6a54040>"
]
},
"execution_count": 270,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/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dDMKsJdYzMrND8jNDMDwoHQzIrOgyVmVmgRtfWMsHaGdcyshoj6hh65ljavJPWTNE3S3yQ9J+mHqfx6SXMlzUzL6FQuSRNTgvdZknZr6x5uEZpZRZTxGeEqYExELJfUG3hc0t1p3/ci4tYmx48FRqVlT+Dq9LNFDoRmVnbl/NY4JV5anjZ7p6W1abPGAVPSeU9IGiRpWETMb+kEd43NrPwie06YZyEleC9ZTmp6OUk9Jc0EFgD3R8STaddFqfs7QVLfVLYmwXtSmvy9WW4RmllFtGPUuNUE7wARUQ+MljQI+IOknYBzgLeAPmSpPM4CLuxIXd0iNLOyizIOlqx13Yh3yPIZHxQR8yOzimxy5z3SYY0J3huVJn9vlgOhmVVEO7rGrZI0NLUEkdQf+ALwd0nDUpmAw4Fn0yl3AF9Po8d7Actaez4I7hqbWYWUcdR4GDBZUk+yxtvNEXFXyoc+FBAwEzglHT8VOBiYA6wATmjrBg6EZlZ2WWuvbKPGs4BdmylvNsVHGi0+tT33cCA0s4qopS9LHAjNrCI6IUFm2TgQmlnZBaLBE7OaWdHVUIPQgdDMKqCMgyWdwYHQzCqjhpqEDoRmVhHdokUo6b9pJaZHxLcqUiMzq3kBNDR0g0AITO+0WphZ9xJAd2gRRsTk0m1J60XEispXycy6g1p6j7DNF30k7S1pNvD3tL2LpKsqXjMzq22Rc+kC8rzxeAVwILAYICL+BuxXwTqZWc0TEfmWriDXqHFEvJ7NdLNGfWWqY2bdRhdp7eWRJxC+LmkfIFLilDOA5ytbLTOraQFRQ6PGebr
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plot_confusion_matrix(dt,X_test,y_test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Boosted Trees\n",
"\n",
"**TASK: Use AdaBoost or Gradient Boosting to create a model and report back the classification report and plot a confusion matrix for its predicted results**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 288,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.ensemble import GradientBoostingClassifier,AdaBoostClassifier"
]
},
{
"cell_type": "code",
"execution_count": 289,
"metadata": {},
"outputs": [],
"source": [
"ada_model = AdaBoostClassifier()"
]
},
{
"cell_type": "code",
"execution_count": 290,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AdaBoostClassifier()"
]
},
"execution_count": 290,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ada_model.fit(X_train,y_train)"
]
},
{
"cell_type": "code",
"execution_count": 291,
"metadata": {},
"outputs": [],
"source": [
"preds = ada_model.predict(X_test)"
]
},
{
"cell_type": "code",
"execution_count": 292,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" No 0.88 0.90 0.89 557\n",
" Yes 0.60 0.54 0.57 147\n",
"\n",
" accuracy 0.83 704\n",
" macro avg 0.74 0.72 0.73 704\n",
"weighted avg 0.82 0.83 0.83 704\n",
"\n"
]
}
],
"source": [
"print(classification_report(y_test,preds))"
]
},
{
"cell_type": "code",
"execution_count": 293,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay at 0x2d1e9373a30>"
]
},
"execution_count": 293,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAUIAAAEGCAYAAAAQZJzmAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAd4UlEQVR4nO3de5he473/8fcn5xARkbCDBKngh02oOraq0W6CitqU0tYme6NFtX5tUftCdXNVi2i24peWStCDQ1uHxvmw0ZZISLOJIhXHhByFSERm5vv7Y90TT8Yc1kyeZ555Zn1e17W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IOknYBzgLeAPmSpPM4CLuxIXd0iNLOyizIOlqx13Yh3yPIZHxQR8yOzimxy5z3SYY0J3huVJn9vlgOhmVVEO7rGrZI0NLUEkdQf+ALwd0nDUpmAw4Fn0yl3AF9Po8d7Actaez4I7hqbWYWUcdR4GDBZUk+yxtvNEXFXyoc+FBAwEzglHT8VOBiYA6wATmjrBg6EZlZ2WWuvbKPGs4BdmylvNsVHGi0+tT33cCA0s4qopS9LHAjNrCI6IUFm2TgQmlnZBaLBE7OaWdHVUIPQgdDMKqCMgyWdwYHQzCqjhpqEDoRmVhHdokUo6b9pJaZHxLcqUiMzq3kBNDR0g0AITO+0WphZ9xJAd2gRRsTk0m1J60XEispXycy6g1p6j7DNF30k7S1pNvD3tL2LpKsqXjMzq22Rc+kC8rzxeAVwILAYICL+BuxXwTqZWc0TEfmWriDXqHFEvJ7NdLNGfWWqY2bdRhdp7eWRJxC+LmkfIFLilDOA5ytbLTOraQFRQ6PGebr
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plot_confusion_matrix(dt,X_test,y_test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**TASK: Analyze your results, which model performed best for you?**"
]
},
{
"cell_type": "code",
"execution_count": 294,
"metadata": {},
"outputs": [],
"source": [
"# With base models, we got best performance from an AdaBoostClassifier, but note, we didn't do any gridsearching AND most models performed about the same on the data set."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Great job!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}