Practice
1.
from sklearn.tree import DecisionTreeClassifier
import numpy as np
X = np.array([[0, 0], [1, 1], [1, 0], [0, 1]])
y = np.array([0, 1, 1, 0])
clf = DecisionTreeClassifier(criterion='gini')
clf.fit(X, y)
print(clf.predict([[0, 0], [1, 1]]))What is the output of the above code?easy
Solution
Step 1: Understand the training data.
The data is perfectly separable, and the decision tree will learn to classify based on the given labels.Step 2: Predict using the trained model.
For input [0, 0], the label is 0, and for [1, 1], the label is 1.Final Answer:
Option C -> Option CQuick Check:
Check training labels for predictions. [OK]
Hint: Check training labels for predictions. [OK]
Common Mistakes:
2. In the context of high-dimensional data, which of the following is a primary reason why the curse of dimensionality affects nearest neighbor algorithms?
easy
Solution
Step 1: Understand the curse of dimensionality.
In high dimensions, the distance between points becomes less informative.Step 2: Eliminate wrong options.
High-dimensional data increases the risk of overfitting. is about overfitting, not distance. High-dimensional data requires more computational resources. is about computation, not distance. High-dimensional data leads to more complex decision boundaries. is about decision boundaries, not distance.Final Answer:
Option A -> Option AQuick Check:
High dimensions dilute distance meaning. [OK]
Hint: High dimensions dilute distance meaning. [OK]
Common Mistakes:
3. When comparing two ML models using A/B testing, why might you choose causal inference over the holdout method?
medium
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]
Hint: Causal inference explains why, not just what. [OK]
Common Mistakes:
4. A model trained on offline data is underperforming when deployed in a real-time environment. What is the most likely cause?
medium
Solution
Step 1: Identify the mismatch between training and deployment
Models trained on offline data may not handle real-time data well due to differences in data characteristics.Step 2: Eliminate unrelated causes
Options A, C, and D do not specifically address the real-time processing capability issue.Final Answer:
Option C -> Option CQuick Check:
Offline-trained models may struggle with real-time data. [OK]
Hint: Offline-trained models may struggle with real-time data. [OK]
Common Mistakes:
5. In a recommendation system, how would you apply feature engineering to improve the model's ability to capture user-item interactions?
hard
Solution
Step 1: Identify the need for capturing interactions.
Recommendation systems benefit from understanding user-item interactions.Step 2: Evaluate feature engineering techniques.
Collaborative filtering (A) is a model, not feature engineering. One-hot encoding (B) doesn't capture interactions. Normalizing (D) doesn't enhance interaction capture. Interaction terms (C) explicitly model user-item interactions, improving the system's ability to recommend.Final Answer:
Option A -> Option AQuick Check:
Interaction terms enhance user-item interaction capture. [OK]
Hint: Interaction terms enhance user-item interaction capture. [OK]
Common Mistakes:
