API Documentation
The MLOps API can be requested from the localhost
on port 5000
.
predict(user_id)
Predict status from user ID features.
Retrieve most recent features and make a prediction on the status
.
cURL command:
curl -X 'GET' 'http://localhost:5000/{user_id}/predict' -H 'accept: application/json'
Parameters: |
|
---|
Returns: |
|
---|
Source code in app/api.py
@app.get(
"/{user_id}/predict",
tags=["Prediction"],
response_model=Response,
response_model_exclude_none=True,
)
def predict(user_id: int) -> dict:
"""
Predict status from user ID features.
Retrieve most recent features and make a prediction on the ``status``.
cURL command:
```bash
curl -X 'GET' 'http://localhost:5000/{user_id}/predict' -H 'accept: application/json'
```
Parameters:
user_id (int):
User ID.
Returns:
Response with ``prediction``.
"""
data = serve_features(user_id)["data"]
if data["found"]:
data["prediction"] = int(model.predict([data["features"]]))
return {"data": data}
serve_features(user_id)
Serve features from a user ID.
Retrieve age
, years_on_the_job
, nb_previous_loans
,
avg_amount_loans_previous
and flag_own_car
most recent features.
cURL command:
curl -X 'GET' 'http://localhost:5000/{user_id}' -H 'accept: application/json'
Parameters: |
|
---|
Returns: |
|
---|
Source code in app/api.py
@app.get(
"/{user_id}",
tags=["Features"],
response_model=Response,
response_model_exclude_none=True,
)
def serve_features(user_id: int) -> dict:
"""
Serve features from a user ID.
Retrieve ``age``, ``years_on_the_job``, ``nb_previous_loans``,
``avg_amount_loans_previous`` and ``flag_own_car``
most recent features.
cURL command:
```bash
curl -X 'GET' 'http://localhost:5000/{user_id}' -H 'accept: application/json'
```
Parameters:
user_id (int):
User ID.
Returns:
Response with ``features``.
"""
data = {
"user_id": user_id,
"found": user_id in df["id"].values,
"features": None,
}
if data["found"]:
ser = df[df["id"] == user_id].iloc[-1]
ser.drop(["id", "status"], inplace=True)
data["features"] = ser
return {"data": data}