-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
103 lines (77 loc) · 3.11 KB
/
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
# importing required libraries
import pickle
import streamlit as st
# loading the trained model
pickle_in = open('classifier.pkl', 'rb')
classifier = pickle.load(pickle_in)
# this is the main function in which we define our app
def main():
# header of the page
html_temp = """
<div style ="background-color:yellow;padding:13px">
<h1 style ="color:black;text-align:center;">Check your Loan Eligibility</h1>
</div>
"""
st.markdown(html_temp, unsafe_allow_html = True)
# following lines create boxes in which user can enter data required to make prediction
Gender = st.selectbox('Gender',("Male","Female","Other"))
Married = st.selectbox('Marital Status',("Unmarried","Married"))
Self_Employed = st.selectbox('Self_Employed',("Yes","No"))
Dependents = st.selectbox('Number of Dependents',("0","1", "2", "3+"))
Education = st.selectbox('Education level',("Graduate","Not Graduate"))
Property_Area = st.selectbox('Property_Area',("Rural","Semiurban", "Urban"))
ApplicantIncome = st.number_input("Monthly Income in Rupees")
CoapplicantIncome = st.number_input("Coapplicant's Monthly Income in Rupees")
LoanAmount = st.number_input("Loan Amount in Rupees")
Loan_Amount_Term = st.number_input("Term for Loan Amount")
Credit_History = st.number_input("Credit_History")
result =""
# when 'Check' is clicked, make the prediction and store it
if st.button("Check"):
result = prediction(Gender, Married,Self_Employed,Dependents,Education,Property_Area,
ApplicantIncome, CoapplicantIncome,LoanAmount,Loan_Amount_Term ,Credit_History)
st.success('Your loan is {}'.format(result))
# defining the function which will make the prediction using the data which the user inputs
def prediction(Gender, Married,Self_Employed,Dependents,Education,Property_Area, ApplicantIncome,CoapplicantIncome,
LoanAmount,Loan_Amount_Term ,Credit_History):
# 2. Loading and Pre-processing the data
if Gender == "Male":
Gender = 0
else:
Gender = 1
if Married == "Yes":
Married = 1
else:
Married = 0
if Self_Employed == "Yes":
Self_Employed = 0
else:
Self_Employed = 1
if Dependents == "0":
Dependents = 0
elif Dependents == "1":
Dependents = 1
elif Dependents == "2":
Dependents = 2
else:
Dependents = 3
if Education == "Graduate":
Education = 1
else:
Education = 0
if Property_Area == "Rural":
Property_Area = 0
elif Property_Area=="Semiurban":
Property_Area = 1
else:
Property_Area = 2
prediction = classifier.predict(
[[Gender, Married, Self_Employed,Dependents,Education,Property_Area,ApplicantIncome,CoapplicantIncome,
LoanAmount, Loan_Amount_Term,Credit_History ]])
if prediction == 0:
pred = 'Rejected'
else:
pred = 'Approved'
return pred
if __name__=='__main__':
main()