Practice
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = LogisticRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print(accuracy_score(y_test, y_pred))Solution
Step 1: Understand the impact of data leakage
Data leakage often results in overly optimistic performance metrics.Step 2: Analyze the code behavior
The code will execute without errors, but if leakage exists, the model will perform better than it should.Final Answer:
Option D -> Option DQuick Check:
Leakage inflates accuracy [OK]
from tokenizers import Tokenizer
from tokenizers.models import BPE
from tokenizers.pre_tokenizers import Whitespace
# Initialize a BPE tokenizer
bpe_tokenizer = Tokenizer(BPE())
bpe_tokenizer.pre_tokenizer = Whitespace()
# Train the tokenizer
bpe_tokenizer.train(["hello world", "hello there"], vocab_size=10)
# Encode a sentence
output = bpe_tokenizer.encode("hello world")
print(output.tokens)Solution
Step 1: Understand BPE tokenization with whitespace pre-tokenization.
BPE with whitespace pre-tokenization will initially split on spaces.Step 2: Analyze the output of the encode method.
The sentence 'hello world' is tokenized as ['hello', 'world'] due to whitespace splitting.Final Answer:
Option D -> Option DQuick Check:
BPE with whitespace splits on spaces first. [OK]
Solution
Step 1: Analyze the impact of standardization on model performance.
Standardization centers data around zero, which can affect models sensitive to feature means.Step 2: Identify the potential issue.
Some models may perform poorly if they rely on the original mean of the data.Final Answer:
Option A -> Option AQuick Check:
Model sensitive to mean? Standardization affects it. [OK]
Solution
Step 1: Understand metric differences
NDCG considers the position of relevant items, giving higher weight to top-ranked items.Step 2: Eliminate wrong options
MAP considers all relevant items equally, NDCG is not necessarily easier or more interpretable, and both metrics are sensitive to the number of relevant items.Final Answer:
Option C -> Option CQuick Check:
NDCG weights top positions more. [OK]
Solution
Step 1: Identify symptoms of vanishing gradient.
Early plateauing of loss often indicates vanishing gradients.Step 2: Eliminate other causes.
High learning rate (A) would cause erratic loss, overfitting (B) would show low training loss, and small dataset (D) would not cause early plateau.Final Answer:
Option C -> Option CQuick Check:
Early plateau = vanishing gradient. [check]
