Credit Limit
Introduction ๐
Credit cards are sometimes a good tool. However, they are constrained in their ability to spend. limitations on credit, specifically. The maximum amount you are permitted to charge on a revolving credit account, such as a credit card, is known as the credit limit. The value of each transaction made with your card deducts from your available credit. Your remaining number is referred to as your available credit. Now credit cards are used to find fraud.
Customer Churn and Credit Card Usage Analysis
In the project, we will perform a series of analyses on the dataset to understand a bank's customer churn and analyse credit card usage.
Importing Necessary Packages ๐ฆ
!pip install phik --quiet
!pip install spacy --quiet
!pip install mlxtend --quiet
print("Installed")
import os
import json
import math
import phik
import spacy
import numpy as np
import pandas as pd
import seaborn as sns
from scipy import stats
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.model_selection import GridSearchCV
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, confusion_matrix
import plotly.express as px
Data Preprocessing ๐งน
# Import the Credit_Limit.csv file
data = pd.read_csv('Credit_Limit.csv')
data.info()
Handling Missing Values
# Check the first few rows of the dataset
data.head()
# Check the shape of the dataset
data.shape
# Check for missing values
data.isnull().sum()
# Check data types of columns
data.dtypes
The code block above performs the following operations:
-
Importing necessary packages: The code imports the required packages such as numpy, pandas, statsmodels, pingouin, seaborn, and matplotlib.pyplot.
-
Reading the dataset: The code reads the 'Credit_Limit.csv' file and stores it in the 'data' dataframe.
-
Checking the dataset: The code checks the first few rows of the dataset using the 'head()' function and displays the shape of the dataset using the 'shape' attribute. It also checks for missing values in the dataset using the 'isnull().sum()' function and displays the data types of the columns using the 'dtypes' attribute.
-
Data cleaning and validation analysis: The code performs data cleaning and validation analysis, but the specific code for this analysis is not provided in the given code block.
Overall, the code block imports necessary packages, reads the dataset, checks the dataset for initial exploration, and prepares for data cleaning and validation analysis.
# Perform data cleaning and validation analysis
# Drop any rows with missing values
data_cleaned = data.dropna()
# Check the shape of the cleaned dataset
data_cleaned.shape
# Convert the "Attrition_Flag" column to a categorical data type
data_cleaned["Attrition_Flag"] = data_cleaned["Attrition_Flag"].astype("category")
# Convert the "Gender" column to a categorical data type
data_cleaned["Gender"] = data_cleaned["Gender"].astype("category")
# Convert the "Education_Level" column to a categorical data type
data_cleaned["Education_Level"] = data_cleaned["Education_Level"].astype("category")
# Convert the "Marital_Status" column to a categorical data type
data_cleaned["Marital_Status"] = data_cleaned["Marital_Status"].astype("category")
# Convert the "Income_Category" column to a categorical data type
data_cleaned["Income_Category"] = data_cleaned["Income_Category"].astype("category")
# Convert the "Card_Category" column to a categorical data type
data_cleaned["Card_Category"] = data_cleaned["Card_Category"].astype("category")
# Check the data types of columns after conversion
data_cleaned.dtypes
Handling Duplicate Records
# Add the median of a column to missing values
data_cleaned.fillna(data_cleaned.median(), inplace=True)
# Add the mode value of a column to missing values
data_cleaned.fillna(data_cleaned.mode().iloc[0], inplace=True)
# Adding random values to missing values
data_cleaned.fillna(np.random.choice(data_cleaned['Avg_Open_To_Buy'].dropna()), inplace=True)
โ
โ