-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
63 lines (43 loc) · 1.24 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
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 31 09:43:41 2022
@author: laleh
"""
from fastapi import FastAPI
import uvicorn
import pickle
from Clients import Client
import pandas
app=FastAPI()
f=open('data_Milestone3.pkl', 'rb')
val_final=pickle.load(f)
seuil_final=pickle.load(f)
seuil_final=seuil_final[0,0]
rf_grid=pickle.load(f)
rf_model = rf_grid.best_estimator_
f.close()
X_valids=pandas.read_csv("X_valid.csv")
X_valids=X_valids.iloc[:,1:]
@app.get("/")
def greet():
return {"Hello World!"}
@app.post("/predict")
def predictx(req: Client):
i_client=req.Number
"""
preg=req.pregnacies
glucose=req.glucose
bp=req.bp
skinthickness=req.skinthickness
insulin=req.insulin
bmi=req.bmi
dpf=req.dpf
age=req.age
features=list([preg,glucose,bp,skinthickness, insulin,bmi,dpf,age])
"""
predict=rf_model.predict(X_valids.loc[[i_client]])
probab=rf_model.predict_proba(X_valids.loc[[i_client]])
if (predict==1):
return {"ans":"Your credit is approuved with {} probability".format(probab[0][1])}
else:
return {"ans":"Your credit is rejected with {} probability".format(probab[0][0])}