By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Ethics and privacy in data science are the set of principles, laws, and technical safeguards that ensure personal data is collected, stored, processed, and shared responsibly. In a typical workflow—e.g., building a churn‑prediction model for a telecom provider—you must verify that every row of customer data was obtained with valid consent, that any personally‑identifiable information (PII) is anonymized or pseudonymized, and that the final model complies with regulations such as the EU GDPR. Ignoring these steps can lead to legal penalties, loss of trust, and biased or unsafe models (e.g., a medical‑image classifier that inadvertently reveals patient IDs).
fairlearn
AIF360
Ingest with Consent Log python consent_df = pd.read_csv('consent_log.csv') # columns: user_id, consent_ts, version raw_df = pd.read_csv('raw_features.csv') df = raw_df.merge(consent_df, on='user_id') assert df['consent'].all() # abort if any missing consent
python consent_df = pd.read_csv('consent_log.csv') # columns: user_id, consent_ts, version raw_df = pd.read_csv('raw_features.csv') df = raw_df.merge(consent_df, on='user_id') assert df['consent'].all() # abort if any missing consent
Apply Data Minimization & Quasi‑Identifier Selection python keep_cols = ['age', 'zip', 'plan_type', 'churn'] # drop free‑text comments, email df = df[keep_cols] qi = ['age', 'zip'] # quasi‑identifiers
python keep_cols = ['age', 'zip', 'plan_type', 'churn'] # drop free‑text comments, email df = df[keep_cols] qi = ['age', 'zip'] # quasi‑identifiers
Anonymize / Pseudonymize python # k‑anonymize using generalization df['age_bin'] = pd.cut(df['age'], bins=[0,20,30,40,50,60,100], labels=False) df['zip_prefix'] = df['zip'].astype(str).str[:3] # 3‑digit prefix # Pseudonymize user_id for downstream joins df['user_hash'] = df['user_id'].apply(lambda x: hashlib.sha256(str(x).encode()).hexdigest())
python # k‑anonymize using generalization df['age_bin'] = pd.cut(df['age'], bins=[0,20,30,40,50,60,100], labels=False) df['zip_prefix'] = df['zip'].astype(str).str[:3] # 3‑digit prefix # Pseudonymize user_id for downstream joins df['user_hash'] = df['user_id'].apply(lambda x: hashlib.sha256(str(x).encode()).hexdigest())
Differentially‑Private Model Training (optional) python from tensorflow_privacy import DPGradientDescentGaussianOptimizer optimizer = DPGradientDescentGaussianOptimizer(l2_norm_clip=1.0, noise_multiplier=1.1, num_microbatches=256, learning_rate=0.01) model.compile(optimizer=optimizer, loss='binary_crossentropy') model.fit(X_train, y_train, epochs=5)
python from tensorflow_privacy import DPGradientDescentGaussianOptimizer optimizer = DPGradientDescentGaussianOptimizer(l2_norm_clip=1.0, noise_multiplier=1.1, num_microbatches=256, learning_rate=0.01) model.compile(optimizer=optimizer, loss='binary_crossentropy') model.fit(X_train, y_train, epochs=5)
Validate Legal & Ethical Compliance
fairlearn.metrics.demographic_parity_difference
Verify RTBF by deleting a user’s rows and re‑computing model predictions on the remaining data.
Deploy with Monitoring
Mistake: “I can keep the raw email column because I’ll drop it later.” Correction: Store only the minimum needed; retaining raw identifiers even temporarily can breach GDPR’s data‑minimization principle and increase breach risk.
Mistake: “k‑anonymity alone protects privacy.” Correction: k‑anonymity is vulnerable to homogeneity and background‑knowledge attacks; combine with ℓ‑diversity or differential privacy for stronger guarantees.
Mistake: “Hashing user IDs is enough for anonymization.” Correction: Simple hashes are reversible with rainbow tables; use salted hashes or HMAC and treat them as pseudonyms, not full anonymization.
Mistake: “I can ignore consent because the data is already public.” Correction: Public data still requires a legal basis; if the original collection lacked consent for the new purpose, you must obtain it or fall back to a legitimate‑interest assessment.
Mistake: “Differential privacy is free—just add noise and go.” Correction: DP introduces a privacy budget (ε); you must track cumulative ε across analyses and understand the trade‑off between utility and privacy.
Anonymization is irreversible (no way to re‑identify); pseudonymization is reversible under controlled conditions (e.g., salted hash).
“How would you implement k‑anonymity on a dataset with age and zip code?”
Generalize age into bins, truncate zip to a prefix, then verify each equivalence class size ≥ k; if not, increase bin width or suppress outliers.
“What is the privacy‑utility trade‑off in differential privacy?”
Adding more noise (lower ε) improves privacy but degrades model accuracy; interviewers expect you to discuss budgeting ε across multiple queries.
“When is a data‑subject’s right to be forgotten technically impossible, and what do you do?”
Scenario: Your churn model uses a feature “full address”. Q: What privacy step must you take before training? A: Generalize or remove the address (e.g., keep only zip‑prefix) to satisfy data minimization and reduce re‑identification risk.
Scenario: A regulator asks for proof of consent for a specific user. Q: How should you have stored this information? A: Immutable consent log with timestamp, version of privacy notice, and user identifier (hashed) to demonstrate compliance.
Scenario: After applying k‑anonymity (k=5), you notice one equivalence class still has only 3 records. Q: What is the quickest fix? A: Suppress or generalize additional attributes (e.g., broaden age bins) until the class reaches size ≥ 5.
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.