File size: 1,714 Bytes
2d1db40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pickle5
import streamlit as st

# loading the trained model
pickle_in = open('classifier.pkl', 'rb')
classifier = pickle5.load(pickle_in)


@st.cache()
# defining the function which will make the prediction using the data which the user inputs
def prediction(Gender, Married, ApplicantIncome, LoanAmount, Credit_History):
	# Pre-processing user input
	if Gender == "Male":
		Gender = 0
	else:
		Gender = 1

	if Married == "Unmarried":
		Married = 0
	else:
		Married = 1

	if Credit_History == "Unclear Debts":
		Credit_History = 0
	else:
		Credit_History = 1

	LoanAmount = LoanAmount / 1000

	# Making predictions
	prediction = classifier.predict(
		[[Gender, Married, ApplicantIncome, LoanAmount, Credit_History]])

	if prediction == 0:
		pred = 'Rejected'
	else:
		pred = 'Approved'
	return pred


# this is the main function in which we define our webpage
def main():
	# front end elements of the web page
	st.title("Streamlit Loan Prediction ML App By DSC PSAU ")

	# display the front end aspect

	# following lines create boxes in which user can enter data required to make prediction
	Gender = st.selectbox('Gender', ("Male", "Female"))
	Married = st.selectbox('Marital Status', ("Unmarried", "Married"))
	ApplicantIncome = st.number_input("Applicants monthly income")
	LoanAmount = st.number_input("Total loan amount")
	Credit_History = st.selectbox('Credit_History', ("Unclear Debts", "No Unclear Debts"))
	result = ""

	# when 'Predict' is clicked, make the prediction and store it
	if st.button("Predict"):
		result = prediction(Gender, Married, ApplicantIncome, LoanAmount, Credit_History)
		st.success('Your loan is {}'.format(result))
		print(LoanAmount)


if __name__ == '__main__':
	main()