Data Analysis

Code
# Import Libraries
from nbdev.showdoc import *
import pandas as pd
import numpy as np
from pandas_profiling import ProfileReport
from datetime import datetime
import plotly.express as px
import matplotlib.pyplot as plt
import seaborn as sns


import warnings
warnings.filterwarnings('ignore')
import re

# Load Dataset
df=pd.read_csv('clean_dataset.csv')
Code
del df['Unnamed: 0']
Code
df
Customer_ID Month Name Age Occupation Annual_Income Monthly_Inhand_Salary Num_Bank_Accounts Num_Credit_Card Interest_Rate ... Credit_Score Auto Loan Credit-Builder Loan Not Specified Personal Loan Payday Loan Mortgage Loan Home Equity Loan Debt Consolidation Loan Student Loan
0 CUS_0xd40 1 Aaron Maashoh 23 Scientist 19114.12 1824.843333 3 4 3 ... Good True True False True False False True False False
1 CUS_0xd40 4 Aaron Maashoh 23 Scientist 19114.12 1824.843333 3 4 3 ... Good True True False True False False True False False
2 CUS_0xd40 6 Aaron Maashoh 23 Scientist 19114.12 1824.843333 3 4 3 ... Good True True False True False False True False False
3 CUS_0xd40 7 Aaron Maashoh 23 Scientist 19114.12 1824.843333 3 4 3 ... Good True True False True False False True False False
4 CUS_0xd40 8 Aaron Maashoh 23 Scientist 19114.12 1824.843333 3 4 3 ... Standard True True False True False False True False False
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
63830 CUS_0xb80d 5 Alex Frewt 32 Developer 28796.82 2378.735000 6 6 21 ... Poor False False False True True False False False True
63831 CUS_0xb80d 6 Alex Frewt 32 Developer 28796.82 2378.735000 6 6 21 ... Standard False False False True True False False False True
63832 CUS_0xb80d 7 Alex Frewt 32 Developer 28796.82 2378.735000 6 6 21 ... Poor False False False True True False False False True
63833 CUS_0xb80d 8 Alex Frewt 32 Developer 28796.82 2378.735000 6 6 21 ... Poor False False False True True False False False True
63834 CUS_0x9d41 5 Rothackerz 38 Lawyer 41015.55 3152.962500 1194 4 4 ... Standard False False False False True False False False False

63835 rows × 35 columns

Credit Score Distribution

Code
creditscore=df.Credit_Score.value_counts().reset_index().rename(columns={'Credit_Score':'Count','index':'Credit_Score'})
Code
fig = px.pie(creditscore, values='Count', names='Credit_Score')
fig.update_traces(textinfo='value+percent')
fig.show()
Code
credit_score_num = {
    "Bad":0,
    "Standard":1,
    "Good":2
}
df['credit_score_num'] = df['Credit_Score'].map(credit_score_num)
Code
corr_plot=np.round(df.corr(),2)
mask=np.triu(np.ones_like(corr_plot, dtype=bool))
f, ax = plt.subplots(figsize=(11, 9))
sns.heatmap(corr_plot,mask=mask, 
            cmap='PiYG',
            # cmap='Greens',
            vmax=1, 
            vmin = -1,
            annot = True)
plt.title('Correlation Plot')
plt.show()

Higher the Monthly income, higher the credit score

Code
df_month_income=df.groupby(['Month','Credit_Score'])['Monthly_Inhand_Salary'].agg('mean').reset_index()
fig = px.line(df_month_income, x='Month', y="Monthly_Inhand_Salary", color='Credit_Score')
fig.show()

With increase in age, credit score will increase

Code
df_age_creditscore=df.groupby(['Credit_Score'])['Age'].agg('mean').reset_index()
fig = px.bar(df_age_creditscore, x='Credit_Score', y="Age", color='Credit_Score')
fig.update_layout(xaxis={'categoryorder':'total descending'})
fig.show()

Delay in payment will have negative impact on credit score

Code
delay_credit=df.groupby(['Month','Credit_Score'])['Delay_from_due_date'].agg('mean').reset_index()
fig = px.line(delay_credit, x='Month', y="Delay_from_due_date",color='Credit_Score' ) #, color='Category' , trendline="ols"
fig.update_layout(title_text='Impact of delayed payment on credit score', title_x=0.5)
fig.show()

Credit score of customers across occupation will not be same

Code
occu_credit=df.groupby(['Occupation','Credit_Score'])['Customer_ID'].nunique().reset_index()
fig = px.bar(occu_credit, x='Occupation', y="Customer_ID",color='Credit_Score' ) #, color='Category' , trendline="ols"
fig.update_layout(title_text='Impact of delayed payment on credit score', title_x=0.5,xaxis={'categoryorder':'total descending'})
fig.show()

Credit History Age has positive impact on credit score

Code
credithistage_credit=df.groupby(['Credit_Score'])['Credit_History_Age'].agg('mean').reset_index()
fig = px.bar(credithistage_credit, x='Credit_Score', y="Credit_History_Age",color='Credit_Score' ) #, color='Category' , trendline="ols"
fig.update_layout(title_text='Impact of delayed payment on credit score', title_x=0.5,xaxis={'categoryorder':'total descending'})
fig.show()