Create the prediction endpoint
In this exercise, you'll create a prediction endpoint that uses a pre-trained model to estimate diabetes progression.
The model has been trained on a dataset which has three features age
, bmi
and blood_pressure
. It then predicts the diabetes progression score. Using these inputs, it predicts a diabetes progression score, which helps assess how the condition may develop over time.
You'll use FastAPI
to create a POST
endpoint that accepts patient data and returns a prediction of diabetes progression.
This exercise is part of the course
Deploying AI into Production with FastAPI
Exercise instructions
- Create an application instance of
FastAPI
to start developing the API. - Create a
POST
endpoint at/predict
that accepts patientfeatures
and returns a prediction. - Use the loaded model to make a prediction based on the input features.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create FastAPI instance
app = ____()
# Create a POST request endpoint at the route "/predict"
@app.____("____")
async def predict_progression(features: DiabetesFeatures):
input_data = [[
features.age,
features.bmi,
features.blood_pressure
]]
# Use the predict method to make a prediction
prediction = model.____(input_data)
return {"predicted_progression": float(prediction[0])}