{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ab3c44f1-b880-42ed-98e9-e8b8394f13a5",
   "metadata": {},
   "source": [
    "# Customer Lifetime Value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd735dde-76f2-45ef-b3b0-0f4d923ff30e",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9976dad-4321-472f-8b2b-eb7e24127f1c",
   "metadata": {},
   "source": [
    "## Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "efc9ea60-6f34-4540-804a-ee684cf66093",
   "metadata": {},
   "outputs": [],
   "source": [
    "from fastai.vision.all import *\n",
    "from aiking.data.external import * #We need to import this after fastai modules\n",
    "import pandas as pd\n",
    "from sklearn.ensemble import RandomForestRegressor\n",
    "from sklearn.model_selection import cross_val_score\n",
    "from sklearn.feature_selection import mutual_info_regression"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "074a41c2-c2c7-4da4-9e3a-ee1d6dd155d8",
   "metadata": {},
   "source": [
    "## Getting Dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3dd737ad-86ce-4652-b299-0232360a9849",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Path('/content/drive/MyDrive/PPV/S_Personal_Study/aiking/data/ibm-watson-marketing-customer-value-data')"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#kaggle datasets download -d pankajjsh06/ibm-watson-marketing-customer-value-data\n",
    "path = untar_data(\"kaggle_datasets::pankajjsh06/ibm-watson-marketing-customer-value-data\"); path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec59a26e-9603-47f7-8694-e72410e18f6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(#1) [Path('/content/drive/MyDrive/PPV/S_Personal_Study/aiking/data/ibm-watson-marketing-customer-value-data/WA_Fn-UseC_-Marketing-Customer-Value-Analysis.csv')]"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "path.ls()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6842a931-5a78-4036-a58b-4bbd5172bc5b",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(path/\"WA_Fn-UseC_-Marketing-Customer-Value-Analysis.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb41a39d-442a-4776-b487-78b0da188189",
   "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>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Customer</th>\n",
       "      <td>BU79786</td>\n",
       "      <td>QZ44356</td>\n",
       "      <td>AI49188</td>\n",
       "      <td>WW63253</td>\n",
       "      <td>HB64268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <td>Washington</td>\n",
       "      <td>Arizona</td>\n",
       "      <td>Nevada</td>\n",
       "      <td>California</td>\n",
       "      <td>Washington</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Customer Lifetime Value</th>\n",
       "      <td>2763.519279</td>\n",
       "      <td>6979.535903</td>\n",
       "      <td>12887.43165</td>\n",
       "      <td>7645.861827</td>\n",
       "      <td>2813.692575</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Response</th>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Coverage</th>\n",
       "      <td>Basic</td>\n",
       "      <td>Extended</td>\n",
       "      <td>Premium</td>\n",
       "      <td>Basic</td>\n",
       "      <td>Basic</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Education</th>\n",
       "      <td>Bachelor</td>\n",
       "      <td>Bachelor</td>\n",
       "      <td>Bachelor</td>\n",
       "      <td>Bachelor</td>\n",
       "      <td>Bachelor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Effective To Date</th>\n",
       "      <td>2/24/11</td>\n",
       "      <td>1/31/11</td>\n",
       "      <td>2/19/11</td>\n",
       "      <td>1/20/11</td>\n",
       "      <td>2/3/11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>EmploymentStatus</th>\n",
       "      <td>Employed</td>\n",
       "      <td>Unemployed</td>\n",
       "      <td>Employed</td>\n",
       "      <td>Unemployed</td>\n",
       "      <td>Employed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gender</th>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Income</th>\n",
       "      <td>56274</td>\n",
       "      <td>0</td>\n",
       "      <td>48767</td>\n",
       "      <td>0</td>\n",
       "      <td>43836</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Location Code</th>\n",
       "      <td>Suburban</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>Rural</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marital Status</th>\n",
       "      <td>Married</td>\n",
       "      <td>Single</td>\n",
       "      <td>Married</td>\n",
       "      <td>Married</td>\n",
       "      <td>Single</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Monthly Premium Auto</th>\n",
       "      <td>69</td>\n",
       "      <td>94</td>\n",
       "      <td>108</td>\n",
       "      <td>106</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Months Since Last Claim</th>\n",
       "      <td>32</td>\n",
       "      <td>13</td>\n",
       "      <td>18</td>\n",
       "      <td>18</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Months Since Policy Inception</th>\n",
       "      <td>5</td>\n",
       "      <td>42</td>\n",
       "      <td>38</td>\n",
       "      <td>65</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Number of Open Complaints</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Number of Policies</th>\n",
       "      <td>1</td>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Policy Type</th>\n",
       "      <td>Corporate Auto</td>\n",
       "      <td>Personal Auto</td>\n",
       "      <td>Personal Auto</td>\n",
       "      <td>Corporate Auto</td>\n",
       "      <td>Personal Auto</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Policy</th>\n",
       "      <td>Corporate L3</td>\n",
       "      <td>Personal L3</td>\n",
       "      <td>Personal L3</td>\n",
       "      <td>Corporate L2</td>\n",
       "      <td>Personal L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Renew Offer Type</th>\n",
       "      <td>Offer1</td>\n",
       "      <td>Offer3</td>\n",
       "      <td>Offer1</td>\n",
       "      <td>Offer1</td>\n",
       "      <td>Offer1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sales Channel</th>\n",
       "      <td>Agent</td>\n",
       "      <td>Agent</td>\n",
       "      <td>Agent</td>\n",
       "      <td>Call Center</td>\n",
       "      <td>Agent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Total Claim Amount</th>\n",
       "      <td>384.811147</td>\n",
       "      <td>1131.464935</td>\n",
       "      <td>566.472247</td>\n",
       "      <td>529.881344</td>\n",
       "      <td>138.130879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Vehicle Class</th>\n",
       "      <td>Two-Door Car</td>\n",
       "      <td>Four-Door Car</td>\n",
       "      <td>Two-Door Car</td>\n",
       "      <td>SUV</td>\n",
       "      <td>Four-Door Car</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Vehicle Size</th>\n",
       "      <td>Medsize</td>\n",
       "      <td>Medsize</td>\n",
       "      <td>Medsize</td>\n",
       "      <td>Medsize</td>\n",
       "      <td>Medsize</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            0  ...              4\n",
       "Customer                              BU79786  ...        HB64268\n",
       "State                              Washington  ...     Washington\n",
       "Customer Lifetime Value           2763.519279  ...    2813.692575\n",
       "Response                                   No  ...             No\n",
       "Coverage                                Basic  ...          Basic\n",
       "Education                            Bachelor  ...       Bachelor\n",
       "Effective To Date                     2/24/11  ...         2/3/11\n",
       "EmploymentStatus                     Employed  ...       Employed\n",
       "Gender                                      F  ...              M\n",
       "Income                                  56274  ...          43836\n",
       "Location Code                        Suburban  ...          Rural\n",
       "Marital Status                        Married  ...         Single\n",
       "Monthly Premium Auto                       69  ...             73\n",
       "Months Since Last Claim                    32  ...             12\n",
       "Months Since Policy Inception               5  ...             44\n",
       "Number of Open Complaints                   0  ...              0\n",
       "Number of Policies                          1  ...              1\n",
       "Policy Type                    Corporate Auto  ...  Personal Auto\n",
       "Policy                           Corporate L3  ...    Personal L1\n",
       "Renew Offer Type                       Offer1  ...         Offer1\n",
       "Sales Channel                           Agent  ...          Agent\n",
       "Total Claim Amount                 384.811147  ...     138.130879\n",
       "Vehicle Class                    Two-Door Car  ...  Four-Door Car\n",
       "Vehicle Size                          Medsize  ...        Medsize\n",
       "\n",
       "[24 rows x 5 columns]"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head().T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8926c0db-45cf-45dd-b3c9-d7a74fa4709a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}