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]
import numpy as np
business_goals = np.array(['increase sales', 'reduce churn', 'improve satisfaction'])
ml_problems = np.array(['classification', 'regression', 'clustering'])
result = np.char.add(business_goals, ml_problems)
print(result)Solution
Step 1: Understand the operation
The np.char.add function concatenates corresponding elements of two arrays element-wise.Step 2: Eliminate wrong options
['increase sales', 'reduce churn', 'improve satisfaction'] and C are incorrect because they ignore the concatenation operation. Throws an error due to incompatible types is incorrect because np.char.add handles string arrays correctly.Final Answer:
Option A -> Option AQuick Check:
np.char.add concatenates strings element-wise. [OK]
Solution
Step 1: Understand the methods
Causal inference helps understand the cause-effect relationship, not just performance.Step 2: Eliminate wrong options
Holdout is not inherently less accurate or unsuitable for large datasets. Causal inference is not necessarily faster.Final Answer:
Option C -> Option CQuick Check:
Causal inference explains why, not just what. [OK]
Solution
Step 1: Identify symptoms of vanishing gradients
Extremely small gradients often indicate the vanishing gradient problem, typically caused by certain activation functions like sigmoid or tanh.Step 2: Eliminate wrong options
The learning rate is too high. is incorrect because a high learning rate would cause divergence. The network is too shallow. is incorrect because a shallow network is less prone to vanishing gradients. The dataset is too small. is unrelated to gradient size.Final Answer:
Option C -> Option CQuick Check:
Small gradients often mean vanishing issue. [OK]
Solution
Step 1: Consider latency constraints.
Embedded methods integrate feature selection into model training, optimizing for both accuracy and speed.Step 2: Eliminate wrong options.
Filter methods do not consider model performance. Wrapper methods and recursive feature elimination are too slow for real-time systems.Final Answer:
Option B -> Option BQuick Check:
Embedded = fast, integrated. [OK]
