From 042a680399c2e6c12a818f29317b93df8c91ae5c Mon Sep 17 00:00:00 2001 From: Davi Santos Date: Tue, 2 Apr 2024 17:54:53 -0300 Subject: [PATCH 1/3] Sending resolution --- files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb diff --git a/files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb b/files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb new file mode 100644 index 0000000..e69de29 From bcd7997a22e85d08119dec304a728553c505de3e Mon Sep 17 00:00:00 2001 From: Davi Santos Date: Sat, 6 Apr 2024 12:54:51 -0300 Subject: [PATCH 2/3] Delete files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb --- files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb diff --git a/files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb b/files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb deleted file mode 100644 index e69de29..0000000 From e264e2b9bfcbece40597234204b351487f758f6d Mon Sep 17 00:00:00 2001 From: Davi Santos Date: Sat, 6 Apr 2024 12:55:26 -0300 Subject: [PATCH 3/3] Add files via upload --- .../[Davi]lab-customer-analysis-round-5.ipynb | 637 ++++++++++++++++++ 1 file changed, 637 insertions(+) create mode 100644 files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb diff --git a/files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb b/files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb new file mode 100644 index 0000000..dcd3c6a --- /dev/null +++ b/files_for_lab/[Davi]lab-customer-analysis-round-5.ipynb @@ -0,0 +1,637 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "\n", + "import warnings\n", + "warnings.filterwarnings('ignore')\n", + "\n", + "import matplotlib.pyplot as plt\n", + "%matplotlib inline\n", + "\n", + "import seaborn as sns\n", + "from sklearn import linear_model\n", + "from sklearn.metrics import mean_squared_error, r2_score\n", + "\n", + "import statsmodels.api as sm\n", + "from statsmodels.formula.api import ols" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customerstatecustomer_lifetime_valueresponsecoverageeducationeffective_to_dateemploymentstatusgenderincome...months_since_policy_inceptionnumber_of_open_complaintsnumber_of_policiespolicy_typepolicyrenew_offer_typesales_channeltotal_claim_amountvehicle_classvehicle_size
0BU79786Washington2763.519279NoBasicBachelor2/24/11EmployedF56274...501Corporate AutoCorporate L3Offer1Agent384.811147Two-Door CarMedsize
1QZ44356Arizona6979.535903NoExtendedBachelor1/31/11UnemployedF0...4208Personal AutoPersonal L3Offer3Agent1131.464935Four-Door CarMedsize
2AI49188Nevada12887.431650NoPremiumBachelor2/19/11EmployedF48767...3802Personal AutoPersonal L3Offer1Agent566.472247Two-Door CarMedsize
3WW63253California7645.861827NoBasicBachelor1/20/11UnemployedM0...6507Corporate AutoCorporate L2Offer1Call Center529.881344SUVMedsize
4HB64268Washington2813.692575NoBasicBachelor2/3/11EmployedM43836...4401Personal AutoPersonal L1Offer1Agent138.130879Four-Door CarMedsize
..................................................................
9129LA72316California23405.987980NoBasicBachelor2/10/11EmployedM71941...8902Personal AutoPersonal L1Offer2Web198.234764Four-Door CarMedsize
9130PK87824California3096.511217YesExtendedCollege2/12/11EmployedF21604...2801Corporate AutoCorporate L3Offer1Branch379.200000Four-Door CarMedsize
9131TD14365California8163.890428NoExtendedBachelor2/6/11UnemployedM0...3732Corporate AutoCorporate L2Offer1Branch790.784983Four-Door CarMedsize
9132UP19263California7524.442436NoExtendedCollege2/3/11EmployedM21941...303Personal AutoPersonal L2Offer3Branch691.200000Four-Door CarLarge
9133Y167826California2611.836866NoExtendedCollege2/14/11UnemployedM0...9001Corporate AutoCorporate L3Offer4Call Center369.600000Two-Door CarMedsize
\n", + "

9134 rows × 24 columns

\n", + "
" + ], + "text/plain": [ + " customer state customer_lifetime_value response coverage \\\n", + "0 BU79786 Washington 2763.519279 No Basic \n", + "1 QZ44356 Arizona 6979.535903 No Extended \n", + "2 AI49188 Nevada 12887.431650 No Premium \n", + "3 WW63253 California 7645.861827 No Basic \n", + "4 HB64268 Washington 2813.692575 No Basic \n", + "... ... ... ... ... ... \n", + "9129 LA72316 California 23405.987980 No Basic \n", + "9130 PK87824 California 3096.511217 Yes Extended \n", + "9131 TD14365 California 8163.890428 No Extended \n", + "9132 UP19263 California 7524.442436 No Extended \n", + "9133 Y167826 California 2611.836866 No Extended \n", + "\n", + " education effective_to_date employmentstatus gender income ... \\\n", + "0 Bachelor 2/24/11 Employed F 56274 ... \n", + "1 Bachelor 1/31/11 Unemployed F 0 ... \n", + "2 Bachelor 2/19/11 Employed F 48767 ... \n", + "3 Bachelor 1/20/11 Unemployed M 0 ... \n", + "4 Bachelor 2/3/11 Employed M 43836 ... \n", + "... ... ... ... ... ... ... \n", + "9129 Bachelor 2/10/11 Employed M 71941 ... \n", + "9130 College 2/12/11 Employed F 21604 ... \n", + "9131 Bachelor 2/6/11 Unemployed M 0 ... \n", + "9132 College 2/3/11 Employed M 21941 ... \n", + "9133 College 2/14/11 Unemployed M 0 ... \n", + "\n", + " months_since_policy_inception number_of_open_complaints \\\n", + "0 5 0 \n", + "1 42 0 \n", + "2 38 0 \n", + "3 65 0 \n", + "4 44 0 \n", + "... ... ... \n", + "9129 89 0 \n", + "9130 28 0 \n", + "9131 37 3 \n", + "9132 3 0 \n", + "9133 90 0 \n", + "\n", + " number_of_policies policy_type policy renew_offer_type \\\n", + "0 1 Corporate Auto Corporate L3 Offer1 \n", + "1 8 Personal Auto Personal L3 Offer3 \n", + "2 2 Personal Auto Personal L3 Offer1 \n", + "3 7 Corporate Auto Corporate L2 Offer1 \n", + "4 1 Personal Auto Personal L1 Offer1 \n", + "... ... ... ... ... \n", + "9129 2 Personal Auto Personal L1 Offer2 \n", + "9130 1 Corporate Auto Corporate L3 Offer1 \n", + "9131 2 Corporate Auto Corporate L2 Offer1 \n", + "9132 3 Personal Auto Personal L2 Offer3 \n", + "9133 1 Corporate Auto Corporate L3 Offer4 \n", + "\n", + " sales_channel total_claim_amount vehicle_class vehicle_size \n", + "0 Agent 384.811147 Two-Door Car Medsize \n", + "1 Agent 1131.464935 Four-Door Car Medsize \n", + "2 Agent 566.472247 Two-Door Car Medsize \n", + "3 Call Center 529.881344 SUV Medsize \n", + "4 Agent 138.130879 Four-Door Car Medsize \n", + "... ... ... ... ... \n", + "9129 Web 198.234764 Four-Door Car Medsize \n", + "9130 Branch 379.200000 Four-Door Car Medsize \n", + "9131 Branch 790.784983 Four-Door Car Medsize \n", + "9132 Branch 691.200000 Four-Door Car Large \n", + "9133 Call Center 369.600000 Two-Door Car Medsize \n", + "\n", + "[9134 rows x 24 columns]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.read_csv(r'csv_files\\marketing_customer_analysis.csv')\n", + "cols = []\n", + "for i in range(len(df.columns)):\n", + " cols.append(df.columns[i].lower().replace(' ', '_'))\n", + "df.columns = cols\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "customer object\n", + "state object\n", + "customer_lifetime_value float64\n", + "response object\n", + "coverage object\n", + "education object\n", + "effective_to_date object\n", + "employmentstatus object\n", + "gender object\n", + "income int64\n", + "location_code object\n", + "marital_status object\n", + "monthly_premium_auto int64\n", + "months_since_last_claim int64\n", + "months_since_policy_inception int64\n", + "number_of_open_complaints int64\n", + "number_of_policies int64\n", + "policy_type object\n", + "policy object\n", + "renew_offer_type object\n", + "sales_channel object\n", + "total_claim_amount float64\n", + "vehicle_class object\n", + "vehicle_size object\n", + "dtype: object" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.dtypes" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "
OLS Regression Results
Dep. Variable: total_claim_amount R-squared (uncentered): 0.508
Model: OLS Adj. R-squared (uncentered): 0.508
Method: Least Squares F-statistic: 9426.
Date: Tue, 02 Apr 2024 Prob (F-statistic): 0.00
Time: 21:50:34 Log-Likelihood: -66885.
No. Observations: 9134 AIC: 1.338e+05
Df Residuals: 9133 BIC: 1.338e+05
Df Model: 1
Covariance Type: nonrobust
\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "
coef std err t P>|t| [0.025 0.975]
customer_lifetime_value 0.0353 0.000 97.089 0.000 0.035 0.036
\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "
Omnibus: 843.685 Durbin-Watson: 1.647
Prob(Omnibus): 0.000 Jarque-Bera (JB): 6058.287
Skew: -0.059 Prob(JB): 0.00
Kurtosis: 6.988 Cond. No. 1.00


Notes:
[1] R² is computed without centering (uncentered) since the model does not contain a constant.
[2] Standard Errors assume that the covariance matrix of the errors is correctly specified." + ], + "text/latex": [ + "\\begin{center}\n", + "\\begin{tabular}{lclc}\n", + "\\toprule\n", + "\\textbf{Dep. Variable:} & total\\_claim\\_amount & \\textbf{ R-squared (uncentered):} & 0.508 \\\\\n", + "\\textbf{Model:} & OLS & \\textbf{ Adj. R-squared (uncentered):} & 0.508 \\\\\n", + "\\textbf{Method:} & Least Squares & \\textbf{ F-statistic: } & 9426. \\\\\n", + "\\textbf{Date:} & Tue, 02 Apr 2024 & \\textbf{ Prob (F-statistic):} & 0.00 \\\\\n", + "\\textbf{Time:} & 21:50:34 & \\textbf{ Log-Likelihood: } & -66885. \\\\\n", + "\\textbf{No. Observations:} & 9134 & \\textbf{ AIC: } & 1.338e+05 \\\\\n", + "\\textbf{Df Residuals:} & 9133 & \\textbf{ BIC: } & 1.338e+05 \\\\\n", + "\\textbf{Df Model:} & 1 & \\textbf{ } & \\\\\n", + "\\textbf{Covariance Type:} & nonrobust & \\textbf{ } & \\\\\n", + "\\bottomrule\n", + "\\end{tabular}\n", + "\\begin{tabular}{lcccccc}\n", + " & \\textbf{coef} & \\textbf{std err} & \\textbf{t} & \\textbf{P$> |$t$|$} & \\textbf{[0.025} & \\textbf{0.975]} \\\\\n", + "\\midrule\n", + "\\textbf{customer\\_lifetime\\_value} & 0.0353 & 0.000 & 97.089 & 0.000 & 0.035 & 0.036 \\\\\n", + "\\bottomrule\n", + "\\end{tabular}\n", + "\\begin{tabular}{lclc}\n", + "\\textbf{Omnibus:} & 843.685 & \\textbf{ Durbin-Watson: } & 1.647 \\\\\n", + "\\textbf{Prob(Omnibus):} & 0.000 & \\textbf{ Jarque-Bera (JB): } & 6058.287 \\\\\n", + "\\textbf{Skew:} & -0.059 & \\textbf{ Prob(JB): } & 0.00 \\\\\n", + "\\textbf{Kurtosis:} & 6.988 & \\textbf{ Cond. No. } & 1.00 \\\\\n", + "\\bottomrule\n", + "\\end{tabular}\n", + "%\\caption{OLS Regression Results}\n", + "\\end{center}\n", + "\n", + "Notes: \\newline\n", + " [1] R² is computed without centering (uncentered) since the model does not contain a constant. \\newline\n", + " [2] Standard Errors assume that the covariance matrix of the errors is correctly specified." + ], + "text/plain": [ + "\n", + "\"\"\"\n", + " OLS Regression Results \n", + "=======================================================================================\n", + "Dep. Variable: total_claim_amount R-squared (uncentered): 0.508\n", + "Model: OLS Adj. R-squared (uncentered): 0.508\n", + "Method: Least Squares F-statistic: 9426.\n", + "Date: Tue, 02 Apr 2024 Prob (F-statistic): 0.00\n", + "Time: 21:50:34 Log-Likelihood: -66885.\n", + "No. Observations: 9134 AIC: 1.338e+05\n", + "Df Residuals: 9133 BIC: 1.338e+05\n", + "Df Model: 1 \n", + "Covariance Type: nonrobust \n", + "===========================================================================================\n", + " coef std err t P>|t| [0.025 0.975]\n", + "-------------------------------------------------------------------------------------------\n", + "customer_lifetime_value 0.0353 0.000 97.089 0.000 0.035 0.036\n", + "==============================================================================\n", + "Omnibus: 843.685 Durbin-Watson: 1.647\n", + "Prob(Omnibus): 0.000 Jarque-Bera (JB): 6058.287\n", + "Skew: -0.059 Prob(JB): 0.00\n", + "Kurtosis: 6.988 Cond. No. 1.00\n", + "==============================================================================\n", + "\n", + "Notes:\n", + "[1] R² is computed without centering (uncentered) since the model does not contain a constant.\n", + "[2] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n", + "\"\"\"" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# X-y split.\n", + "\n", + "Y = df['total_claim_amount']\n", + "X = df['customer_lifetime_value']\n", + "\n", + "model = sm.OLS(Y,X).fit()\n", + "\n", + "model.summary()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "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.11.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}