0
0
ML Pythonml~10 mins

Privacy considerations in ML Python - Interactive Code Practice

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

Complete the code to import the library used for differential privacy in machine learning.

ML Python
from diffprivlib import [1]
Drag options to blanks, or click blank then click option'
Amodels
Bdatasets
Cprivacy
Dmechanisms
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'models' instead of 'mechanisms'.
Using 'privacy' which is not a valid module.
2fill in blank
medium

Complete the code to add Gaussian noise for privacy to a numeric value.

ML Python
noisy_value = original_value + [1](0, 1)
Drag options to blanks, or click blank then click option'
Arandom.randint
Brandom.uniform
Crandom.gauss
Drandom.normalvariate
Attempts:
3 left
💡 Hint
Common Mistakes
Using uniform noise instead of Gaussian.
Using randint which adds integer noise.
3fill in blank
hard

Fix the error in the code to ensure the model does not memorize sensitive data by limiting training epochs.

ML Python
model.fit(X_train, y_train, epochs=[1])
Drag options to blanks, or click blank then click option'
A1
B1000
C50
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using too many epochs causing overfitting.
Using zero epochs which means no training.
4fill in blank
hard

Fill in the blank to create a dictionary comprehension that filters out data points with sensitive attribute value 'Yes'.

ML Python
filtered_data = {k: v for k, v in data.items() if v[1] 'Yes'}
Drag options to blanks, or click blank then click option'
A>
B!=
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which keeps only 'Yes' values.
Using '<' or '>' which are not meaningful for strings here.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps user IDs to their masked emails only if their consent is True.

ML Python
masked_emails = {user[1]: email[2] for user, (email, consent) in users.items() if consent [3] True}
Drag options to blanks, or click blank then click option'
A[::-1]
B.lower()
C==
D[:3] + '***'
Attempts:
3 left
💡 Hint
Common Mistakes
Using reverse slicing which doesn't mask properly.
Not filtering by consent.
Not converting email to lowercase.