Practice
from sklearn.metrics import precision_score, recall_score, f1_score
y_true = [0, 1, 1, 0, 1, 1, 0]
y_pred = [0, 1, 0, 0, 1, 1, 1]
precision = precision_score(y_true, y_pred)
recall = recall_score(y_true, y_pred)
f1 = f1_score(y_true, y_pred)
print(f"Precision: {precision}, Recall: {recall}, F1: {f1}")What will be the output of this code?Solution
Step 1: Calculate precision.
Precision = TP / (TP + FP) = 2 / (2 + 1) = 0.67Step 2: Calculate recall.
Recall = TP / (TP + FN) = 2 / (2 + 2) = 0.50Step 3: Calculate F1 score.
F1 = 2 * (Precision * Recall) / (Precision + Recall) = 0.57Final Answer:
Option D -> Option DQuick Check:
Precision and recall calculations are key. [OK]
import numpy as np
labels = np.array(['cat', 'dog', 'cat', 'dog'])
heuristics = np.array([1, 0, 1, 0])
weak_labels = np.where(heuristics == 1, 'cat', 'dog')
print(weak_labels)Solution
Step 1: Analyze the code.
The code uses np.where to assign 'cat' where heuristics is 1 and 'dog' where it is 0.Step 2: Determine the output.
Since heuristics is [1, 0, 1, 0], the output will be ['cat', 'dog', 'cat', 'dog'].Final Answer:
Option B -> Option BQuick Check:
np.where logic: match heuristics [OK]
Solution
Step 1: Compare GELU and ReLU characteristics.
GELU provides smoother gradients due to its probabilistic nature, which can help in convergence.Step 2: Evaluate each option.
GELU is not cheaper (A), doesn't entirely avoid dying neurons (C), and isn't more interpretable (D).Final Answer:
Option D -> Option DQuick Check:
GELU smooths gradients, aids convergence. [OK]
Solution
Step 1: Analyze the symptom
If a model's accuracy plateaus, it often indicates that the model has reached its capacity to learn from the data.Step 2: Eliminate wrong options
Options A and B would show different symptoms like oscillating loss or high training error. The dataset is too small would likely cause overfitting, not a plateau.Final Answer:
Option A -> Option AQuick Check:
Plateau = model capacity limit [OK]
Solution
Step 1: Identify the symptom.
High variance in predictions suggests the model is not generalizing well.Step 2: Determine the most likely cause.
Data drift, where the input data distribution changes over time, is a common cause of unexpected behavior in production.Final Answer:
Option D -> Option DQuick Check:
Data drift causes unexpected variance. [OK]
