0
0
ML Pythonml~10 mins

Flask API for model serving in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AFlask
BRequest
Cjsonify
Drender_template
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Request or jsonify instead of Flask
Using wrong class name for app creation
2fill in blank
medium

Complete 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'
A/predict
B/train
C/model
D/input
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET method instead of POST
Wrong endpoint path like '/train'
3fill in blank
hard

Fix 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'
Ajsonify
Bjson
Cget_json()
Dget_json
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.json without parentheses
Using request.jsonify which is incorrect
4fill in blank
hard

Fill 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'
Aload
Bpredict
Cdump
Dfit
Attempts:
3 left
💡 Hint
Common Mistakes
Using joblib.dump instead of load
Using model.fit instead of predict
5fill in blank
hard

Fill 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'
A'result'
B200
C201
D'output'
Attempts:
3 left
💡 Hint
Common Mistakes
Using status code 201 which means created
Using wrong JSON key names