Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the model's prediction on new data.
ML Python
prediction = model.[1](new_data) print(prediction)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fit' instead of 'predict' to get predictions.
✗ Incorrect
The predict method is used to get the model's output on new data.
2fill in blank
mediumComplete the code to save the trained model for deployment.
ML Python
import joblib joblib.[1](model, 'model.pkl')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'load' instead of 'dump' to save the model.
✗ Incorrect
The dump function saves the model to a file for later use.
3fill in blank
hardFix the error in the code to deploy a model as a web service.
ML Python
from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/predict', methods=['POST']) def predict(): data = request.get_json() prediction = model.[1](data['input']) return jsonify({'prediction': prediction.tolist()})
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fit' or 'train' instead of 'predict' in deployment code.
✗ Incorrect
Use predict to get the model's output on input data in deployment.
4fill in blank
hardFill both blanks to create a dictionary comprehension that filters features with importance above 0.1.
ML Python
important_features = {feature: importance for feature, importance in model.feature_importances_.items() if importance [1] 0.1 and feature [2] 'bias'} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for importance check.
Using '==' instead of '!=' to exclude 'bias'.
✗ Incorrect
We want features with importance greater than 0.1 and exclude the 'bias' feature.
5fill in blank
hardFill all three blanks to create a dictionary of predictions for inputs with confidence above 0.8.
ML Python
high_confidence_preds = [1]: [2] for [3] in inputs if model.predict_proba([[3]])[0][1] > 0.8}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using predict_proba output directly as prediction.
✗ Incorrect
We use 'input' as the key and the model's prediction as the value for each input in inputs.