Practice
1. Given the following Python code snippet for a segmentation task, what will be the output shape if the input image shape is (256, 256, 3) and the model outputs a segmentation map with 10 classes?
import numpy as np
input_image = np.random.rand(256, 256, 3)
model_output = np.random.rand(256, 256, 10)easy
Solution
Step 1: Understand the model output
The model outputs a segmentation map with a shape corresponding to the input spatial dimensions and the number of classes.Step 2: Eliminate wrong options
(256, 256, 3) is the input shape, (256, 256, 1) implies binary segmentation, and (256, 256) lacks class dimension.Final Answer:
Option A -> Option AQuick Check:
Output shape = Input spatial + class channels [OK]
Hint: Output shape = Input spatial + class channels [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 evaluating models on imbalanced datasets, which metric is more sensitive to changes in the minority class predictions?
easy
Solution
Step 1: Understand metric sensitivity
PR-AUC focuses on precision and recall, which are directly affected by the minority class predictions.Step 2: Eliminate wrong options
ROC-AUC is less sensitive to class imbalance. Accuracy can be misleading in imbalanced datasets. F1-Score is related but not as directly sensitive as PR-AUC.Final Answer:
Option C -> Option CQuick Check:
PR-AUC focuses on minority class. [OK]
Hint: PR-AUC focuses on minority class. [OK]
Common Mistakes:
4.
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(1, input_dim=2, activation='relu'))
model.add(Dense(1, activation='relu'))
weights = model.get_weights()
print([w.shape for w in weights])What does this code output?easy
Solution
Step 1: Analyze the network structure
The first layer has 2 inputs and 1 output, so weights are (2, 1) and biases are (1,). The second layer has 1 input and 1 output, so weights are (1, 1) and biases are (1,).Step 2: Eliminate wrong options
[(2, 1), (1,), (1, 2), (1,)] is incorrect because the second layer's weights should be (1, 1). [(1, 2), (1,), (1, 1), (1,)] is incorrect because the first layer's weights should be (2, 1). [(2, 1), (2,), (1, 1), (1,)] is incorrect because the first layer's biases should be (1,).Final Answer:
Option A -> Option AQuick Check:
Check layer dimensions match input/output. [OK]
Hint: Check layer dimensions match input/output. [OK]
Common Mistakes:
5. How would you adapt K-Means to handle a dataset with categorical features?
hard
Solution
Step 1: Understand K-Means limitations
K-Means is not suitable for categorical data as it relies on Euclidean distance.Step 2: Choose the right adaptation
K-Modes is designed for clustering categorical data, making it the best choice.Final Answer:
Option B -> Option BQuick Check:
K-Modes for categorical data [OK]
Hint: K-Modes for categorical data [OK]
Common Mistakes:
