Practice
1. Given the following Python code, what is the output when evaluating the calibration of a model using Brier Score?
from sklearn.metrics import brier_score_loss
true_labels = [0, 1, 1, 0]
predicted_probs = [0.1, 0.9, 0.8, 0.4]
score = brier_score_loss(true_labels, predicted_probs)
print(score)easy
Solution
Step 1: Understand Brier Score calculation.
Brier Score is the mean squared difference between predicted probabilities and actual outcomes.Step 2: Calculate the score.
For each pair: (0.1-0)^2, (0.9-1)^2, (0.8-1)^2, (0.4-0)^2. Mean = (0.01 + 0.01 + 0.04 + 0.16) / 4 = 0.055.Final Answer:
Option D -> Option DQuick Check:
Brier Score = mean squared error of probabilities. [OK]
Hint: Brier Score = mean squared error of probabilities. [OK]
Common Mistakes:
2.
import numpy as np
class ContinualLearner:
def __init__(self):
self.model = None
def update(self, new_data):
if self.model is None:
self.model = new_data
else:
self.model += new_data
learner = ContinualLearner()
learner.update(np.array([1, 2, 3]))
learner.update(np.array([4, 5, 6]))
print(learner.model)What does this code output?easy
Solution
Step 1: Understand the update mechanism.
The code initializes the model with the first data and adds subsequent data to it.Step 2: Calculate the output.
First update sets model to [1, 2, 3]. Second update adds [4, 5, 6], resulting in [5, 7, 9].Final Answer:
Option A -> Option AQuick Check:
First set, then add. [OK]
Hint: First set, then add. [OK]
Common Mistakes:
3. Given the following Python code snippet, what is the output?
import numpy as np
relevance_scores = [3, 2, 3, 0, 1, 2]
ideal_dcg = np.sum([3/np.log2(i+2) for i in range(len(relevance_scores))])
print(round(ideal_dcg, 2))easy
Solution
Step 1: Calculate the ideal DCG
Use the formula DCG = Σ(rel_i / log2(i+2)) for each relevance score.Step 2: Perform the calculation
3/1 + 2/1.585 + 3/2 + 0/2.322 + 1/2.585 + 2/2.807 = 6.86.Final Answer:
Option B -> Option BQuick Check:
DCG uses log2(i+2) for position i. [OK]
Hint: DCG uses log2(i+2) for position i. [OK]
Common Mistakes:
4. You are tasked with designing a fraud detection system. How would you ensure that your model does not suffer from data leakage?
hard
Solution
Step 1: Identify potential leakage sources in fraud detection
Using future-derived features can cause leakage.Step 2: Evaluate each option
Use cross-validation with shuffling to ensure robust performance. might introduce leakage if shuffling is inappropriate, Include all available transaction data up to the current date in the training set. risks future data leakage, Use a single train-test split to simplify the evaluation process. is simplistic and risky.Final Answer:
Option A -> Option AQuick Check:
Avoid future-derived features in training [OK]
Hint: Avoid future-derived features in training [OK]
Common Mistakes:
5. In a multilingual context, how can you adapt Word2Vec embeddings to handle multiple languages effectively?
hard
Solution
Step 1: Evaluate multilingual strategies
Multilingual BERT is designed to handle multiple languages effectively, unlike Word2Vec.Step 2: Eliminate wrong options
Train separate Word2Vec models for each language and concatenate the embeddings. doesn't capture cross-lingual semantics. Use a shared vocabulary across languages and train a single Word2Vec model. is impractical due to vocabulary differences. Translate all text to a single language before training Word2Vec. loses language-specific nuances.Final Answer:
Option A -> Option AQuick Check:
Multilingual BERT for cross-language tasks [OK]
Hint: Multilingual BERT for cross-language tasks [OK]
Common Mistakes:
