Practice
1. What is the time complexity of the K-Means clustering algorithm implemented from scratch using Lloyd's algorithm?
easy
Solution
Step 1: Analyze the algorithm
The time complexity is determined by the number of data points (n), clusters (k), dimensions (d), and iterations (i).Step 2: Eliminate wrong options
O(n^2) and C are incorrect as they don't account for k, d, and i. O(k^2) is incorrect because it doesn't consider n, d, and i.Final Answer:
Option A -> Option AQuick Check:
Consider n, k, d, and i for complexity. [OK]
Hint: Consider n, k, d, and i for complexity. [OK]
Common Mistakes:
2. What is the time complexity of calculating DCG for a list of n relevance scores?
easy
Solution
Step 1: Analyze the DCG Calculation
DCG involves iterating over the list once and performing constant-time operations for each element.Step 2: Determine Complexity
Since each element is processed once, the complexity is O(n).Final Answer:
Option A -> Option AQuick Check:
DCG iterates once over n elements. [OK]
Hint: DCG iterates once over n elements. [OK]
Common Mistakes:
3.
import numpy as np
from sklearn.model_selection import train_test_split
X = np.array([1, 2, 3, 4, 5, 6])
y = np.array([0, 0, 1, 1, 0, 1])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, stratify=y)
print(y_train)easy
Solution
Step 1: Understand stratification
Stratification ensures that the class distribution in the train and test sets is similar to the original dataset.Step 2: Calculate class distribution
Original y has 3 zeros and 3 ones. With stratification, y_train should have 1 zero and 2 ones.Final Answer:
Option D -> Option DQuick Check:
Stratify maintains class distribution. [OK]
Hint: Stratify maintains class distribution. [OK]
Common Mistakes:
4. In a text classification task using Multinomial Naive Bayes, which preprocessing step is crucial for improving model performance?
medium
Solution
Step 1: Understand text preprocessing needs
In text classification, irrelevant words can add noise.Step 2: Evaluate preprocessing steps
Removing stop words (Removing stop words) reduces noise and improves performance. Options A and C are less relevant as MultinomialNB doesn't require normalized or scaled features. Applying PCA for dimensionality reduction is unnecessary as PCA isn't typically used for text data.Final Answer:
Option C -> Option CQuick Check:
Remove stop words to reduce noise in text data. [OK]
Hint: Remove stop words to reduce noise in text data. [OK]
Common Mistakes:
5. How can you optimize the memory usage of a Min-Max scaling implementation for a large dataset?
hard
Solution
Step 1: Identify Memory Bottlenecks
Loading large datasets entirely into memory can be inefficient.Step 2: Optimize Memory Usage
Processing data in chunks reduces memory footprint, making it feasible to handle large datasets.Final Answer:
Option A -> Option AQuick Check:
Chunk processing saves memory. [OK]
Hint: Chunk processing saves memory. [OK]
Common Mistakes:
