-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf9730a
commit 8279e3f
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.dvc | ||
data | ||
notebooks | ||
reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM python:3.10 | ||
ENV PYTHONPATH=/app | ||
WORKDIR /app | ||
COPY . . | ||
RUN pip install -U pip | ||
RUN pip install -r requirements.txt | ||
EXPOSE 8080 | ||
CMD uvicorn src.app.main:app --host 0.0.0.0 --port 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import json | ||
import sys | ||
from pathlib import Path | ||
|
||
import uvicorn | ||
|
||
src_path = Path(__file__).parent.parent.resolve() | ||
sys.path.append(str(src_path)) | ||
|
||
from typing import List | ||
|
||
import pandas as pd | ||
from fastapi import Body, FastAPI, Request | ||
from fastapi.middleware.cors import CORSMiddleware | ||
from joblib import load | ||
from pydantic import BaseModel | ||
|
||
from utils.load_params import load_params | ||
|
||
app = FastAPI() | ||
# https://fastapi.tiangolo.com/tutorial/cors/#use-corsmiddleware | ||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=["*"], | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
params = load_params(params_path='params.yaml') | ||
model_path = params.train.model_path | ||
feat_cols = params.base.feat_cols | ||
model = load(filename=model_path) | ||
|
||
class Customer(BaseModel): | ||
CreditScore: int | ||
Age: int | ||
Tenure: int | ||
Balance: float | ||
NumOfProducts: int | ||
HasCrCard: int | ||
IsActiveMember: int | ||
EstimatedSalary: float | ||
|
||
class Request(BaseModel): | ||
data: List[Customer] | ||
|
||
@app.post("/predict") | ||
async def predict(info: Request = Body(..., example={ | ||
"data": [ | ||
{ | ||
"CreditScore": 619, | ||
"Age": 42, | ||
"Tenure": 2, | ||
"Balance": 0, | ||
"NumOfProducts": 1, | ||
"HasCrCard": 1, | ||
"IsActiveMember": 1, | ||
"EstimatedSalary": 101348.88 | ||
}, | ||
{ | ||
"CreditScore": 699, | ||
"Age": 39, | ||
"Tenure": 21, | ||
"Balance": 0, | ||
"NumOfProducts": 2, | ||
"HasCrCard": 0, | ||
"IsActiveMember": 0, | ||
"EstimatedSalary": 93826.63 | ||
} | ||
] | ||
})): | ||
json_list = json.loads(info.json()) | ||
data = json_list['data'] | ||
input_data = pd.DataFrame(data) | ||
probs = model.predict_proba(input_data)[:,0] | ||
probs = probs.tolist() | ||
return probs | ||
|
||
if __name__ == "__main__": | ||
uvicorn.run(app, host="0.0.0.0", port=8000) |
8279e3f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics
Feature Importances
Confusion Matrix