forked from codejay411/loan_prediction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
110 lines (85 loc) · 2.93 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
104
105
106
107
108
109
110
# save this as app.py
from flask import Flask, escape, request, render_template
import pickle
import numpy as np
app = Flask(__name__)
model = pickle.load(open('model.pkl', 'rb'))
@app.route('/')
def home():
return render_template("index.html")
@app.route('/predict', methods=['GET', 'POST'])
def predict():
if request.method == 'POST':
gender = request.form['gender']
married = request.form['married']
dependents = request.form['dependents']
education = request.form['education']
employed = request.form['employed']
credit = float(request.form['credit'])
area = request.form['area']
ApplicantIncome = float(request.form['ApplicantIncome'])
CoapplicantIncome = float(request.form['CoapplicantIncome'])
LoanAmount = float(request.form['LoanAmount'])
Loan_Amount_Term = float(request.form['Loan_Amount_Term'])
# gender
if (gender == "Male"):
male=1
else:
male=0
# married
if(married=="Yes"):
married_yes = 1
else:
married_yes=0
# dependents
if(dependents=='1'):
dependents_1 = 1
dependents_2 = 0
dependents_3 = 0
elif(dependents == '2'):
dependents_1 = 0
dependents_2 = 1
dependents_3 = 0
elif(dependents=="3+"):
dependents_1 = 0
dependents_2 = 0
dependents_3 = 1
else:
dependents_1 = 0
dependents_2 = 0
dependents_3 = 0
# education
if (education=="Not Graduate"):
not_graduate=1
else:
not_graduate=0
# employed
if (employed == "Yes"):
employed_yes=1
else:
employed_yes=0
# property area
if(area=="Semiurban"):
semiurban=1
urban=0
elif(area=="Urban"):
semiurban=0
urban=1
else:
semiurban=0
urban=0
ApplicantIncomelog = np.log(ApplicantIncome)
totalincomelog = np.log(ApplicantIncome+CoapplicantIncome)
LoanAmountlog = np.log(LoanAmount)
Loan_Amount_Termlog = np.log(Loan_Amount_Term)
prediction = model.predict([[credit, ApplicantIncomelog,LoanAmountlog, Loan_Amount_Termlog, totalincomelog, male, married_yes, dependents_1, dependents_2, dependents_3, not_graduate, employed_yes,semiurban, urban ]])
# print(prediction)
if(prediction=="N"):
prediction="No"
else:
prediction="Yes"
return render_template("prediction.html", prediction_text="loan status is {}".format(prediction))
else:
return render_template("prediction.html")
if __name__ == "__main__":
app.run(debug=True)