-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcredit_api.py
134 lines (120 loc) · 3.72 KB
/
credit_api.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
from flask import Flask
from flask.ext.restplus import Api
app = Flask(__name__)
api = Api(
app,
version='1.0',
title='Credit API',
description='A simple Prediction API')
ns = api.namespace('approve_credit',
description='Approve Credit Operations')
from flask.ext.restplus import fields
resource_fields = api.model('Resource', {
'result': fields.String,
})
parser = api.parser()
parser.add_argument(
'RevolvingUtilizationOfUnsecuredLines',
type=float,
required=True,
help='Total balance on credit cards and personal lines of credit except real estate and no installment debt like car loans divided by the sum of credit limits',
location='form')
parser.add_argument(
'age',
type=float,
required=True,
help='Age of borrower in years',
location='form')
parser.add_argument(
'NumberOfTime30-59DaysPastDueNotWorse',
type=float,
required=True,
help='Number of times borrower has been 30-59 days past due but no worse in the last 2 years.',
location='form')
parser.add_argument(
'DebtRatio',
type=float,
required=True,
help='Monthly debt payments, alimony,living costs divided by monthy gross income',
location='form')
parser.add_argument(
'MonthlyIncome',
type=float,
required=True,
help='Monthly income',
location='form')
parser.add_argument(
'NumberOfOpenCreditLinesAndLoans',
type=float,
required=True,
help='Number of Open loans (installment like car loan or mortgage) and Lines of credit (e.g. credit cards)',
location='form')
parser.add_argument(
'NumberOfTimes90DaysLate',
type=float,
required=True,
help='Number of times borrower has been 90 days or more past due.',
location='form')
parser.add_argument(
'NumberRealEstateLoansOrLines',
type=float,
required=True,
help='Number of mortgage and real estate loans including home equity lines of credit',
location='form')
parser.add_argument(
'NumberOfTime60-89DaysPastDueNotWorse',
type=float,
required=True,
help='Number of mortgage and real estate loans including home equity lines of credit',
location='form')
parser.add_argument(
'NumberOfDependents',
type=float,
required=True,
help='Number of mortgage and real estate loans including home equity lines of credit',
location='form')
from flask.ext.restplus import Resource
@ns.route('/')
class CreditApi(Resource):
@api.doc(parser=parser)
@api.marshal_with(resource_fields)
def post(self):
args = parser.parse_args()
result = self.get_result(args)
return result, 201
def get_result(self, args):
debtRatio = args["DebtRatio"]
monthlyIncome = args["MonthlyIncome"]
dependents = args["NumberOfDependents"]
openCreditLinesAndLoans = args["NumberOfOpenCreditLinesAndLoans"]
pastDue30Days = args["NumberOfTime30-59DaysPastDueNotWorse"]
pastDue60Days = args["NumberOfTime60-89DaysPastDueNotWorse"]
pastDue90Days = args["NumberOfTimes90DaysLate"]
realEstateLoansOrLines = args["NumberRealEstateLoansOrLines"]
unsecuredLines = args["RevolvingUtilizationOfUnsecuredLines"]
age = args["age"]
from pandas import DataFrame
df = DataFrame([[
debtRatio,
monthlyIncome,
dependents,
openCreditLinesAndLoans,
pastDue30Days,
pastDue60Days,
pastDue90Days,
realEstateLoansOrLines,
unsecuredLines,
age
]])
from sklearn.externals import joblib
clf = joblib.load('model/nb.pkl');
result = clf.predict(df)
if(result[0] == 1.0):
result = "deny"
else:
result = "approve"
return {
"result": result
}
if __name__ == '__main__':
app.run(debug=True)