Project 2 - EDA on Vehicle Insurance Customer Data
1.Question
import pandas as pd
import numpy as np
Customer_Detail=pd.read_csv('customer_details.csv')
Customer_Policy=pd.read_csv('customer_policy_details.csv')
Customer_Detail.columns=['Customer_id','Gender','Age','Driving Licence Present','Region Code','Previously Insured','Vehicle age','Vehicle Damage']
Customer_Policy.columns=['Customer_id','Annual Premium(in Rs)','Sales Channel code','Vintage', 'Response']
Customer_Detail
Ans:
| Customer_id | Gender | Age | Driving Licence Present | Region Code | Previously Insured | Vehicle age | Vehicle Damage | |
|---|---|---|---|---|---|---|---|---|
| 0 | 1.0 | Male | 44.0 | 1.0 | 28.0 | 0.0 | > 2 Years | Yes |
| 1 | 2.0 | Male | 76.0 | 1.0 | 3.0 | 0.0 | 1-2 Year | No |
| 2 | 3.0 | Male | 47.0 | 1.0 | 28.0 | 0.0 | > 2 Years | Yes |
| 3 | 4.0 | Male | 21.0 | 1.0 | 11.0 | 1.0 | < 1 Year | No |
| 4 | 5.0 | Female | 29.0 | 1.0 | 41.0 | 1.0 | < 1 Year | No |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | Male | 74.0 | 1.0 | 26.0 | 1.0 | 1-2 Year | No |
| 381105 | 381106.0 | Male | 30.0 | 1.0 | 37.0 | 1.0 | < 1 Year | No |
| 381106 | 381107.0 | Male | 21.0 | 1.0 | 30.0 | 1.0 | < 1 Year | No |
| 381107 | 381108.0 | Female | 68.0 | 1.0 | 14.0 | 0.0 | > 2 Years | Yes |
| 381108 | 381109.0 | Male | 46.0 | 1.0 | 29.0 | 0.0 | 1-2 Year | No |
381109 rows × 8 columns
Customer_Policy
Ans:
| Customer_id | Annual Premium(in Rs) | Sales Channel code | Vintage | Response | |
|---|---|---|---|---|---|
| 0 | 1.0 | 40454.0 | 26.0 | 217.0 | 1.0 |
| 1 | 2.0 | 33536.0 | 26.0 | 183.0 | 0.0 |
| 2 | 3.0 | 38294.0 | 26.0 | 27.0 | 1.0 |
| 3 | 4.0 | 28619.0 | 152.0 | 203.0 | 0.0 |
| 4 | 5.0 | 27496.0 | 152.0 | 39.0 | 0.0 |
| ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | 30170.0 | 26.0 | 88.0 | 0.0 |
| 381105 | 381106.0 | 40016.0 | 152.0 | 131.0 | 0.0 |
| 381106 | 381107.0 | 35118.0 | 160.0 | 161.0 | 0.0 |
| 381107 | 381108.0 | 44617.0 | 124.0 | 74.0 | 0.0 |
| 381108 | 381109.0 | 41777.0 | 26.0 | 237.0 | 0.0 |
381109 rows × 5 columns
2.Question
Customer_Detail.isnull().sum()
Ans:
Customer_id 386 Gender 368 Age 368 Driving Licence Present 393 Region Code 392 Previously Insured 381 Vehicle age 381 Vehicle Damage 407 dtype: int64
Customer_Detail.fillna(Customer_Detail.mean())
Ans:
| Customer_id | Gender | Age | Driving Licence Present | Region Code | Previously Insured | Vehicle age | Vehicle Damage | |
|---|---|---|---|---|---|---|---|---|
| 0 | 1.0 | Male | 44.0 | 1.0 | 28.0 | 0.0 | > 2 Years | Yes |
| 1 | 2.0 | Male | 76.0 | 1.0 | 3.0 | 0.0 | 1-2 Year | No |
| 2 | 3.0 | Male | 47.0 | 1.0 | 28.0 | 0.0 | > 2 Years | Yes |
| 3 | 4.0 | Male | 21.0 | 1.0 | 11.0 | 1.0 | < 1 Year | No |
| 4 | 5.0 | Female | 29.0 | 1.0 | 41.0 | 1.0 | < 1 Year | No |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | Male | 74.0 | 1.0 | 26.0 | 1.0 | 1-2 Year | No |
| 381105 | 381106.0 | Male | 30.0 | 1.0 | 37.0 | 1.0 | < 1 Year | No |
| 381106 | 381107.0 | Male | 21.0 | 1.0 | 30.0 | 1.0 | < 1 Year | No |
| 381107 | 381108.0 | Female | 68.0 | 1.0 | 14.0 | 0.0 | > 2 Years | Yes |
| 381108 | 381109.0 | Male | 46.0 | 1.0 | 29.0 | 0.0 | 1-2 Year | No |
381109 rows × 8 columns
Customer_Policy.isnull().sum()
Customer_id 387 Annual Premium(in Rs) 346 Sales Channel code 400 Vintage 388 Response 361 dtype: int64
Customer_Policy.fillna(Customer_Policy.mean())
| Customer_id | Annual Premium(in Rs) | Sales Channel code | Vintage | Response | |
|---|---|---|---|---|---|
| 0 | 1.0 | 40454.0 | 26.0 | 217.0 | 1.0 |
| 1 | 2.0 | 33536.0 | 26.0 | 183.0 | 0.0 |
| 2 | 3.0 | 38294.0 | 26.0 | 27.0 | 1.0 |
| 3 | 4.0 | 28619.0 | 152.0 | 203.0 | 0.0 |
| 4 | 5.0 | 27496.0 | 152.0 | 39.0 | 0.0 |
| ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | 30170.0 | 26.0 | 88.0 | 0.0 |
| 381105 | 381106.0 | 40016.0 | 152.0 | 131.0 | 0.0 |
| 381106 | 381107.0 | 35118.0 | 160.0 | 161.0 | 0.0 |
| 381107 | 381108.0 | 44617.0 | 124.0 | 74.0 | 0.0 |
| 381108 | 381109.0 | 41777.0 | 26.0 | 237.0 | 0.0 |
381109 rows × 5 columns
Customer_Detail['Gender'].fillna(Customer_Detail['Gender'].mode()[0],inplace=True
Customer_Detail['Vehicle age'].fillna(Customer_Detail['Vehicle age'].mode()[0],inplace=True)
Customer_Detail['Region Code'].fillna(Customer_Detail['Region Code'].mode()[0],inplace=True)
Customer_Policy.fillna(Customer_Policy).mode()
| Customer_id | Annual Premium(in Rs) | Sales Channel code | Vintage | Response | |
|---|---|---|---|---|---|
| 0 | 1.0 | 2630.0 | 152.0 | 256.0 | 0.0 |
| 1 | 2.0 | NaN | NaN | NaN | NaN |
| 2 | 3.0 | NaN | NaN | NaN | NaN |
| 3 | 4.0 | NaN | NaN | NaN | NaN |
| 4 | 5.0 | NaN | NaN | NaN | NaN |
| ... | ... | ... | ... | ... | ... |
| 380717 | 381105.0 | NaN | NaN | NaN | NaN |
| 380718 | 381106.0 | NaN | NaN | NaN | NaN |
| 380719 | 381107.0 | NaN | NaN | NaN | NaN |
| 380720 | 381108.0 | NaN | NaN | NaN | NaN |
| 380721 | 381109.0 | NaN | NaN | NaN | NaN |
380722 rows × 5 columns
Customer_Detail.dropna(subset=["Customer_id"],inplace=True)
Customer_Policy.dropna(subset=["Customer_id"],inplace=True)
ii outlier
Q1=Customer_Detail.quantile(0.25)
Q3=Customer_Policy.quantile(0.75)
print(Q1)
Ans:
Customer_id 95269.5 Age 25.0 Driving Licence Present 1.0 Region Code 15.0 Previously Insured 0.0 Name: 0.25, dtype: float64
print(Q3)
Ans:
Customer_id 285818.75 Annual Premium(in Rs) 39401.75 Sales Channel code 152.00 Vintage 227.00 Response 0.00 Name: 0.75, dtype: float64
IQR=Q3-Q1
lower=Q1-(1.5*IQR)
upper=Q3+(1.5*IQR)
Customer_Detail[(Customer_Detail<lower) | (Customer_Detail>upper)].sum()
Customer_Policy[(Customer_Policy<lower) | (Customer_Policy>upper)].sum()
Customer_Detail.describe()
| Customer_id | Age | Driving Licence Present | Region Code | Previously Insured | |
|---|---|---|---|---|---|
| count | 380723.000000 | 380357.000000 | 380331.000000 | 380723.000000 | 380342.000000 |
| mean | 190548.776244 | 38.822788 | 0.997868 | 26.391090 | 0.458259 |
| std | 110016.805160 | 15.512284 | 0.046128 | 13.223772 | 0.498255 |
| min | 1.000000 | 20.000000 | 0.000000 | 0.000000 | 0.000000 |
| 25% | 95269.500000 | 25.000000 | 1.000000 | 15.000000 | 0.000000 |
| 50% | 190543.000000 | 36.000000 | 1.000000 | 28.000000 | 0.000000 |
| 75% | 285822.500000 | 49.000000 | 1.000000 | 35.000000 | 1.000000 |
| max | 381109.000000 | 85.000000 | 1.000000 | 52.000000 | 1.000000 |
Customer_Policy.describe()
| Customer_id | Annual Premium(in Rs) | Sales Channel code | Vintage | Response | |
|---|---|---|---|---|---|
| count | 380722.000000 | 380378.000000 | 380322.000000 | 380334.000000 | 380361.000000 |
| mean | 190547.491663 | 30563.999774 | 112.036687 | 154.347192 | 0.122526 |
| std | 110013.824148 | 17197.918886 | 54.205529 | 83.670742 | 0.327892 |
| min | 1.000000 | 2630.000000 | 1.000000 | 10.000000 | 0.000000 |
| 25% | 95276.250000 | 24407.000000 | 29.000000 | 82.000000 | 0.000000 |
| 50% | 190536.500000 | 31667.000000 | 133.000000 | 154.000000 | 0.000000 |
| 75% | 285818.750000 | 39401.750000 | 152.000000 | 227.000000 | 0.000000 |
| max | 381109.000000 | 540165.000000 | 163.000000 | 299.000000 | 1.000000 |
Customer_Policy['Annual Premium(in Rs)']=Customer_Policy['Annual Premium(in Rs)'].astype('float')
Q1=Customer_Policy[['Annual Premium(in Rs)']].quantile(0.25)
Q2=Customer_Policy[['Annual Premium(in Rs)']].quantile(0.75)
((Customer_Policy[['Annual Premium(in Rs)']]<lower) | (Customer_Policy[['Annual Premium(in Rs)']]>upper)).sum
Customer_Policy['Response']=Customer_Policy['Response'].astype('float')
Q1=Customer_Policy[['Response']].quantile(0.25)
Q2=Customer_Policy[['Response']].quantile(0.75)
((Customer_Policy[['Response']]<lower)) | (Customer_Policy[['Response']]>upper).sum()
iii WhiteSpaces
Customer_Detail.apply(lambda x:x.str.strip() if x.dtype=="object" else x)
| Customer_id | Gender | Age | Driving Licence Present | Region Code | Previously Insured | Vehicle age | Vehicle Damage | |
|---|---|---|---|---|---|---|---|---|
| 0 | 1.0 | Male | 44.0 | 1.0 | 28.0 | 0.0 | > 2 Years | Yes |
| 1 | 2.0 | Male | 76.0 | 1.0 | 3.0 | 0.0 | 1-2 Year | No |
| 2 | 3.0 | Male | 47.0 | 1.0 | 28.0 | 0.0 | > 2 Years | Yes |
| 3 | 4.0 | Male | 21.0 | 1.0 | 11.0 | 1.0 | < 1 Year | No |
| 4 | 5.0 | Female | 29.0 | 1.0 | 41.0 | 1.0 | < 1 Year | No |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | Male | 74.0 | 1.0 | 26.0 | 1.0 | 1-2 Year | No |
| 381105 | 381106.0 | Male | 30.0 | 1.0 | 37.0 | 1.0 | < 1 Year | No |
| 381106 | 381107.0 | Male | 21.0 | 1.0 | 30.0 | 1.0 | < 1 Year | No |
| 381107 | 381108.0 | Female | 68.0 | 1.0 | 14.0 | 0.0 | > 2 Years | Yes |
| 381108 | 381109.0 | Male | 46.0 | 1.0 | 29.0 | 0.0 | 1-2 Year | No |
380723 rows × 8 columns
Customer_Policy.apply(lambda x: x.str.strip() if x.dtype=="object" else x)
| Customer_id | Annual Premium(in Rs) | Sales Channel code | Vintage | Response | |
|---|---|---|---|---|---|
| 0 | 1.0 | 40454.0 | 26.0 | 217.0 | 1.0 |
| 1 | 2.0 | 33536.0 | 26.0 | 183.0 | 0.0 |
| 2 | 3.0 | 38294.0 | 26.0 | 27.0 | 1.0 |
| 3 | 4.0 | 28619.0 | 152.0 | 203.0 | 0.0 |
| 4 | 5.0 | 27496.0 | 152.0 | 39.0 | 0.0 |
| ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | 30170.0 | 26.0 | 88.0 | 0.0 |
| 381105 | 381106.0 | 40016.0 | 152.0 | 131.0 | 0.0 |
| 381106 | 381107.0 | 35118.0 | 160.0 | 161.0 | 0.0 |
| 381107 | 381108.0 | 44617.0 | 124.0 | 74.0 | 0.0 |
| 381108 | 381109.0 | 41777.0 | 26.0 | 237.0 | 0.0 |
380722 rows × 5 columns
iv Case correction
Customer_Detail.apply(lambda x:x.astype(str).str.upper())
Customer_Detail
Ans:
| Customer_id | Gender | Age | Driving Licence Present | Region Code | Previously Insured | Vehicle age | Vehicle Damage | |
|---|---|---|---|---|---|---|---|---|
| 0 | 1.0 | Male | 44.0 | 1.0 | 28.0 | 0.0 | > 2 Years | Yes |
| 1 | 2.0 | Male | 76.0 | 1.0 | 3.0 | 0.0 | 1-2 Year | No |
| 2 | 3.0 | Male | 47.0 | 1.0 | 28.0 | 0.0 | > 2 Years | Yes |
| 3 | 4.0 | Male | 21.0 | 1.0 | 11.0 | 1.0 | < 1 Year | No |
| 4 | 5.0 | Female | 29.0 | 1.0 | 41.0 | 1.0 | < 1 Year | No |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | Male | 74.0 | 1.0 | 26.0 | 1.0 | 1-2 Year | No |
| 381105 | 381106.0 | Male | 30.0 | 1.0 | 37.0 | 1.0 | < 1 Year | No |
| 381106 | 381107.0 | Male | 21.0 | 1.0 | 30.0 | 1.0 | < 1 Year | No |
| 381107 | 381108.0 | Female | 68.0 | 1.0 | 14.0 | 0.0 | > 2 Years | Yes |
| 381108 | 381109.0 | Male | 46.0 | 1.0 | 29.0 | 0.0 | 1-2 Year | No |
380723 rows × 8 columns
convert nominal data into dummies
Customer_Detail2=pd.get_dummies(Customer_Detail)
Customer_Detail2
| Customer_id | Age | Driving Licence Present | Region Code | Previously Insured | Gender_Female | Gender_Male | Vehicle age_1-2 Year | Vehicle age_< 1 Year | Vehicle age_> 2 Years | Vehicle Damage_No | Vehicle Damage_Yes | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1.0 | 44.0 | 1.0 | 28.0 | 0.0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 |
| 1 | 2.0 | 76.0 | 1.0 | 3.0 | 0.0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
| 2 | 3.0 | 47.0 | 1.0 | 28.0 | 0.0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 |
| 3 | 4.0 | 21.0 | 1.0 | 11.0 | 1.0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
| 4 | 5.0 | 29.0 | 1.0 | 41.0 | 1.0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | 74.0 | 1.0 | 26.0 | 1.0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
| 381105 | 381106.0 | 30.0 | 1.0 | 37.0 | 1.0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
| 381106 | 381107.0 | 21.0 | 1.0 | 30.0 | 1.0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
| 381107 | 381108.0 | 68.0 | 1.0 | 14.0 | 0.0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 |
| 381108 | 381109.0 | 46.0 | 1.0 | 29.0 | 0.0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
380723 rows × 12 columns
Customer_Policy2=pd.get_dummies(Customer_Policy)
Customer_Policy2
| Customer_id | Annual Premium(in Rs) | Sales Channel code | Vintage | Response | |
|---|---|---|---|---|---|
| 0 | 1.0 | 40454.0 | 26.0 | 217.0 | 1.0 |
| 1 | 2.0 | 33536.0 | 26.0 | 183.0 | 0.0 |
| 2 | 3.0 | 38294.0 | 26.0 | 27.0 | 1.0 |
| 3 | 4.0 | 28619.0 | 152.0 | 203.0 | 0.0 |
| 4 | 5.0 | 27496.0 | 152.0 | 39.0 | 0.0 |
| ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | 30170.0 | 26.0 | 88.0 | 0.0 |
| 381105 | 381106.0 | 40016.0 | 152.0 | 131.0 | 0.0 |
| 381106 | 381107.0 | 35118.0 | 160.0 | 161.0 | 0.0 |
| 381107 | 381108.0 | 44617.0 | 124.0 | 74.0 | 0.0 |
| 381108 | 381109.0 | 41777.0 | 26.0 | 237.0 | 0.0 |
380722 rows × 5 columns
Drop duplicate
Customer_Detail2.drop_duplicates()
| Customer_id | Age | Driving Licence Present | Region Code | Previously Insured | Gender_Female | Gender_Male | Vehicle age_1-2 Year | Vehicle age_< 1 Year | Vehicle age_> 2 Years | Vehicle Damage_No | Vehicle Damage_Yes | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1.0 | 44.0 | 1.0 | 28.0 | 0.0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 |
| 1 | 2.0 | 76.0 | 1.0 | 3.0 | 0.0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
| 2 | 3.0 | 47.0 | 1.0 | 28.0 | 0.0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 |
| 3 | 4.0 | 21.0 | 1.0 | 11.0 | 1.0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
| 4 | 5.0 | 29.0 | 1.0 | 41.0 | 1.0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | 74.0 | 1.0 | 26.0 | 1.0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
| 381105 | 381106.0 | 30.0 | 1.0 | 37.0 | 1.0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
| 381106 | 381107.0 | 21.0 | 1.0 | 30.0 | 1.0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
| 381107 | 381108.0 | 68.0 | 1.0 | 14.0 | 0.0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 |
| 381108 | 381109.0 | 46.0 | 1.0 | 29.0 | 0.0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
380723 rows × 12 columns
| Customer_id | Annual Premium(in Rs) | Sales Channel code | Vintage | Response | |
|---|---|---|---|---|---|
| 0 | 1.0 | 40454.0 | 26.0 | 217.0 | 1.0 |
| 1 | 2.0 | 33536.0 | 26.0 | 183.0 | 0.0 |
| 2 | 3.0 | 38294.0 | 26.0 | 27.0 | 1.0 |
| 3 | 4.0 | 28619.0 | 152.0 | 203.0 | 0.0 |
| 4 | 5.0 | 27496.0 | 152.0 | 39.0 | 0.0 |
| ... | ... | ... | ... | ... | ... |
| 381104 | 381105.0 | 30170.0 | 26.0 | 88.0 | 0.0 |
| 381105 | 381106.0 | 40016.0 | 152.0 | 131.0 | 0.0 |
| 381106 | 381107.0 | 35118.0 | 160.0 | 161.0 | 0.0 |
| 381107 | 381108.0 | 44617.0 | 124.0 | 74.0 | 0.0 |
| 381108 | 381109.0 | 41777.0 | 26.0 | 237.0 | 0.0 |
380722 rows × 5 columns
3.Question
Master_Table=Customer_Detail2.merge(Customer_Policy2,on=["Customer_id"])
Master_Table
| Customer_id | Age | Driving Licence Present | Region Code | Previously Insured | Gender_Female | Gender_Male | Vehicle age_1-2 Year | Vehicle age_< 1 Year | Vehicle age_> 2 Years | Vehicle Damage_No | Vehicle Damage_Yes | Annual Premium(in Rs) | Sales Channel code | Vintage | Response | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1.0 | 44.0 | 1.0 | 28.0 | 0.0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 40454.0 | 26.0 | 217.0 | 1.0 |
| 1 | 2.0 | 76.0 | 1.0 | 3.0 | 0.0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 33536.0 | 26.0 | 183.0 | 0.0 |
| 2 | 3.0 | 47.0 | 1.0 | 28.0 | 0.0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 38294.0 | 26.0 | 27.0 | 1.0 |
| 3 | 4.0 | 21.0 | 1.0 | 11.0 | 1.0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 28619.0 | 152.0 | 203.0 | 0.0 |
| 4 | 5.0 | 29.0 | 1.0 | 41.0 | 1.0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 27496.0 | 152.0 | 39.0 | 0.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 380331 | 381105.0 | 74.0 | 1.0 | 26.0 | 1.0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 30170.0 | 26.0 | 88.0 | 0.0 |
| 380332 | 381106.0 | 30.0 | 1.0 | 37.0 | 1.0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 40016.0 | 152.0 | 131.0 | 0.0 |
| 380333 | 381107.0 | 21.0 | 1.0 | 30.0 | 1.0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 35118.0 | 160.0 | 161.0 | 0.0 |
| 380334 | 381108.0 | 68.0 | 1.0 | 14.0 | 0.0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 44617.0 | 124.0 | 74.0 | 0.0 |
| 380335 | 381109.0 | 46.0 | 1.0 | 29.0 | 0.0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 41777.0 | 26.0 | 237.0 | 0.0 |
380336 rows × 16 columns
4.Question
Master_Table.groupby(['Gender_Male']).mean()['Annual Premium(in Rs)']
Ans:
Gender_Male 0 30491.959528 1 30623.670581 Name: Annual Premium(in Rs), dtype: float64
Master_Table.groupby(['Gender_Female']).mean()['Annual Premium(in Rs)']
Ans:
Gender_Female 0 30623.670581 1 30491.959528 Name: Annual Premium(in Rs), dtype: float64
Master_Table.groupby(['Age']).mean()['Annual Premium(in Rs)']
Age
20.0 26920.517153
21.0 30564.476130
22.0 30824.039423
23.0 30688.699065
24.0 31184.306152
...
81.0 31201.571429
82.0 37705.379310
83.0 31012.727273
84.0 35440.818182
85.0 29792.363636
Name: Annual Premium(in Rs), Length: 66, dtype: float64
Master_Table['Gender_Male'].value_counts()
1 205851 0 174485 Name: Gender_Male, dtype: int64
Master_Table['Gender_Female'].value_counts()
0 205851 1 174485 Name: Gender_Female, dtype: int64
Master_Table.groupby(['Vehicle age_1-2 Year']).mean()['Annual Premium(in Rs)']
Vehicle age_1-2 Year 0 30606.151077 1 30524.590052 Name: Annual Premium(in Rs), dtype: float64
Master_Table.groupby(['Vehicle age_< 1 Year']).mean()['Annual Premium(in Rs)']
Vehicle age_< 1 Year 0 30903.960198 1 30115.361397 Name: Annual Premium(in Rs), dtype: float64
Master_Table.groupby(['Vehicle age_> 2 Years']).mean()['Annual Premium(in Rs)']
Ans:
Vehicle age_> 2 Years 0 30340.043557 1 35661.355606 Name: Annual Premium(in Rs), dtype: float64
5.Question
import numpy as np
Master_Table.corr()
| Customer_id | Age | Driving Licence Present | Region Code | Previously Insured | Gender_Female | Gender_Male | Vehicle age_1-2 Year | Vehicle age_< 1 Year | Vehicle age_> 2 Years | Vehicle Damage_No | Vehicle Damage_Yes | Annual Premium(in Rs) | Sales Channel code | Vintage | Response | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Customer_id | 1.000000 | 0.001669 | -0.000475 | -0.000727 | 0.002425 | -0.001153 | 0.001153 | 0.001489 | -0.001337 | -0.000406 | 0.001523 | -0.001436 | 0.003087 | -0.002922 | -0.000603 | -0.001349 |
| Age | 0.001669 | 1.000000 | -0.079770 | 0.042524 | -0.254664 | -0.145127 | 0.145127 | 0.692334 | -0.787152 | 0.220577 | -0.267226 | 0.267260 | 0.067778 | -0.577861 | -0.001218 | 0.111186 |
| Driving Licence Present | -0.000475 | -0.079770 | 1.000000 | -0.001062 | 0.014959 | 0.018318 | -0.018318 | -0.037506 | 0.040221 | -0.005968 | 0.016550 | -0.016649 | -0.012027 | 0.043864 | -0.000851 | 0.010303 |
| Region Code | -0.000727 | 0.042524 | -0.001062 | 1.000000 | -0.024604 | -0.000503 | 0.000503 | 0.037779 | -0.043952 | 0.014508 | -0.027960 | 0.028062 | -0.010700 | -0.042414 | -0.002752 | 0.010471 |
| Previously Insured | 0.002425 | -0.254664 | 0.014959 | -0.024604 | 1.000000 | 0.081909 | -0.081909 | -0.278771 | 0.358379 | -0.191216 | 0.823324 | -0.823328 | 0.004440 | 0.219312 | 0.002397 | -0.341191 |
| Gender_Female | -0.001153 | -0.145127 | 0.018318 | -0.000503 | 0.081909 | 1.000000 | -1.000000 | -0.147153 | 0.165755 | -0.043059 | 0.091462 | -0.091447 | -0.003818 | 0.110926 | 0.002450 | -0.052542 |
| Gender_Male | 0.001153 | 0.145127 | -0.018318 | 0.000503 | -0.081909 | -1.000000 | 1.000000 | 0.147153 | -0.165755 | 0.043059 | -0.091462 | 0.091447 | 0.003818 | -0.110926 | -0.002450 | 0.052542 |
| Vehicle age_1-2 Year | 0.001489 | 0.692334 | -0.037506 | 0.037779 | -0.278771 | -0.147153 | 0.147153 | 1.000000 | -0.918807 | -0.220431 | -0.284118 | 0.284076 | -0.002369 | -0.507877 | -0.002672 | 0.164036 |
| Vehicle age_< 1 Year | -0.001337 | -0.787152 | 0.040221 | -0.043952 | 0.358379 | 0.165755 | -0.165755 | -0.918807 | 1.000000 | -0.182465 | 0.369986 | -0.369995 | -0.022725 | 0.571054 | 0.002437 | -0.209615 |
| Vehicle age_> 2 Years | -0.000406 | 0.220577 | -0.005968 | 0.014508 | -0.191216 | -0.043059 | 0.043059 | -0.220431 | -0.182465 | 1.000000 | -0.206575 | 0.206703 | 0.062055 | -0.146110 | 0.000633 | 0.109413 |
| Vehicle Damage_No | 0.001523 | -0.267226 | 0.016550 | -0.027960 | 0.823324 | 0.091462 | -0.091462 | -0.284118 | 0.369986 | -0.206575 | 1.000000 | -0.997867 | -0.009196 | 0.223998 | 0.001908 | -0.354015 |
| Vehicle Damage_Yes | -0.001436 | 0.267260 | -0.016649 | 0.028062 | -0.823328 | -0.091447 | 0.091447 | 0.284076 | -0.369995 | 0.206703 | -0.997867 | 1.000000 | 0.009259 | -0.224008 | -0.001960 | 0.353969 |
| Annual Premium(in Rs) | 0.003087 | 0.067778 | -0.012027 | -0.010700 | 0.004440 | -0.003818 | 0.003818 | -0.002369 | -0.022725 | 0.062055 | -0.009196 | 0.009259 | 1.000000 | -0.113441 | -0.000671 | 0.022295 |
| Sales Channel code | -0.002922 | -0.577861 | 0.043864 | -0.042414 | 0.219312 | 0.110926 | -0.110926 | -0.507877 | 0.571054 | -0.146110 | 0.223998 | -0.224008 | -0.113441 | 1.000000 | -0.000151 | -0.139071 |
| Vintage | -0.000603 | -0.001218 | -0.000851 | -0.002752 | 0.002397 | 0.002450 | -0.002450 | -0.002672 | 0.002437 | 0.000633 | 0.001908 | -0.001960 | -0.000671 | -0.000151 | 1.000000 | -0.001094 |
| Response | -0.001349 | 0.111186 | 0.010303 | 0.010471 | -0.341191 | -0.052542 | 0.052542 | 0.164036 | -0.209615 | 0. |