Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the model's predictions as a list.
Prompt Engineering / GenAI
predictions = model.predict(data) print(list([1]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data' instead of 'predictions' inside print.
Trying to print 'model' object directly.
✗ Incorrect
The model's predictions are stored in the variable 'predictions'. To print them as a list, we convert 'predictions' to a list.
2fill in blank
mediumComplete the code to calculate accuracy score from true and predicted labels.
Prompt Engineering / GenAI
from sklearn.metrics import accuracy_score accuracy = accuracy_score([1], predicted_labels)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping true and predicted labels in accuracy_score.
Passing the model object instead of labels.
✗ Incorrect
The accuracy_score function compares true labels with predicted labels. The first argument must be the true labels.
3fill in blank
hardFix the error in printing the training loss after each epoch.
Prompt Engineering / GenAI
for epoch in range(5): loss = model.train_on_batch(x_train, y_train) print(f"Epoch {epoch+1}, Loss: [1]")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Printing 'model' or 'epoch' instead of 'loss'.
Forgetting to add 1 to epoch for display.
✗ Incorrect
The variable 'loss' holds the training loss value returned by train_on_batch, so it should be printed.
4fill in blank
hardFill both blanks to create a dictionary of predictions with keys as sample IDs and values as predicted labels.
Prompt Engineering / GenAI
pred_dict = [1](sample_id: [2] for sample_id, [3] in zip(ids, predictions))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'list' instead of 'dict' for dictionary creation.
Using wrong variable names for predicted labels.
✗ Incorrect
To create a dictionary comprehension, use 'dict' and map sample_id to label from predictions.
5fill in blank
hardFill all three blanks to filter predictions greater than threshold and create a result dictionary.
Prompt Engineering / GenAI
result = [1]: [2] for [3], [4] in enumerate(predictions) if [2] > threshold}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or forgetting to use enumerate.
Using wrong variable names for keys or values.
✗ Incorrect
Use 'i' as the key from enumerate, 'pred' as the value, and iterate with 'i, pred' to filter predictions above threshold.