Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import joblib | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
from imblearn.pipeline import Pipeline as imbpipe | |
APP_ICON_URL = "credit-card.png" | |
# Setup web page | |
st.set_page_config( | |
page_title="CREDIT CARD APPROVAL APP", | |
page_icon=APP_ICON_URL, | |
layout="wide", | |
) | |
st.markdown(""" | |
<style type="text/css"> | |
blockquote { | |
margin: 1em 0px 1em -1px; | |
padding: 0px 0px 0px 1.2em; | |
font-size: 20px; | |
border-left: 5px solid rgb(230, 234, 241); | |
# background-color: rgb(129, 164, 182); | |
} | |
blockquote p { | |
font-size: 30px; | |
color: #FFFFFF; | |
} | |
[data-testid=stSidebar] { | |
background-color: rgb(129, 164, 182); | |
color: #FFFFFF; | |
} | |
[aria-selected="true"] { | |
color: #000000; | |
} | |
</style> | |
""", unsafe_allow_html=True) | |
with st.container(): | |
col1,col2,_,_ = st.columns([1,14,1,1],gap="large") | |
with col1: | |
st.image(APP_ICON_URL, width=80) | |
with col2: | |
st.header(f"Credit Card Prediction App") | |
st.caption(f"App developed by [Alsello](https://github.com/AlselloDM)") | |
st.write(f"This application predicts whether your credit card application is **Approved** or **Not Approved**.") | |
st.markdown("___") | |
def fetch_data(): | |
df = pd.read_csv('Application_Data.csv') | |
return df | |
df = fetch_data() | |
st.sidebar.title("Approval App ๐") | |
st.sidebar.write('Please choose the page') | |
#make two pages for EDA and Prediction | |
page = st.sidebar.selectbox('Choose a page', ['EDA', 'Approval Form๐']) | |
if page == 'EDA': | |
st.subheader('Approval Status') | |
st.write('Approval Status is the target variable with value of 0 (not approved) and 1 (approved).') | |
sns.countplot(x='Status', data=df) | |
plt.xticks([0, 1]) | |
st.pyplot(plt) | |
st.write('The data is imbalanced.') | |
st.subheader('Correlation between Years Employed and Total Income') | |
st.write('Years Employed and Total Income usually has correlation.') | |
plt.figure(figsize=(8, 6)) | |
plt.scatter(df['Years_of_Working'], df['Total_Income'], alpha=0.5) | |
plt.xlabel('Years Employed') | |
plt.ylabel('Total Income') | |
plt.title('Correlation between Years Employed and Total Income') | |
st.pyplot(plt) | |
st.write('We can see that the longer the Years Employed, it does not increase the Total Income.') | |
st.write('') | |
st.subheader('Correlation of the Features') | |
st.write("One of the many Feature Selection Methods is Pearson's Heatmap Correlation Method.") | |
plt.figure(figsize=(15,15)) | |
sns.heatmap(df.corr(), annot=True) | |
plt.show() | |
st.pyplot(plt) | |
st.write("There are no good enough features to choose so I used another method called 'SelectKBest'.") | |
st.write('') | |
else: | |
st.sidebar.title("Applicant's Profile") | |
st.sidebar.write('Please enter the needed profile here') | |
def user_input_features(): | |
# Applicant ID | |
id = st.number_input("ID of the applicant (7 Digits of your ID)") | |
# Male or Female | |
sex = st.selectbox('Gender',('M','F')) | |
# Car Ownership | |
car_ownership = st.selectbox('Car Ownership (1 : Yes | 0 : No)',(1,0)) | |
# Property Ownership | |
property_ownership = st.selectbox('Property Ownership (1 : Yes | 0 : No)',(1,0)) | |
# Total Children | |
total_children = st.slider('Number of Children?',0,5,0) | |
# Income | |
income = st.number_input('Yearly Income',27000,1575000) | |
# Income Type | |
income_type = st.selectbox("Employment Status",('Working','Commercial associate ','State servant','Pensioner','Student')) | |
# Education Level | |
education = st.selectbox("Education Level",('Lower secondary','Secondary / secondary special','Incomplete higher ','Higher education ','Academic degree')) | |
# Marriage Status | |
marriage_status = st.selectbox("Marriage Status",('Single / not married','Married','Civil marriage','Separated','Widow')) | |
# Residence | |
residence = st.selectbox('Residency',('House / apartment','With parents','Municipal apartment','Rented apartment','Office apartment','Co-op apartment')) | |
# Mobile Phone Ownership | |
mobile_phone = st.selectbox('Mobile Phone Ownership (1 : True | 0 : False)',(1,0)) | |
# Work Phone Ownership | |
work_phone = st.selectbox('Work Phone Ownership (1 : True | 0 : False)',(1,0)) | |
# Phone Ownership | |
phone = st.selectbox('Phone Ownership (1 : True | 0 : False)',(1,0)) | |
# Email Ownership | |
email = st.selectbox('Email Ownership (1 : True | 0 : False)',(1,0)) | |
# Job Title | |
job_title = st.selectbox('Job Title',('Laborers','Core staff','Sales staff','Managers','Drivers','High skill tech staff','Accountants','Medicine staff','Cooking staff','Security staff','Cleaning staff','Private service staff','Low-skill Laborers','Waiters/barmen staff','Secretaries','HR staff','Realty agents','IT staff')) | |
# Total Family Member | |
total_family = st.slider('Number of Family Member',1,7,1) | |
# Applicant Age | |
age = st.number_input("Age") | |
# Years of Working | |
years_of_working = st.number_input("Years of Work") | |
# Total Bad Debt | |
total_bad_debt = st.slider('Total of Bad Debt',0,49,0)\ | |
# Total Good Debt | |
total_good_debt = st.slider('Total of Good Debt',1,61,1) | |
data = {'Applicant_ID': id,'Applicant_Gender':sex,'Owned_Car':car_ownership, | |
'Owned_Realty':property_ownership,'Total_Children':total_children, | |
'Total_Income':income,'Income_Type':income_type, | |
'Education_Type':education,'Family_Status':marriage_status, | |
'Housing_Type':residence,'Owned_Mobile_Phone':mobile_phone,'Owned_Work_Phone':work_phone, | |
'Owned_Phone':phone,'Owned_Email':email,'Job_Title':job_title,'Total_Family_Members':total_family, | |
'Applicant_Age':age,'Years_of_Working':years_of_working, | |
'Total_Bad_Debt':total_bad_debt,'Total_Good_Debt':total_good_debt} | |
# | |
features = pd.DataFrame(data,index=[0]) | |
return features | |
input_df = user_input_features() | |
st.subheader('Applicant Data๐') | |
st.write(input_df) | |
load_model = joblib.load("model") | |
if st.button('Predict'): | |
try: | |
prediction = load_model.predict(input_df) | |
prediction_proba = load_model.predict_proba(input_df) | |
st.subheader('APPROVAL') | |
for i in range(len(prediction)): | |
if prediction[i] == 0: | |
st.error("This applicant is not **Approved**") | |
else: | |
st.success("This applicant is **Approved**") | |
st.subheader('Probability') | |
st.write("0 : No | 1 : Yes") | |
st.write(prediction_proba) | |
except ValueError: | |
st.header("Insufficient Applicant Data") |