Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Deploying AI into Production with FastAPI

Cursus bekijken

Oefeninstructies

  • Create an application instance of FastAPI to start developing the API.
  • Create a POST endpoint at /predict that accepts patient features and returns a prediction.
  • Use the loaded model to make a prediction based on the input features.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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])}
Code bewerken en uitvoeren