0
0
Prompt Engineering / GenAIml~10 mins

Output format control in Prompt Engineering / GenAI - Interactive Code Practice

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

Complete 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'
Adata
Bpredictions
Cmodel
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data' instead of 'predictions' inside print.
Trying to print 'model' object directly.
2fill in blank
medium

Complete 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'
Atrue_labels
Bpredicted_labels
Cmodel
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping true and predicted labels in accuracy_score.
Passing the model object instead of labels.
3fill in blank
hard

Fix 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'
Aepoch
Bmodel
Closs
Dx_train
Attempts:
3 left
💡 Hint
Common Mistakes
Printing 'model' or 'epoch' instead of 'loss'.
Forgetting to add 1 to epoch for display.
4fill in blank
hard

Fill 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'
Adict
Blabel
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'list' instead of 'dict' for dictionary creation.
Using wrong variable names for predicted labels.
5fill in blank
hard

Fill 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'
Ai
Bpred
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or forgetting to use enumerate.
Using wrong variable names for keys or values.