Complete the code to log model predictions to a file.
with open('audit_log.txt', '[1]') as f: f.write(f"Prediction: {prediction}\n")
Use 'a' to append logs without overwriting existing data.
Complete the code to include a timestamp in the audit log entry.
import datetime log_entry = f"{datetime.datetime.now()}: Prediction = {prediction}" with open('audit_log.txt', 'a') as f: f.write([1] + '\n')
log_entry is already a string, so write it directly.
Fix the error in the code that logs model input and output as JSON.
import json log_data = {'input': model_input, 'output': model_output} with open('audit_log.json', 'a') as f: f.write(json.dumps([1]) + '\n')
json.dumps expects a dictionary, so pass log_data directly.
Fill both blanks to create a dictionary comprehension that logs only features with values above 0.5.
filtered_log = {key: value for key, value in model_features.items() if value [1] 0.5 and key [2] 'confidence'}We want values greater than 0.5 and keys not equal to 'confidence'.
Fill all three blanks to create a filtered audit log dictionary with uppercase keys, values above 0.7, and keys not equal to 'bias'.
filtered_audit = [1]: [2] for [3], val in audit_data.items() if val > 0.7 and [3] != 'bias'
Use key.upper() for keys, val for values, and key as the loop variable.
