Practice
from sklearn.naive_bayes import GaussianNB
import numpy as np
X = np.array([[1, 2], [2, 3], [3, 4]])
y = np.array([1, 0, 1])
model = GaussianNB()
model.fit(X, y)
print(model.predict([[2, 2]]))Solution
Step 1: Understand the Code Execution
The code fits a Gaussian Naive Bayes model and predicts the class for a new sample [2, 2].Step 2: Analyze the Prediction
Given the training data, the model predicts class 1 for [2, 2] based on the likelihoods.Final Answer:
Option A -> Option AQuick Check:
GaussianNB predicts based on likelihoods. [[check]]
Solution
Step 1: Identify overfitting causes.
Overfitting often occurs when the model is too complex, such as a deep tree.Step 2: Eliminate wrong options.
A shallow tree would underfit, a small dataset affects generalization but not directly overfitting, and uninformative features would lead to poor performance, not overfitting.Final Answer:
Option D -> Option DQuick Check:
Deep trees overfit easily. [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]
Solution
Step 1: Consider real-time constraints
Real-time systems need to adapt to new data while maintaining performance.Step 2: Evaluate options for adaptability and efficiency
Use a single train-test split to minimize latency. risks overfitting. Use a large test set to ensure model robustness. misallocates resources. Use a static validation set to simplify the system. lacks adaptability to new data.Final Answer:
Option D -> Option DQuick Check:
Rolling window adapts to new data efficiently. [OK]
Solution
Step 1: Identify the best adaptation method.
Some decision tree algorithms, like C4.5, handle categorical features natively.Step 2: Eliminate wrong options.
One-hot encoding can lead to high dimensionality, label encoding can mislead the model, and PCA is not suitable for categorical data.Final Answer:
Option A -> Option AQuick Check:
Use native categorical support in trees. [OK]
