Practice
import numpy as np
class ContinualLearner:
def __init__(self):
self.model = None
def update(self, new_data):
if self.model is None:
self.model = new_data
else:
self.model += new_data
learner = ContinualLearner()
learner.update(np.array([1, 2, 3]))
learner.update(np.array([4, 5, 6]))
print(learner.model)What does this code output?Solution
Step 1: Understand the update mechanism.
The code initializes the model with the first data and adds subsequent data to it.Step 2: Calculate the output.
First update sets model to [1, 2, 3]. Second update adds [4, 5, 6], resulting in [5, 7, 9].Final Answer:
Option A -> Option AQuick Check:
First set, then add. [OK]
Solution
Step 1: Understand the impact of outliers on metrics.
MAE is less sensitive to outliers compared to MSE and RMSE because it doesn't square the errors.Step 2: Eliminate wrong options.
MSE and RMSE are sensitive to outliers due to squaring errors. MAPE is not suitable for zero or near-zero values.Final Answer:
Option D -> Option DQuick Check:
MAE handles outliers better than MSE. [OK]
Solution
Step 1: Understand the No Free Lunch Theorem
The theorem states that no single model is universally best across all datasets.Step 2: Eliminate wrong options
A model that performs well on one dataset will perform well on all datasets. is incorrect because model performance varies by dataset. The best model for a dataset can be determined without testing. is incorrect because testing is necessary to determine the best model. A complex model always outperforms a simple model. is incorrect because complexity does not guarantee better performance.Final Answer:
Option B -> Option BQuick Check:
No universal best model. [OK]
Solution
Step 1: Analyze the problem
Poor performance on a specific slice often indicates distribution mismatch.Step 2: Eliminate wrong options
The model is overfitting to the training data. is incorrect as overfitting would affect overall performance. The model has too many parameters. is unrelated to slice-specific issues. The learning rate is too high. affects convergence, not slice performance.Final Answer:
Option A -> Option AQuick Check:
Slice mismatch = distribution issue. [OK]
Solution
Step 1: Consider latency constraints.
Real-time systems require low-latency solutions.Step 2: Evaluate focal loss.
Focal loss can be integrated into the model without affecting real-time processing speed.Final Answer:
Option C -> Option CQuick Check:
Focal loss suits real-time needs. [OK]
