-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathloan_web_app.py
168 lines (140 loc) · 6.56 KB
/
loan_web_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 25 19:47:54 2021
@author: sagnik1511
"""
# Libraries
import streamlit as st
import pandas as pd
import base64
from PIL import Image
from sklearn.ensemble import RandomForestClassifier as rfc
#-------------------------------------------------------
# Data elements for test value preparation
#-------------------------------------------------------
def value(lst,string):
for i in range(len(lst)):
if lst[i]==string:
return i
jobs=['admin','blue-collar','entrepreneur','housemaid','managerial','retired','self-employed','services','student','technician','unemployed','others']
marital_status=['divorced','married','single']
education=['10th standard or lower','12th standard','graduate','postgraduate or higher']
yn=['NO','YES']
commn=['Cellular','Telephone','Others']
mon=['January','February','March','April','May','June','July','August','September','October','November','December']
outcome=['Failure','Other','Success','Unknown']
#---------------------------------------------------------
# Body Interface
#---------------------------------------------------------
main_bg = "assets/images/bg.jpg"
main_bg_ext = "jpg"
side_bg = "assets/images/bg.jpg"
side_bg_ext = "jpg"
image=Image.open('assets/images/head.jpg')
st.sidebar.image(image)
st.markdown("<h1 style='text-align: center; color:#7a000d;'>LOAN-WEB</h1>", unsafe_allow_html=True)
st.markdown("<h2 style='text-align: center; color:#7a000d;'>Customer Filtering Engine for Loan Marketing</h2>",unsafe_allow_html=True)
st.markdown("<h3 style='text-align: center; color:#7a000d;'>Find out your perfect customer.</h3>",unsafe_allow_html=True)
st.markdown(
f"""
<style>
.reportview-container {{
background: url(data:image/{main_bg_ext};base64,{base64.b64encode(open(main_bg, "rb").read()).decode()})
}}
.sidebar .sidebar-content {{
background: url(data:image/{side_bg_ext};base64,{base64.b64encode(open(side_bg, "rb").read()).decode()})
}}
</style>
""",
unsafe_allow_html=True
)
#------------------------------------------------------------
# Sidebar Interface
#------------------------------------------------------------
st.sidebar.markdown("""
---
Update your customer data here.
Submit to see results!!
""")
age= st.sidebar.slider("⦿ Age ( Customer's age in Years)",5,100)
job = st.sidebar.selectbox("⦿ Present Job : Customer's present Job",('admin','blue-collar','entrepreneur','housemaid','managerial','retired','self-employed','services','student','technician','unemployed','others'))
marriage = st.sidebar.selectbox("⦿ Marital Status of the user : ",('divorced','married','single'))
edu = st.sidebar.selectbox("⦿ Educational background : ",('10th standard or lower','12th standard','graduate','postgraduate or higher'))
defa = st.sidebar.selectbox('⦿ User possess Credit Card/Cards',('NO','YES'))
bal = st.sidebar.slider("⦿ Average yearly Balance (Lacks per annum) Negative values for debt ",-0.75,100.0)
housing=st.sidebar.selectbox('⦿ Has any housing Loan',('NO','YES'))
loan=st.sidebar.selectbox('⦿ Has any other Loan',('NO',"YES"))
comm=st.sidebar.selectbox('⦿ Contact Medium : ',('Cellular','Telephone','Others'))
day=st.sidebar.slider('⦿ Last Contact day of the month (If no contact till now leave this as it is)',1,30)
month=st.sidebar.selectbox('⦿ Last Contact month (If no contact till now leave this as it is)' ,('January','February','March','April','May','June','July','August','September','October','November','December'))
dur=st.sidebar.slider('⦿ Duration of last call (In minutes)IfNo contact then leave it as 0: ',0,120)
camp=st.sidebar.slider('⦿ Total Number of candidates will be called for this campaign',1,100)
pdays=st.sidebar.slider('⦿ Number of days that passed by after the client was last contacted from a previous campaign (set it -1 if it is the first approach)', int(-1),1095)
prev=st.sidebar.slider('⦿ Number of calls executed in this campaign',0,99)
out=st.sidebar.selectbox('⦿ Previous Campaign Outcome()If no previous campaign leave it as Unknown',('Failure','Success','Unknown','Other'))
#--------------------------------------------------------
# Main Function
#--------------------------------------------------------
if st.sidebar.button('SUBMIT'):
data ={
'age':age,
'job':value(jobs,job),
'marital':value(marital_status,marriage),
'education':value(education,edu),
'default':value(yn,defa),
'balance':(bal/90.17)*100000,
'housing':value(yn,housing),
'loan':value(yn,loan),
'contact':value(commn,comm),
'day':day,
'month':value(mon,month),
'duration':dur*60,
'campaign':camp,
'pdays':pdays,
'previous':prev,
'poutcome':value(outcome,out)
}
df=pd.DataFrame(data,index=[0])
st.markdown("<h1 style='text-align: center; color:#7a000d;'>Engine Running.Processing Results........</h1>", unsafe_allow_html=True)
data=pd.read_csv('assets/data/evaluation data/final_train.csv')
clf=rfc(random_state=1,n_estimators=95)
clf.fit(data.drop('y',1),data['y'])
prediction=clf.predict(df)
prob=clf.predict_proba(df)*100
prob=pd.DataFrame(prob,columns=['Rejection Possibility(in %)','Accepting Possibility(in %)'])
if int(prediction.reshape(1))==1:
image = Image.open('assets/images/pos.png')
st.image(image)
else:
image=Image.open('assets/images/neg.png')
st.image(image)
st.write(pd.DataFrame(prob),index=[0])
#--------------------------------------------------------------
# Footers
#--------------------------------------------------------------
footer="""<style>
a:link , a:visited{
color: blue;
background-color: transparent;
text-decoration: underline;
}
a:hover, a:active {
color:red;
background-color: transparent;
text-decoration: underline;
}
.footer {
position: fixed;
bottom: 0;
width:45%;
color: black;
text-align: center;
}
</style>
<div class="footer">
<p>Developed with ❤ by <a style='display: block; text-align: center;' href="http://happai.epizy.com" target="_blank">Sagnik Roy</a></p>
</div>
"""
st.markdown(footer,unsafe_allow_html=True)
st.sidebar.markdown("""Follow me on [Kaggle](https://kaggle.com/sagnik1511) , [Instagram](https://www.instagram.com/tensored___/) , [Github](https://github.com/sagnik1511)""")
#-----------------------------------------------------------------