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 torch.nn as nn
import torch
class SimpleGNNLayer(nn.Module):
def __init__(self, in_features, out_features):
super(SimpleGNNLayer, self).__init__()
self.linear = nn.Linear(in_features, out_features)
def forward(self, x, adj):
return torch.matmul(adj, self.linear(x))
x = torch.randn(5, 10)
adj = torch.eye(5)
gnn_layer = SimpleGNNLayer(10, 20)
output = gnn_layer(x, adj)Solution
Step 1: Understand the operations
The linear layer transforms the input features from 10 to 20 dimensions.Step 2: Apply the adjacency matrix
The adjacency matrix is used to aggregate features, maintaining the node count.Final Answer:
Option A -> Option AQuick Check:
Linear layer changes feature dim, adj keeps node count. [check]
Solution
Step 1: Consider dataset size and model complexity.
Small datasets are prone to overfitting with complex models.Step 2: Evaluate the impact of each option.
Polynomial features (A, C) increase complexity significantly, leading to overfitting. Interaction terms (B, D) add complexity but less than polynomial features, making them more suitable for small datasets.Final Answer:
Option D -> Option DQuick Check:
Small data: prefer interaction terms to avoid overfitting. [OK]
Solution
Step 1: Identify the effect of high alpha in Lasso.
High alpha increases regularization strength, leading to high bias.Step 2: Eliminate wrong options.
Large datasets do not cause overfitting. High complexity increases variance, not bias. Non-normalized features affect scale, not bias directly.Final Answer:
Option D -> Option DQuick Check:
High alpha = high bias in Lasso. [OK]
Solution
Step 1: Consider the requirements for multilingual tokenization.
SentencePiece is designed to handle multiple scripts and does not rely on whitespace, making it suitable for multilingual models.Step 2: Eliminate wrong options.
BPE (A) and WordPiece (B) are less effective with diverse scripts; character-level (D) is too granular and inefficient.Final Answer:
Option B -> Option BQuick Check:
SentencePiece handles scripts without whitespace. [OK]
