# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# **The notebook contains preprocessing of the data and visualization of few features of the dataset**

# +
# Import the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# %matplotlib inline
# -

#import and read dataset
dataset = pd.read_csv("credit_card_defaults.csv")

# recap of data
dataset.head()

#Stats of features/variables in dataset
dataset.info()

# stats of numerical variables
dataset.describe().transpose()

#Check for null values
dataset.isnull().sum()

# +
# Analyze the variables/features
# -

dataset["LIMIT_BAL"].describe()

dataset["SEX"].value_counts()

dataset["EDUCATION"].value_counts()

dataset["MARRIAGE"].value_counts()

dataset["AGE"].describe()

# +
# Analyze the repayment history
pay0 = dataset["PAY_0"].value_counts()
pay2 = dataset["PAY_2"].value_counts()
pay3 = dataset["PAY_3"].value_counts()
pay4 = dataset["PAY_4"].value_counts()
pay5 = dataset["PAY_5"].value_counts()
pay6 = dataset["PAY_6"].value_counts()

print("PAY0: \n",pay0,"\nPAY2: \n",pay2,"\nPAY3: \n",pay3,"\nPAY4: \n",pay4,"\nPAY5: \n",pay5,"\nPAY6: \n",pay6)
# -

# **Analysis of Variables using Visualization**

#Distribution of balance limit
dataset["LIMIT_BAL"].plot(kind='hist', color='green', bins=60)

dataset.groupby('default payment next month').size().plot(kind='bar', color='blue')
plt.xlabel('default payment next month')
plt.ylabel('count')

dataset['SEX'].value_counts().plot(kind='bar', color='orange')
plt.xlabel("Gender")
plt.ylabel("Count")

# +
# Count of Marriage levels
#By matplotlib
#dataset['MARRIAGE'].value_counts().plot(kind='bar', color='red')
#dataset.groupby('MARRIAGE').size().plot(kind='bar',color='purple')

#by Seaborn
sns.countplot(x='MARRIAGE', data=dataset, palette='BuGn_r')
# -

#default payment vs limit balance wrt gender
sns.barplot(x='default payment next month', y='LIMIT_BAL',hue='SEX',data=dataset,palette='Blues')

#Count of Education levels wrt deault payments
sns.countplot(x='EDUCATION', hue='default payment next month', data=dataset, palette='hls')

# marriage level vs default payment
sns.countplot(x='MARRIAGE', hue='default payment next month', data=dataset, palette='gist_rainbow_r')



StarcoderdataJupyterScriptsDedupFiltered