Challenge - 5 Problems
Flask Model Serving Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Flask API response code?
Consider a Flask API that loads a trained model and predicts the class for input data. What will be the JSON response when sending input data [5.1, 3.5, 1.4, 0.2] to this endpoint?
ML Python
from flask import Flask, request, jsonify import numpy as np import pickle app = Flask(__name__) # Load model with open('iris_model.pkl', 'rb') as f: model = pickle.load(f) @app.route('/predict', methods=['POST']) def predict(): data = request.json['data'] arr = np.array(data).reshape(1, -1) pred = model.predict(arr) return jsonify({'prediction': int(pred[0])})
Attempts:
2 left
💡 Hint
The model is trained on Iris dataset where class 0 corresponds to 'setosa'. The input matches typical setosa features.
✗ Incorrect
The model predicts class 0 for the given input features which correspond to Iris setosa. The API returns the class index as an integer in JSON.
❓ Model Choice
intermediate2:00remaining
Which model type is best suited for this Flask API serving handwritten digit recognition?
You want to serve a model via Flask API that recognizes handwritten digits (0-9) from 28x28 grayscale images. Which model type below is most appropriate for this task?
Attempts:
2 left
💡 Hint
Consider the input type and the need to capture spatial features in images.
✗ Incorrect
CNNs are designed to capture spatial patterns in images and perform well on image classification tasks like digit recognition.
❓ Hyperparameter
advanced2:00remaining
Which hyperparameter tuning improves Flask API model latency the most?
You deployed a deep learning model in a Flask API. The API latency is high. Which hyperparameter tuning below will most likely reduce prediction latency?
Attempts:
2 left
💡 Hint
Think about what affects model size and inference speed.
✗ Incorrect
Reducing model size via pruning or quantization decreases computation needed during inference, lowering latency.
🔧 Debug
advanced2:00remaining
Why does this Flask API code raise a KeyError?
This Flask API code raises a KeyError when a POST request is sent. What is the cause?
ML Python
from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/predict', methods=['POST']) def predict(): data = request.json['input'] # model prediction code here return jsonify({'result': 'ok'})
Attempts:
2 left
💡 Hint
Check the JSON keys sent in the request body.
✗ Incorrect
If the client sends JSON without the 'input' key, accessing request.json['input'] raises KeyError.
❓ Metrics
expert2:00remaining
Which metric best evaluates a Flask API model for imbalanced binary classification?
Your Flask API serves a model that predicts rare disease presence (positive class is 1% of data). Which metric below is best to evaluate model performance?
Attempts:
2 left
💡 Hint
Consider a metric that balances false positives and false negatives in imbalanced data.
✗ Incorrect
F1-score balances precision and recall, providing a better measure than accuracy alone for imbalanced classes.