Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flask class from the flask package.
ML Python
from flask import [1] app = [1](__name__)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Request or jsonify instead of Flask
Using wrong class name for app creation
✗ Incorrect
The Flask class is imported from the flask package to create the app instance.
2fill in blank
mediumComplete the code to define a route for the API endpoint '/predict'.
ML Python
@app.route('[1]', methods=['POST']) def predict(): pass
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET method instead of POST
Wrong endpoint path like '/train'
✗ Incorrect
The route decorator defines the URL path '/predict' for the prediction API.
3fill in blank
hardFix the error in the code to get JSON data from the POST request.
ML Python
data = request.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.json without parentheses
Using request.jsonify which is incorrect
✗ Incorrect
Use request.get_json() method to parse JSON data from the request body.
4fill in blank
hardFill both blanks to load a saved model and make a prediction.
ML Python
import joblib model = joblib.[1]('model.pkl') prediction = model.[2]([input_data])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using joblib.dump instead of load
Using model.fit instead of predict
✗ Incorrect
Use joblib.load to load the saved model and model.predict to get predictions.
5fill in blank
hardFill both blanks to return the prediction as JSON with status code 200.
ML Python
from flask import jsonify return jsonify([1]: prediction[0]}), [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using status code 201 which means created
Using wrong JSON key names
✗ Incorrect
Return JSON with key 'result' and HTTP status code 200 for success.