<jupyter_start><jupyter_text>Questions that need to be answered:1) Whom to approve or reject for the credit card?2) How much credit limit to give if approved?Information on Columns in Dataset -  User Information- user_id- gender- date_of_birth- workclass- education_level- education_num: education_level as a continuous variable. Eg, Masters(14) >Bachelors(13)- marital_status- occupation- relationship: current relationship status- capital_gain: capital gain made in the last financial year in USD through investments- capital_loss: capital loss in the last financial year in USD through investments- Hours_per_week: Number of hours worked by the person per week.- approved: Whether customer was approved for the Credit Card.- address- Email CIBIL Information- Inquiry_purpose_code: Purpose of enquiry from the bureau- Institute_type: Type of institute that requested the bureau- Account_type: Type of account of the customer for requesting from the bureau- Asset_class_cd: Current state of the assets of the customer- Asset_code: Type of ownership of the customer- Portfolio_type: Type of portfolio<jupyter_code># !pip3 install lux pyforest scipy sklearn lazypredict lux-api
# !pip3 uninstall lux lux-api -y
!pip3 install scikit-learn==0.23
# !pip install pandas-profiling[notebook]
%load_ext autoreload
%autoreload 2
import pyforest
import warnings
warnings.filterwarnings("ignore")
from sklearn import metrics
from sklearn.metrics import accuracy_score
# import lux
import pandas as pd
from pandas_profiling import ProfileReport
import numpy as np
from datetime import datetime, date
import lazypredict
from lazypredict.Supervised import LazyClassifier
all_data = pd.read_csv('./payments_bank_digicard.csv')
print(all_data.dtypes)
target_variable = 'approved' 
# all_data.groupby("gender")["approved"].mean()
# gender = {" Male": 1," Female": 2}
# all_data.gender = [gender[item] for item in all_data.gender]
# # print(all_data.dtypes)
# all_data.groupby("gender")["approved"].mean()
#Feature Engineering
def age(date_of_birth):
    date_of_b = datetime.strptime(date_of_birth, "%Y-%m-%d").date()
    today = date.today()
    return today.year - date_of_b.year - ((today.month, today.day) < (date_of_b.month, date_of_b.day))

all_data['Age'] = all_data['date_of_birth'].apply(age)
all_data['gender'] = all_data['gender'].apply(lambda x: 1 if x == ' Male' else 2)

# all_data["approved"] = all_data["approved"].astype(np.float64)
# all_data[["approved"]] = all_data[["approved"]].apply(pd.to_numeric)
all_data.corrwith(all_data[target_variable])
profile = ProfileReport(all_data, title="Pandas Profiling Report", html={'style':{'full_width':True}}, dark_mode = True)
profile.to_widgets()
# profile.to_notebook_iframe()
import seaborn as sns
sns.pairplot(all_data, hue = target_variable, diag_kind="hist", corner=True)
import matplotlib.pyplot as plt

numeric_columns = all_data.select_dtypes(include=[np.number]).columns.tolist()
numeric_columns.remove(target_variable)

for column_name in numeric_columns:
    plt.figure()
    df = all_data.groupby(column_name)[target_variable].mean().reset_index()
    plt.plot(df[column_name],df[target_variable])
    plt.title("Interaction between " + str(column_name) + " and Approval Rate")
    plt.xlabel(column_name)
    plt.ylabel("Approval Rate")
    plt.show()

df = all_data.groupby('asset_code')[target_variable].mean().reset_index()
df
df = {228 : '<NAME> (Shishu/Kishor/Tarun)',227 : '<NAME> (Over Draft)',226 : 'Loan on Credit Card',225 : 'Kisan Credit Card',224 : 'Corporate Credit Card',213 : 'Tractor Loan',223 : 'Construction Equipment Loan',222 : 'Used Car Loan',221 : 'Secured Credit Card',220 : 'Loan, Staff',196 : 'Business Loan Against Bank Deposits',175 : 'Non-Funded Credit Facility, Priority Sector - Others',200 : 'Non-Funded Credit Facility, Priority Sector - Agriculture',199 : 'Non-Funded Credit Facility, Priority Sector - Small Buisiness',198 : 'Non-Funded Credit Facility, General',197 : 'Business Loan - Priority Sector - Others',179 : 'Business Loan - Priority Sector - Agriculture',178 : 'Business Loan - Priority Sector - Small Business',177 : 'Business Loan - General',176 : 'Microfinance, Other',170 : 'Microfinance, Housing',168 : 'Microfinance, Personal',167 : 'Microfinance, Business',216 : 'Service, Telco - Landline',215 : 'Service, Telco - Broadband',217 : 'Service, Telco - Wireless',172 : 'Instalment Loan, Commercial Vehicle',214 : 'Credit Card, Fleet',184 : 'Loan Against Bank Deposits',181 : 'Credit Facility, Non-Funded',173 : 'Instalment Loan, Two-Wheeler',121 : 'Banking, Overdraft',219 : 'Leasing, Other',5 : 'Credit Card',187 : 'Loan to Professional',130 : 'Loan, Student',191 : 'Loan, Gold',189 : 'Loan, Consumer',123 : 'Loan, Personal Cash',185 : 'Loan Against Shares/Securities',195 : 'Loan, Property',58 : 'Instalment Loan, Mortgage',47 : 'Instalment Loan, Automobile',999 : 'Other'}

all_data["account_type_"] = [df.get(item, str(item) + " Not Given") for item in all_data.account_type]
df = all_data.groupby('account_type_')[target_variable].mean().reset_index()
df.sort_values(by=['approved'], ascending=False)
df = {99 : 'Others',19 : 'Credit Review',18 : 'Consumer loan',17 : 'Working capital loan',16 : 'Two/Three wheeler loan',15 : 'Telecom',14 : 'Property Loan',13 : 'Personal Loan',12 : 'Non-funded credit facility',11 : 'Microfinance',10 : 'Load Against Collateral',9 : 'Leasing',8 : 'Education Load',7 : 'Credit Card',6 : 'Consumer Search',5 : 'Construction Euipment Loans',4 : 'Commercial Vehicle Loans',3 : 'Business Loan',2 : 'Auto Loan',1 : 'Agriculture Loan',}

all_data["inquiry"] = [df.get(item, "Not Given") for item in all_data.inquiry_purpose_code]
df = all_data.groupby('inquiry')[target_variable].mean().reset_index()
df.sort_values(by=['approved'], ascending=False)
df = {'X' : 'Leasing','S' : 'Service Credit','R' : 'Revolving Credit','M' : 'Mortgage','L' : 'Loans','I' : 'Installment Credit','F' : 'Microfinance','B' : 'Banking'}

all_data["portfolio_type_"] = [df.get(item, "Not Given") for item in all_data.inquiry_purpose_code]
df = all_data.groupby('portfolio_type_')[target_variable].mean().reset_index()
df.sort_values(by=['approved'], ascending=False)
train = all_data[all_data.select_dtypes(include=[np.number]).columns.tolist()]

X = train.drop(target_variable, axis=1)
y = train[target_variable]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size =0.6, random_state=42)
print(X_train.shape, X_test.shape, y_train.shape, y_test.shape)
clf = LazyClassifier(verbose=0,ignore_warnings=True, custom_metric=None)
models, predictions = clf.fit(X_train, X_test, y_train, y_test)
models

Currently Approved Loans
# Salary

Cost = DefaultProbability * Loan Size


Present Value of All Payments - Initial Cost > 4%

Amount Disbursed
10%<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13574261789334507, 'fraction_numerical': 0.027471720287938886, 'mean_word_length': 6.312567132116004, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '34812', 'license': 'MIT', 'n_tokens_mistral': 2389, 'n_tokens_neox': 2151, 'n_words': 587, 'path': 'Payment Option Approval.ipynb', 'repo_name': 'traveller-scientist/credit-card-approval', 'size': '6823'}