0
0
MLOpsdevops~10 mins

Audit trails for model decisions in MLOps - Interactive Code Practice

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

Complete the code to log model predictions to a file.

MLOps
with open('audit_log.txt', '[1]') as f:
    f.write(f"Prediction: {prediction}\n")
Drag options to blanks, or click blank then click option'
Ar
Ba
Cw+
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' which overwrites the file, losing previous logs.
2fill in blank
medium

Complete the code to include a timestamp in the audit log entry.

MLOps
import datetime

log_entry = f"{datetime.datetime.now()}: Prediction = {prediction}"
with open('audit_log.txt', 'a') as f:
    f.write([1] + '\n')
Drag options to blanks, or click blank then click option'
Alog_entry()
Bstr(log_entry)
Crepr(log_entry)
Dlog_entry
Attempts:
3 left
💡 Hint
Common Mistakes
Calling log_entry() which causes an error because it's not a function.
3fill in blank
hard

Fix the error in the code that logs model input and output as JSON.

MLOps
import json

log_data = {'input': model_input, 'output': model_output}
with open('audit_log.json', 'a') as f:
    f.write(json.dumps([1]) + '\n')
Drag options to blanks, or click blank then click option'
Astr(log_data)
Blog_data()
Clog_data
Djson.dumps(log_data)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing log_data() which causes a TypeError.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that logs only features with values above 0.5.

MLOps
filtered_log = {key: value for key, value in model_features.items() if value [1] 0.5 and key [2] 'confidence'}
Drag options to blanks, or click blank then click option'
A>
B<
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for value comparison.
Using '==' instead of '!=' for key filtering.
5fill in blank
hard

Fill all three blanks to create a filtered audit log dictionary with uppercase keys, values above 0.7, and keys not equal to 'bias'.

MLOps
filtered_audit = [1]: [2] for [3], val in audit_data.items() if val > 0.7 and [3] != 'bias'
Drag options to blanks, or click blank then click option'
Akey.upper()
Bval
Ckey
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' instead of 'val' for values.
Using 'value' or 'val' as loop variable instead of 'key'.