Practice
1. In the context of model calibration, which metric is most appropriate to evaluate the probability outputs of a classifier?
easy
Solution
Step 1: Identify the purpose of calibration.
Calibration aims to ensure that predicted probabilities reflect true likelihoods.Step 2: Evaluate each metric.
Accuracy, precision, and F1 score do not consider probability estimates, only classification decisions. Log Loss penalizes incorrect probability estimates, making it suitable for calibration.Final Answer:
Option C -> Option CQuick Check:
Log Loss evaluates probability accuracy. [OK]
Hint: Log Loss evaluates probability accuracy. [OK]
Common Mistakes:
2. Given the following Python code snippet using a pre-trained YOLO model, what will be the output shape of the detection results?
import torch
from torchvision.models.detection import yolo_v3
model = yolo_v3(pretrained=True)
model.eval()
input_tensor = torch.rand(1, 3, 416, 416)
output = model(input_tensor)
print(output[0]['boxes'].shape)easy
Solution
Step 1: Understand YOLO output
YOLO outputs a list of detections, each with a bounding box of 4 coordinates.Step 2: Determine output shape
The shape is (N, 4) where N is the number of detected objects.Final Answer:
Option B -> Option BQuick Check:
YOLO boxes = (N, 4) [OK]
Hint: YOLO boxes = (N, 4) [OK]
Common Mistakes:
3.
import shap
import xgboost
# Load data
X, y = shap.datasets.boston()
# Train model
model = xgboost.XGBRegressor().fit(X, y)
# Explain the model's predictions using SHAP
explainer = shap.Explainer(model, X)
shap_values = explainer(X)
# What is the shape of shap_values?easy
Solution
Step 1: Understand SHAP output.
SHAP values are calculated for each feature of each instance.Step 2: Determine the shape based on input data.
The dataset has 506 instances and 13 features, so SHAP values will have the shape (506, 13).Final Answer:
Option C -> Option CQuick Check:
SHAP values match data shape: (instances, features). [OK]
Hint: SHAP values match data shape: (instances, features). [OK]
Common Mistakes:
4.
from sklearn.ensemble import RandomForestClassifier
import numpy as np
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
y = np.array([0, 1, 0, 1])
model = RandomForestClassifier(n_estimators=1, max_features=1, bootstrap=False)
model.fit(X, y)
print(model.estimators_[0].tree_.feature)What does this code output?easy
Solution
Step 1: Analyze the code
The RandomForestClassifier is set with max_features=1, meaning each tree considers only one feature for splitting.Step 2: Determine the output
Since bootstrap=False, the entire dataset is used, and the tree will choose one feature. The output shows the feature index used for splitting.Final Answer:
Option C -> Option CQuick Check:
max_features=1 limits to one feature. [OK]
Hint: max_features=1 limits to one feature. [OK]
Common Mistakes:
5. A model trained on a dataset is performing exceptionally well on the test set but poorly on new unseen data. What is the most likely cause?
medium
Solution
Step 1: Analyze the symptoms
High test performance but poor real-world performance suggests leakage.Step 2: Eliminate other causes
The model is overfitting due to too many parameters. would affect both test and real-world data, The model has not been trained for enough epochs. would not cause high test performance, The feature scaling was not applied correctly. would affect all data equally.Final Answer:
Option B -> Option BQuick Check:
High test, low real-world = leakage [OK]
Hint: High test, low real-world = leakage [OK]
Common Mistakes:
