Practice
1.
import torch
x = torch.tensor([-1.0, 0.0, 1.0])
output = torch.nn.functional.relu(x)
print(output)What is the output of this code?easy
Solution
Step 1: Understand ReLU behavior.
ReLU outputs zero for negative inputs and the input itself for non-negative inputs.Step 2: Apply ReLU to each element.
For -1.0, output is 0.0; for 0.0, output is 0.0; for 1.0, output is 1.0.Final Answer:
Option A -> Option AQuick Check:
ReLU zeros negatives, keeps positives. [OK]
Hint: ReLU zeros negatives, keeps positives. [OK]
Common Mistakes:
2.
import numpy as np
from sklearn.model_selection import train_test_split
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
y = np.array([0, 1, 0, 1])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
print(X_train.shape, X_test.shape)What is the output of this code snippet?easy
Solution
Step 1: Understand train_test_split behavior.
With test_size=0.5, the data is split equally into train and test sets.Step 2: Calculate expected shapes.
Original data has 4 samples, so both train and test sets will have 2 samples each.Final Answer:
Option C -> Option CQuick Check:
Equal split with test_size=0.5. [OK]
Hint: Equal split with test_size=0.5. [OK]
Common Mistakes:
3.
import numpy as np
x = np.array([1, 2, 3])
y = np.array([4, 5, 6])
result = np.dot(x, y)
print(result)What does this code output?easy
Solution
Step 1: Understand the dot product operation.
The dot product of two vectors is the sum of the products of their corresponding elements.Step 2: Calculate the dot product.
(1*4) + (2*5) + (3*6) = 32.Final Answer:
Option C -> Option CQuick Check:
Dot product sums element-wise products. [OK]
Hint: Dot product sums element-wise products. [OK]
Common Mistakes:
4. A machine learning model is consistently overfitting on a dataset. What is the most likely cause?
medium
Solution
Step 1: Identify symptoms of overfitting.
Overfitting occurs when a model learns noise instead of the signal.Step 2: Determine the cause related to model complexity.
Too many parameters can lead to overfitting by capturing noise.Final Answer:
Option B -> Option BQuick Check:
Overfitting often means too complex a model. [OK]
Hint: Overfitting often means too complex a model. [OK]
Common Mistakes:
5. How would you adapt a decision tree to handle a dataset with a large number of categorical features?
hard
Solution
Step 1: Identify the best adaptation method.
Some decision tree algorithms, like C4.5, handle categorical features natively.Step 2: Eliminate wrong options.
One-hot encoding can lead to high dimensionality, label encoding can mislead the model, and PCA is not suitable for categorical data.Final Answer:
Option A -> Option AQuick Check:
Use native categorical support in trees. [OK]
Hint: Use native categorical support in trees. [OK]
Common Mistakes:
