Practice
1. Given the following Python code using Word2Vec, what is the output shape of the word vector for 'king'?
from gensim.models import Word2Vec
model = Word2Vec(sentences, vector_size=100, window=5, min_count=1, workers=4)
vector = model.wv['king']easy
Solution
Step 1: Understand Word2Vec output
The Word2Vec model returns a 1D array of the specified vector size for each word.Step 2: Determine the shape
The vector size is set to 100, so the output shape is (100,).Final Answer:
Option C -> Option CQuick Check:
Word2Vec outputs 1D vector of size [OK]
Hint: Word2Vec outputs 1D vector of size [OK]
Common Mistakes:
2. Given the following Python code using Naive Bayes, what will be the output?
from sklearn.naive_bayes import GaussianNB
import numpy as np
X = np.array([[1, 2], [2, 3], [3, 4]])
y = np.array([1, 0, 1])
model = GaussianNB()
model.fit(X, y)
print(model.predict([[2, 2]]))easy
Solution
Step 1: Understand the Code Execution
The code fits a Gaussian Naive Bayes model and predicts the class for a new sample [2, 2].Step 2: Analyze the Prediction
Given the training data, the model predicts class 1 for [2, 2] based on the likelihoods.Final Answer:
Option A -> Option AQuick Check:
GaussianNB predicts based on likelihoods. [[check]]
Hint: GaussianNB predicts based on likelihoods. [[check]]
Common Mistakes:
3. In the context of Support Vector Machines, what is the primary purpose of the margin?
easy
Solution
Step 1: Understand the role of the margin
The margin in SVM is the distance between the decision boundary and the nearest data points from either class.Step 2: Eliminate wrong options
To minimize the number of support vectors is incorrect because the number of support vectors is not minimized. To ensure the model is non-linear is incorrect because the margin itself does not ensure non-linearity. To reduce the dimensionality of the data is incorrect because the margin does not reduce dimensionality.Final Answer:
Option B -> Option BQuick Check:
Margin maximizes boundary distance [OK]
Hint: Margin maximizes boundary distance [OK]
Common Mistakes:
4. A model trained on a dataset shows unexpected bias against a minority group. What is the most likely root cause?
medium
Solution
Step 1: Identify the symptom.
Bias against a minority group indicates potential data imbalance.Step 2: Analyze the options.
Imbalanced data (B) is a common cause of bias. Other options relate to model complexity or training dynamics, not bias directly.Final Answer:
Option A -> Option AQuick Check:
Imbalanced data often leads to bias. [OK]
Hint: Imbalanced data often leads to bias. [OK]
Common Mistakes:
5. You are tasked with deploying a real-time fraud detection system. Which approach would you choose to handle class imbalance effectively without significantly increasing latency?
hard
Solution
Step 1: Consider latency constraints.
Real-time systems require low-latency solutions.Step 2: Evaluate focal loss.
Focal loss can be integrated into the model without affecting real-time processing speed.Final Answer:
Option C -> Option CQuick Check:
Focal loss suits real-time needs. [OK]
Hint: Focal loss suits real-time needs. [OK]
Common Mistakes:
