text_plain_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import scipy.stats as ss

import seaborn as sns

df = pd.read_csv('../input/travel insurance.csv')
df1 = df

df.fillna('Not Specified', inplace=True)

df.isnull().sum()

df_numerical = df._get_numeric_data()

df.loc[df['Duration'] < 0, 'Duration'] = 49.317

df.loc[df['Net Sales'] == 0.0, 'Commision (in value)'] = 0

def cramers_v(x, y):
    confusion_matrix = pd.crosstab(x, y)
    chi2 = ss.chi2_contingency(confusion_matrix)[0]
    n = confusion_matrix.sum().sum()
    phi2 = chi2 / n
    r, k = confusion_matrix.shape
    phi2corr = max(0, phi2 - (k - 1) * (r - 1) / (n - 1))
    rcorr = r - (r - 1) ** 2 / (n - 1)
    kcorr = k - (k - 1) ** 2 / (n - 1)
    return np.sqrt(phi2corr / min(kcorr - 1, rcorr - 1))

categorical = ['Agency', 'Agency Type', 'Distribution Channel', 'Product Name', 'Destination', 'Gender', 'Claim']
cramers = pd.DataFrame({i: [cramers_v(df[i], df[j]) for j in categorical] for i in categorical})
cramers['column'] = [i for i in categorical if i not in ['memberid']]
cramers.set_index('column', inplace=True)

test = [(df[df['Gender'] == 'Not Specified']['Claim'].value_counts() / len(df[df['Gender'] == 'Not Specified']['Claim']))[1], (df[df['Gender'] == 'M']['Claim'].value_counts() / len(df[df['Gender'] == 'M']['Claim']))[1], (df[df['Gender'] == 'F']['Claim'].value_counts() / len(df[df['Gender'] == 'F']['Claim']))[1]]
test

fig, axes=plt.subplots(1,3,figsize=(24,9))
sns.countplot(df[df['Gender']=='Not Specified']['Claim'],ax=axes[0])
axes[0].set(title='Distribution of claims for null gender')
axes[0].text(x=1,y=30000,s=f'% of 1 class: {round(test[0],2)}',fontsize=16,weight='bold',ha='center',va='bottom',color='navy')
sns.countplot(df[df['Gender']=='M']['Claim'],ax=axes[1])
axes[1].set(title='Distribution of claims for Male')
axes[1].text(x=1,y=6000,s=f'% of 1 class: {round(test[1],2)}',fontsize=16,weight='bold',ha='center',va='bottom',color='navy')
sns.countplot(df[df['Gender']=='F']['Claim'],ax=axes[2])
axes[2].set(title='Distribution of claims for Female')
axes[2].text(x=1,y=6000,s=f'% of 1 class: {round(test[2],2)}',fontsize=16,weight='bold',ha='center',va='bottom',color='navy')
plt.show()

sns.countplot(df['Claim'])