MauryaHub PYQ Practice

Machine Learning Practice · Quiz 2 · May 2024

Machine Learning Practice · Quiz 2 · May 2024

← Course papers · Start practice / exam

Questions and published explanations below are available without starting a test. Some questions may not have a published solution yet.

22 / 22 published solutions

Question 123 MCQ · 3.0 marks

Source diagram or notation
6406532867229.
[0, 1, 1]
6406532867230.
[0, 2, 1]
6406532867231.
[0, 0, 1]
6406532867232.
[0, 0, 2]

Published solution

**Answer: C** **Topic:** Polynomial Regression — *Coefficients of LinearRegression on Degree-2 PolynomialFeatures* ### Step-by-Step Solution **Step 1:** In the given code, $X = [1, 2, 3, 4, 5]^T$ and $y = [1, 4, 9, 16, 25]^T = X^2$. **Step 2:** `PolynomialFeatures(degree=2, interaction_only=False)` (with default `include_bias=True`) generates the 3 features $[1, x, x^2]$ for each sample. **Step 3:** When `LinearRegression().fit(X_poly, y)` fits $y = 1 \cdot x^2$, the intercept is `0` and the coefficients `model.coef_` corresponding to the 3 columns $[1, x, x^2]$ are: - Coefficient for bias column $1$: `0` - Coefficient for linear column $x$: `0` - Coefficient for quadratic column $x^2$: `1` **Step 4:** Therefore, `print(model.coef_)` outputs **`[0, 0, 1]`**, which matches **C**. **Key Takeaway / Tip:** By default, `PolynomialFeatures(degree=2)` prepends a constant bias column of `1`s as Column 0, so `model.coef_` has 3 entries `[0, 0, 1]` corresponding to $[1, x, x^2]$. A: **Incorrect:** Option A ([0, 1, 1]) does not satisfy the conditions derived in the step-by-step analysis for Coefficients of LinearRegression on Degree-2 PolynomialFeatures (correct choice: C). B: **Incorrect:** Option B ([0, 2, 1]) does not satisfy the conditions derived in the step-by-step analysis for Coefficients of LinearRegression on Degree-2 PolynomialFeatures (correct choice: C). C: **Correct:** Option C ([0, 0, 1]) matches our derived result under Coefficients of LinearRegression on Degree-2 PolynomialFeatures. By default, `PolynomialFeatures(degree=2)` prepends a constant bias column of `1`s as Column 0, so `model.coef_` has 3 entries `[0, 0, 1]` corresponding to $[1, x, x^2]$. D: **Incorrect:** Option D ([0, 0, 2]) does not satisfy the conditions derived in the step-by-step analysis for Coefficients of LinearRegression on Degree-2 PolynomialFeatures (correct choice: C).

Report a correction for Q123

Question 124 MCQ · 3.0 marks

What is ‘naive’ assumption in classifiers based on Naive Bayes?
6406532867279.
All the classes are conditionally independent of each other.
6406532867280.
All the classes are conditionally dependent on each other.
6406532867281.
All the features are conditionally dependent on each other.
6406532867282.
All the features are conditionally independent of each other.

Published solution

**Answer: D** **Topic:** Naive Bayes — *Conditional Independence Assumption in Naive Bayes* ### Step-by-Step Solution **Step 1:** Recall the foundational **'naive'** assumption of a Naive Bayes classifier: given the class label $Y$, all input features $X_1, X_2, \dots, X_d$ are assumed to be **conditionally independent** of one another: $$P(X_1, \dots, X_d \mid Y) = \prod_{j=1}^d P(X_j \mid Y)$$ **Step 2:** Compare with the options: - **D**: 'All the features are conditionally independent of each other' — **Correct**. **Step 3:** Therefore, **D** is correct. **Key Takeaway / Tip:** Naive Bayes assumes conditional independence among the **features** given the class, not independence among the classes. A: **Incorrect:** Option A (All the classes are conditionally independent of each other.) does not satisfy the conditions derived in the step-by-step analysis for Conditional Independence Assumption in Naive Bayes (correct choice: D). B: **Incorrect:** Option B (All the classes are conditionally dependent on each other.) does not satisfy the conditions derived in the step-by-step analysis for Conditional Independence Assumption in Naive Bayes (correct choice: D). C: **Incorrect:** Option C (All the features are conditionally dependent on each other.) does not satisfy the conditions derived in the step-by-step analysis for Conditional Independence Assumption in Naive Bayes (correct choice: D). D: **Correct:** Option D (All the features are conditionally independent of each other.) matches our derived result under Conditional Independence Assumption in Naive Bayes. Naive Bayes assumes conditional independence among the **features** given the class, not independence among the classes.

Report a correction for Q124

Question 125 MCQ · 3.0 marks

Source diagram or notation
6406532867283.
cv
6406532867284.
reg_rate
6406532867285.
alpha
6406532867286.
tol
6406532867287.
lambda
6406532867288.
None of these

Published solution

**Answer: C** **Topic:** Linear Classifiers — *Controlling Regularization Strength in RidgeClassifier* ### Step-by-Step Solution **Step 1:** In `sklearn.linear_model.RidgeClassifier` (and `Ridge`), the $L_2$ regularization strength hyperparameter is named **`alpha`**. **Step 2:** Setting `alpha=0` applies no regularization (reducing to unregularized least-squares classification). **Step 3:** Therefore, the missing attribute name is **`alpha`** (**C**). **Key Takeaway / Tip:** In `scikit-learn`, `Ridge`, `Lasso`, `ElasticNet`, and `SGDClassifier` all use the parameter name `alpha` for regularization strength. A: **Incorrect:** Option A (cv) does not satisfy the conditions derived in the step-by-step analysis for Controlling Regularization Strength in RidgeClassifier (correct choice: C). B: **Incorrect:** Option B (reg_rate) does not satisfy the conditions derived in the step-by-step analysis for Controlling Regularization Strength in RidgeClassifier (correct choice: C). C: **Correct:** Option C (alpha) matches our derived result under Controlling Regularization Strength in RidgeClassifier. In `scikit-learn`, `Ridge`, `Lasso`, `ElasticNet`, and `SGDClassifier` all use the parameter name `alpha` for regularization strength. D: **Incorrect:** Option D (tol) does not satisfy the conditions derived in the step-by-step analysis for Controlling Regularization Strength in RidgeClassifier (correct choice: C). E: **Incorrect:** Option E (lambda) does not satisfy the conditions derived in the step-by-step analysis for Controlling Regularization Strength in RidgeClassifier (correct choice: C). F: **Incorrect:** Option F (None of these) does not satisfy the conditions derived in the step-by-step analysis for Controlling Regularization Strength in RidgeClassifier (correct choice: C).

Report a correction for Q125

Question 126 MCQ · 2.0 marks

What is the effect of increasing the regularization parameter alpha in **Ridge Regression**?
6406532867233.
It increases the complexity of the model.
6406532867234.
It reduces the complexity of the model.
6406532867235.
It has no effect on the model.
6406532867236.
It increases the model’s sensitivity to the training data.

Published solution

**Answer: B** **Topic:** Regularized Regression — *Effect of Increasing alpha in Ridge Regression* ### Step-by-Step Solution **Step 1:** In **Ridge Regression**, the objective function is $\|Xw - y\|_2^2 + \alpha \|w\|_2^2$. **Step 2:** As the regularization parameter `alpha` ($\alpha$) **increases**, the penalty on the squared magnitude of the weights $\|w\|_2^2$ becomes stronger, shrinking the coefficients toward zero and **reducing the complexity (variance) of the model**. **Step 3:** Therefore, **B** (`It reduces the complexity of the model`) is correct. **Key Takeaway / Tip:** Increasing `alpha` in Ridge or Lasso strengthens regularization, shrinking weights and reducing model complexity. A: **Incorrect:** Option A (It increases the complexity of the model.) does not satisfy the conditions derived in the step-by-step analysis for Effect of Increasing alpha in Ridge Regression (correct choice: B). B: **Correct:** Option B (It reduces the complexity of the model.) matches our derived result under Effect of Increasing alpha in Ridge Regression. Increasing `alpha` in Ridge or Lasso strengthens regularization, shrinking weights and reducing model complexity. C: **Incorrect:** Option C (It has no effect on the model.) does not satisfy the conditions derived in the step-by-step analysis for Effect of Increasing alpha in Ridge Regression (correct choice: B). D: **Incorrect:** Option D (It increases the model’s sensitivity to the training data.) does not satisfy the conditions derived in the step-by-step analysis for Effect of Increasing alpha in Ridge Regression (correct choice: B).

Report a correction for Q126

Question 127 MCQ · 2.0 marks

Source diagram or notation
6406532867237.
The importance of each feature in predicting the target.
6406532867238.
The residuals of the model.
6406532867239.
The intercept of the regression line.
6406532867240.
It represents the values of hyperparameters of the model.

Published solution

**Answer: A** **Topic:** Linear Regression — *Interpretation of model.coef_ in LinearRegression* ### Step-by-Step Solution **Step 1:** In `sklearn.linear_model.LinearRegression`, after calling `model.fit(X, y)`, the attribute `model.coef_` stores the learned weight (slope) $w_j$ for each input feature $X_j$. **Step 2:** Each coefficient $w_j$ quantifies the expected change in the target per unit change in feature $j$ (holding other features constant), which represents **the importance/effect of each feature in predicting the target** (**A**). **Key Takeaway / Tip:** `model.coef_` contains the feature weights (slopes), while `model.intercept_` contains the bias term. A: **Correct:** Option A (The importance of each feature in predicting the target.) matches our derived result under Interpretation of model.coef_ in LinearRegression. `model.coef_` contains the feature weights (slopes), while `model.intercept_` contains the bias term. B: **Incorrect:** Option B (The residuals of the model.) does not satisfy the conditions derived in the step-by-step analysis for Interpretation of model.coef_ in LinearRegression (correct choice: A). C: **Incorrect:** Option C (The intercept of the regression line.) does not satisfy the conditions derived in the step-by-step analysis for Interpretation of model.coef_ in LinearRegression (correct choice: A). D: **Incorrect:** Option D (It represents the values of hyperparameters of the model.) does not satisfy the conditions derived in the step-by-step analysis for Interpretation of model.coef_ in LinearRegression (correct choice: A).

Report a correction for Q127

Question 128 MCQ · 2.0 marks

How can we use both **Ridge** and **Lasso** Regularization in a machine learning model?
6406532867241.
By setting **penalty** parameter to **l2**
6406532867242.
By setting **penalty** parameter to **l1**
6406532867243.
By setting **penalty** parameter to **elasticnet**
6406532867244.
By setting **penalty** parameter to **l3**

Published solution

**Answer: C** **Topic:** Regularized Regression — *Combining L1 and L2 Regularization via ElasticNet* ### Step-by-Step Solution **Step 1:** In `scikit-learn` linear models (such as `SGDClassifier`, `SGDRegressor`, and `LogisticRegression`), the `penalty` parameter accepts: - `'l2'`: Ridge ($L_2$) regularization only - `'l1'`: Lasso ($L_1$) regularization only - **`'elasticnet'`**: Combines **both Ridge ($L_2$) and Lasso ($L_1$)** regularization penalties. **Step 2:** Therefore, **C** (`By setting penalty parameter to elasticnet`) is correct. **Key Takeaway / Tip:** ElasticNet regularization combines both $L_1$ (Lasso) and $L_2$ (Ridge) penalties. A: **Incorrect:** Option A (By setting **penalty** parameter to **l2**) does not satisfy the conditions derived in the step-by-step analysis for Combining L1 and L2 Regularization via ElasticNet (correct choice: C). B: **Incorrect:** Option B (By setting **penalty** parameter to **l1**) does not satisfy the conditions derived in the step-by-step analysis for Combining L1 and L2 Regularization via ElasticNet (correct choice: C). C: **Correct:** Option C (By setting **penalty** parameter to **elasticnet**) matches our derived result under Combining L1 and L2 Regularization via ElasticNet. ElasticNet regularization combines both $L_1$ (Lasso) and $L_2$ (Ridge) penalties. D: **Incorrect:** Option D (By setting **penalty** parameter to **l3**) does not satisfy the conditions derived in the step-by-step analysis for Combining L1 and L2 Regularization via ElasticNet (correct choice: C).

Report a correction for Q128

Question 129 MCQ · 2.0 marks

Which of the following types of classification problems is being solved when a model predicts multiple labels(greater than 2) for each instance?
6406532867245.
Binary class, single label classification.
6406532867246.
Multi class, multi label classification.
6406532867247.
Binary class, multi label classification.
6406532867248.
Multi class, single label classification.

Published solution

**Answer: B** **Topic:** Multi-Label Classification — *Classification Problem Taxonomy for Multiple Labels per Instance* ### Step-by-Step Solution **Step 1:** When each instance can be simultaneously assigned **multiple labels** from a set of more than 2 possible classes/tags (for example, tagging an article or movie with multiple genres), the task is called **Multi-class, multi-label classification** (or simply multi-label classification). **Step 2:** Therefore, **B** (`Multi class, multi label classification`) is correct. **Key Takeaway / Tip:** Single-label classification assigns exactly 1 class per sample, whereas multi-label classification can assign multiple labels simultaneously to each sample. A: **Incorrect:** Option A (Binary class, single label classification.) does not satisfy the conditions derived in the step-by-step analysis for Classification Problem Taxonomy for Multiple Labels per Instance (correct choice: B). B: **Correct:** Option B (Multi class, multi label classification.) matches our derived result under Classification Problem Taxonomy for Multiple Labels per Instance. Single-label classification assigns exactly 1 class per sample, whereas multi-label classification can assign multiple labels simultaneously to each sample. C: **Incorrect:** Option C (Binary class, multi label classification.) does not satisfy the conditions derived in the step-by-step analysis for Classification Problem Taxonomy for Multiple Labels per Instance (correct choice: B). D: **Incorrect:** Option D (Multi class, single label classification.) does not satisfy the conditions derived in the step-by-step analysis for Classification Problem Taxonomy for Multiple Labels per Instance (correct choice: B).

Report a correction for Q129

Question 130 MCQ · 2.0 marks

Source diagram or notation
6406532867249.
The training data is split into 5 different datasets, each used to train a separate model.
6406532867250.
The model is trained and evaluated using 5-fold cross-validation for hyperparameter tuning
6406532867251.
Five different models are trained on 5 resampled datasets of training data.
6406532867252.
The dataset is divided into 5 parts and trained in a single pass without cross- validation.

Published solution

**Answer: B** **Topic:** Model Selection — *Meaning of cv=5 in GridSearchCV* ### Step-by-Step Solution **Step 1:** In `GridSearchCV(LogisticRegression(), param_grid, cv=5)`, the parameter `cv=5` specifies the cross-validation splitting strategy. **Step 2:** Setting `cv=5` means **the model is trained and evaluated using 5-fold cross-validation for hyperparameter tuning** (for each candidate hyperparameter combination in `param_grid`, the training data is split into 5 folds, training on 4 and validating on 1 five times). **Step 3:** Therefore, **B** is correct. **Key Takeaway / Tip:** In `GridSearchCV`, `cv=k` performs $k$-fold cross-validation on every candidate hyperparameter setting in `param_grid`. A: **Incorrect:** Option A (The training data is split into 5 different datasets, each used to train a separate model.) does not satisfy the conditions derived in the step-by-step analysis for Meaning of cv=5 in GridSearchCV (correct choice: B). B: **Correct:** Option B (The model is trained and evaluated using 5-fold cross-validation for hyperparameter tuning) matches our derived result under Meaning of cv=5 in GridSearchCV. In `GridSearchCV`, `cv=k` performs $k$-fold cross-validation on every candidate hyperparameter setting in `param_grid`. C: **Incorrect:** Option C (Five different models are trained on 5 resampled datasets of training data.) does not satisfy the conditions derived in the step-by-step analysis for Meaning of cv=5 in GridSearchCV (correct choice: B). D: **Incorrect:** Option D (The dataset is divided into 5 parts and trained in a single pass without cross- validation.) does not satisfy the conditions derived in the step-by-step analysis for Meaning of cv=5 in GridSearchCV (correct choice: B).

Report a correction for Q130

Question 131 MCQ · 2.0 marks

Source diagram or notation
6406532867253.
The number of correctly classified samples.
6406532867254.
The accuracy of the classifier.
6406532867255.
The loss function value.
6406532867256.
The number of misclassified samples.

Published solution

**Answer: B** **Topic:** Classification Metrics — *Default Metric Computed by Classifier .score() Method* ### Step-by-Step Solution **Step 1:** In `scikit-learn`, every classifier inheriting from `ClassifierMixin` (including `Perceptron`, `LogisticRegression`, `SVC`, etc.) implements a `.score(X_test, y_test)` method. **Step 2:** By default, `clf.score(X_test, y_test)` computes and returns **the mean accuracy of the classifier** on the given test data and labels. **Step 3:** Therefore, **B** (`The accuracy of the classifier`) is correct. **Key Takeaway / Tip:** For all `scikit-learn` classifiers, `.score(X, y)` returns classification **accuracy**; for all regressors, `.score(X, y)` returns the **$R^2$ score**. A: **Incorrect:** Option A (The number of correctly classified samples.) does not satisfy the conditions derived in the step-by-step analysis for Default Metric Computed by Classifier .score() Method (correct choice: B). B: **Correct:** Option B (The accuracy of the classifier.) matches our derived result under Default Metric Computed by Classifier .score() Method. For all `scikit-learn` classifiers, `.score(X, y)` returns classification **accuracy**; for all regressors, `.score(X, y)` returns the **$R^2$ score**. C: **Incorrect:** Option C (The loss function value.) does not satisfy the conditions derived in the step-by-step analysis for Default Metric Computed by Classifier .score() Method (correct choice: B). D: **Incorrect:** Option D (The number of misclassified samples.) does not satisfy the conditions derived in the step-by-step analysis for Default Metric Computed by Classifier .score() Method (correct choice: B).

Report a correction for Q131

Question 132 MCQ · 2.0 marks

Source diagram or notation
6406532867257.
Trains a single **Logistic Regression** model for all labels.
6406532867258.
Combines **Logistic Regression** with another model.
6406532867259.
Trains a separate **Logistic Regression** model for each label.
6406532867260.
Applies **Logistic Regression** in a one-vs-rest strategy for multi-class classification.

Published solution

**Answer: C** **Topic:** Multi-Label Classification — *How MultiOutputClassifier Wraps a Binary Estimator* ### Step-by-Step Solution **Step 1:** In `sklearn.multioutput.MultiOutputClassifier(LogisticRegression())`, `MultiOutputClassifier` is a meta-estimator for multi-label / multi-output classification. **Step 2:** When `.fit(X_train, y_train)` is called where `y_train` has $K$ target columns (labels), `MultiOutputClassifier` **fits one independent `LogisticRegression` classifier per target label**. **Step 3:** Therefore, **C** (`Trains a separate Logistic Regression model for each label`) is correct. **Key Takeaway / Tip:** `MultiOutputClassifier` extends any single-output classifier to multi-output targets by fitting one independent estimator per target column. A: **Incorrect:** Option A (Trains a single **Logistic Regression** model for all labels.) does not satisfy the conditions derived in the step-by-step analysis for How MultiOutputClassifier Wraps a Binary Estimator (correct choice: C). B: **Incorrect:** Option B (Combines **Logistic Regression** with another model.) does not satisfy the conditions derived in the step-by-step analysis for How MultiOutputClassifier Wraps a Binary Estimator (correct choice: C). C: **Correct:** Option C (Trains a separate **Logistic Regression** model for each label.) matches our derived result under How MultiOutputClassifier Wraps a Binary Estimator. `MultiOutputClassifier` extends any single-output classifier to multi-output targets by fitting one independent estimator per target column. D: **Incorrect:** Option D (Applies **Logistic Regression** in a one-vs-rest strategy for multi-class classification.) does not satisfy the conditions derived in the step-by-step analysis for How MultiOutputClassifier Wraps a Binary Estimator (correct choice: C).

Report a correction for Q132

Question 133 MCQ · 2.0 marks

What is the main advantage of using **RandomizedSearchCV** over **GridSearchCV** ?
6406532867261.
**RandomizedSearchCV** is always faster.
6406532867262.
**RandomizedSearchCV** evaluates all possible combinations of hyperparameters.
6406532867263.
**RandomizedSearchCV** can sample a larger hyperparameter space with fewer iterations.
6406532867264.
**RandomizedSearchCV** always finds the best model.

Published solution

**Answer: C** **Topic:** Model Selection — *Advantage of RandomizedSearchCV Over GridSearchCV* ### Step-by-Step Solution **Step 1:** While `GridSearchCV` exhaustively evaluates every combination in a discrete grid (which grows exponentially with the number of hyperparameters), `RandomizedSearchCV` samples a fixed number (`n_iter`) of random parameter combinations from specified distributions. **Step 2:** Thus, its main advantage is that **`RandomizedSearchCV` can sample a larger hyperparameter space with fewer iterations** (**C**). **Key Takeaway / Tip:** `RandomizedSearchCV` decouples the number of evaluations (`n_iter`) from the size of the search space, allowing exploration of wide/continuous hyperparameter ranges efficiently. A: **Incorrect:** Option A (**RandomizedSearchCV** is always faster.) does not satisfy the conditions derived in the step-by-step analysis for Advantage of RandomizedSearchCV Over GridSearchCV (correct choice: C). B: **Incorrect:** Option B (**RandomizedSearchCV** evaluates all possible combinations of hyperparameters.) does not satisfy the conditions derived in the step-by-step analysis for Advantage of RandomizedSearchCV Over GridSearchCV (correct choice: C). C: **Correct:** Option C (**RandomizedSearchCV** can sample a larger hyperparameter space with fewer iterations.) matches our derived result under Advantage of RandomizedSearchCV Over GridSearchCV. `RandomizedSearchCV` decouples the number of evaluations (`n_iter`) from the size of the search space, allowing exploration of wide/continuous hyperparameter ranges efficiently. D: **Incorrect:** Option D (**RandomizedSearchCV** always finds the best model.) does not satisfy the conditions derived in the step-by-step analysis for Advantage of RandomizedSearchCV Over GridSearchCV (correct choice: C).

Report a correction for Q133

Question 134 MCQ · 2.0 marks

Source diagram or notation
6406532867266.
LogisticRegression
6406532867267.
Perceptron
6406532867268.
RidgeClassifier
6406532867269.
Support Vector Machine (SVM)

Published solution

**Answer: C** **Topic:** Linear Classifiers — *SGDClassifier with squared_loss and l2 Penalty* ### Step-by-Step Solution **Step 1:** When `SGDClassifier` is configured with squared error loss (`loss='squared_loss'` / `'squared_error'`) and $L_2$ regularization (`penalty='l2'`), it minimizes the ridge-regularized least-squares objective $\|Xw - y\|_2^2 + \alpha \|w\|_2^2$ via stochastic gradient descent. **Step 2:** This corresponds to training a **`RidgeClassifier`** (**C**). **Key Takeaway / Tip:** In `SGDClassifier`, `loss='hinge'` gives `SVC`, `loss='log_loss'` gives `LogisticRegression`, and `loss='squared_loss'` with `penalty='l2'` gives `RidgeClassifier`. A: **Incorrect:** Option A (LogisticRegression) does not satisfy the conditions derived in the step-by-step analysis for SGDClassifier with squared_loss and l2 Penalty (correct choice: C). B: **Incorrect:** Option B (Perceptron) does not satisfy the conditions derived in the step-by-step analysis for SGDClassifier with squared_loss and l2 Penalty (correct choice: C). C: **Correct:** Option C (RidgeClassifier) matches our derived result under SGDClassifier with squared_loss and l2 Penalty. In `SGDClassifier`, `loss='hinge'` gives `SVC`, `loss='log_loss'` gives `LogisticRegression`, and `loss='squared_loss'` with `penalty='l2'` gives `RidgeClassifier`. D: **Incorrect:** Option D (Support Vector Machine (SVM)) does not satisfy the conditions derived in the step-by-step analysis for SGDClassifier with squared_loss and l2 Penalty (correct choice: C).

Report a correction for Q134

Question 135 MCQ · 2.0 marks

What type of classification problem is the **Perceptron** algorithm best suited for?
6406532867270.
Linearly separable binary classification problems.
6406532867271.
Non-linear classification problems.
6406532867272.
Regression problems.
6406532867273.
Unsupervised Learning Problems

Published solution

**Answer: A** **Topic:** Linear Classifiers — *Perceptron Convergence and Linearly Separable Binary Classification* ### Step-by-Step Solution **Step 1:** Recall the **Perceptron Convergence Theorem**: the classic `Perceptron` algorithm is a linear binary classifier that is guaranteed to converge in a finite number of updates if and only if the training dataset is **linearly separable**. **Step 2:** Therefore, the Perceptron algorithm is best suited for **linearly separable binary classification problems** (**A**). **Key Takeaway / Tip:** The Perceptron is a linear binary classifier and cannot converge on non-linearly separable data. A: **Correct:** Option A (Linearly separable binary classification problems.) matches our derived result under Perceptron Convergence and Linearly Separable Binary Classification. The Perceptron is a linear binary classifier and cannot converge on non-linearly separable data. B: **Incorrect:** Option B (Non-linear classification problems.) does not satisfy the conditions derived in the step-by-step analysis for Perceptron Convergence and Linearly Separable Binary Classification (correct choice: A). C: **Incorrect:** Option C (Regression problems.) does not satisfy the conditions derived in the step-by-step analysis for Perceptron Convergence and Linearly Separable Binary Classification (correct choice: A). D: **Incorrect:** Option D (Unsupervised Learning Problems) does not satisfy the conditions derived in the step-by-step analysis for Perceptron Convergence and Linearly Separable Binary Classification (correct choice: A).

Report a correction for Q135

Question 136 MCQ · 2.0 marks

Source diagram or notation
6406532867274.
[0, 1, 2]
6406532867275.
[0, 1]
6406532867276.
['setosa', 'versicolor', 'virginica']
6406532867277.
['setosa', 'versicolor’']
6406532867278.
None of these

Published solution

**Answer: A** **Topic:** Naive Bayes — *Inspecting Fitted Class Labels via gnb.classes_ on the Iris Dataset* ### Step-by-Step Solution **Step 1:** In `sklearn.datasets.load_iris()`, - `iris.target_names` contains the string names `['setosa', 'versicolor', 'virginica']`. - `iris.target` (`y`) contains the integer-encoded class labels `0, 1, 2`. **Step 2:** Because `gnb.fit(X_train, y_train)` is fitted on `y = iris.target` (which contains integers `0, 1, 2`), the learned attribute `gnb.classes_` stores the sorted unique values of `y_train`, which is **`[0, 1, 2]`** (**A**). **Key Takeaway / Tip:** `iris.target` contains integer class codes `[0, 1, 2]`, whereas `iris.target_names` contains the string names. A: **Correct:** Option A ([0, 1, 2]) matches our derived result under Inspecting Fitted Class Labels via gnb.classes_ on the Iris Dataset. `iris.target` contains integer class codes `[0, 1, 2]`, whereas `iris.target_names` contains the string names. B: **Incorrect:** Option B ([0, 1]) does not satisfy the conditions derived in the step-by-step analysis for Inspecting Fitted Class Labels via gnb.classes_ on the Iris Dataset (correct choice: A). C: **Incorrect:** Option C (['setosa', 'versicolor', 'virginica']) does not satisfy the conditions derived in the step-by-step analysis for Inspecting Fitted Class Labels via gnb.classes_ on the Iris Dataset (correct choice: A). D: **Incorrect:** Option D (['setosa', 'versicolor’']) does not satisfy the conditions derived in the step-by-step analysis for Inspecting Fitted Class Labels via gnb.classes_ on the Iris Dataset (correct choice: A). E: **Incorrect:** Option E (None of these) does not satisfy the conditions derived in the step-by-step analysis for Inspecting Fitted Class Labels via gnb.classes_ on the Iris Dataset (correct choice: A).

Report a correction for Q136

Question 137 MCQ · 2.0 marks

What is the default loss value in SGDClassifier API and it gives which classifier?
6406532867289.
‘log loss’, LogisticRegressor
6406532867290.
‘log loss’, LogisticClassifier
6406532867291.
‘hinge’, SVM
6406532867292.
‘hinge’, Perceptron

Published solution

**Answer: C** **Topic:** Linear Classifiers — *Default Loss Function of SGDClassifier* ### Step-by-Step Solution **Step 1:** Check the default signature of `sklearn.linear_model.SGDClassifier(loss='hinge', penalty='l2', ...)`: - The default value of the `loss` parameter is **`'hinge'`**. - Minimizing hinge loss with $L_2$ regularization trains a linear **Support Vector Machine (SVM)**. **Step 2:** Therefore, **C** (`'hinge', SVM`) is correct. **Key Takeaway / Tip:** By default, `SGDClassifier()` uses `loss='hinge'`, which fits a linear Support Vector Machine. A: **Incorrect:** Option A (‘log loss’, LogisticRegressor) does not satisfy the conditions derived in the step-by-step analysis for Default Loss Function of SGDClassifier (correct choice: C). B: **Incorrect:** Option B (‘log loss’, LogisticClassifier) does not satisfy the conditions derived in the step-by-step analysis for Default Loss Function of SGDClassifier (correct choice: C). C: **Correct:** Option C (‘hinge’, SVM) matches our derived result under Default Loss Function of SGDClassifier. By default, `SGDClassifier()` uses `loss='hinge'`, which fits a linear Support Vector Machine. D: **Incorrect:** Option D (‘hinge’, Perceptron) does not satisfy the conditions derived in the step-by-step analysis for Default Loss Function of SGDClassifier (correct choice: C).

Report a correction for Q137

Question 138 MCQ · 2.0 marks

Source diagram or notation
6406532867304.
1
6406532867305.
2
6406532867306.
10
6406532867307.
500

Published solution

**Answer: C** **Topic:** Nearest Neighbors — *Tuning n_neighbors in KNeighborsClassifier to Reduce Overfitting* ### Step-by-Step Solution **Step 1:** With `n_neighbors=4`, the model has **98% training accuracy** but only **65% validation accuracy**, which is a classic sign of **overfitting** (high variance). **Step 2:** In k-Nearest Neighbors (`KNeighborsClassifier`), smaller values of $k$ (`1` or `2`) create jagged, complex decision boundaries (more overfitting), whereas increasing $k$ averages over more neighbors and smooths the decision boundary: - Increasing `n_neighbors` from `4` to a moderate value like **`10` (Option C)** smooths the boundary and reduces overfitting. - Setting `n_neighbors=500` (Option D, half the entire 1000-sample dataset) would severely **underfit**. **Step 3:** Therefore, **`10`** (**C**) is the most suitable value to try next. **Key Takeaway / Tip:** To reduce overfitting in k-NN, increase $k$ moderately (e.g., from `4` to `10`) to smooth out noise without underfitting. A: **Incorrect:** Option A (1) does not satisfy the conditions derived in the step-by-step analysis for Tuning n_neighbors in KNeighborsClassifier to Reduce Overfitting (correct choice: C). B: **Incorrect:** Option B (2) does not satisfy the conditions derived in the step-by-step analysis for Tuning n_neighbors in KNeighborsClassifier to Reduce Overfitting (correct choice: C). C: **Correct:** Option C (10) matches our derived result under Tuning n_neighbors in KNeighborsClassifier to Reduce Overfitting. To reduce overfitting in k-NN, increase $k$ moderately (e.g., from `4` to `10`) to smooth out noise without underfitting. D: **Incorrect:** Option D (500) does not satisfy the conditions derived in the step-by-step analysis for Tuning n_neighbors in KNeighborsClassifier to Reduce Overfitting (correct choice: C).

Report a correction for Q138

Question 139 NAT · 3.0 marks

Source diagram or notation

Published solution

**Answer: 0.67** **Topic:** Classification Metrics — *Calculating Class-Specific Precision Score* ### Step-by-Step Solution **Step 1:** Compare `y_true = ["dog", "cat", "dog", "dog", "cat", "mouse"]` and `y_pred = ["cat", "cat", "dog", "dog", "cat", "dog"]` for the target class **`"dog"`**: - Find all positions where the model **predicted `"dog"`** (`y_pred[i] == "dog"`): indices `2, 3, 5` ($3$ total predictions of `"dog"$). - Check how many of those 3 predictions are **actually `"dog"`** in `y_true`: - Index 2: `y_true[2] == "dog"` (**True Positive 1**) - Index 3: `y_true[3] == "dog"` (**True Positive 2**) - Index 5: `y_true[5] == "mouse"` (False Positive) **Step 2:** Compute the precision for class `"dog"`: $$\text{Precision}_{\text{dog}} = \frac{\text{TP}_{\text{dog}}}{\text{TP}_{\text{dog}} + \text{FP}_{\text{dog}}} = \frac{2}{2 + 1} = \frac{2}{3} \approx 0.67$$ **Key Takeaway / Tip:** Precision for class `"dog"` only looks at samples where `y_pred == "dog"` (3 samples), of which 2 have `y_true == "dog"` ($2/3 \approx 0.67$).

Report a correction for Q139

Question 140 NAT · 3.0 marks

Source diagram or notation

Published solution

**Answer: 2** **Topic:** Nearest Neighbors — *KNeighborsClassifier with k Equal to Training Set Size* ### Step-by-Step Solution **Step 1:** In the given code, `n_neighbors=len(y_train)` sets $k = 10$ (the entire training set) with `weights='uniform'`. **Step 2:** When $k$ equals the total number of training points and weights are uniform, `KNeighborsClassifier` simply predicts the **majority (most frequent) class** across the entire `y_train` array! **Step 3:** Count the class frequencies in `y_train = np.array([0, 0, 1, 1, 1, 2, 2, 2, 2, 2])`: - Class `0`: $2$ occurrences - Class `1`: $3$ occurrences - Class `2`: $5$ occurrences (**Majority class!**) **Step 4:** Therefore, `knn.predict(X_test)` outputs `[2]`, so the answer is **2**. **Key Takeaway / Tip:** When `n_neighbors = len(y_train)` with `weights='uniform'`, every training sample votes equally, so the classifier always predicts the global majority class (`2`).

Report a correction for Q140

Question 141 NAT · 2.0 marks

Source diagram or notation

Published solution

**Answer: 2** **Topic:** Data Imputation — *Missing Value Imputation Using KNNImputer* ### Step-by-Step Solution **Step 1:** In `X = [[5, 6, 3], [np.nan, 1, 5], [0, 2, 8], [4, 4, 2]]`, we want `X_trf[1][0]`, which is the imputed value for `np.nan` in Row 1 (`[np.nan, 1, 5]`) using `KNNImputer(n_neighbors=2, weights='uniform')`. **Step 2:** Compute the squared distance from Row 1 (`[nan, 1, 5]`) to the other three rows using the non-missing columns (columns 1 and 2): - **Row 0 (`[5, 6, 3]`)**: $(1 - 6)^2 + (5 - 3)^2 = 25 + 4 = 29$ - **Row 2 (`[0, 2, 8]`)**: $(1 - 2)^2 + (5 - 8)^2 = 1 + 9 = 10$ - **Row 3 (`[4, 4, 2]`)**: $(1 - 4)^2 + (5 - 2)^2 = 9 + 9 = 18$ **Step 3:** The $k = 2$ closest neighbors of Row 1 are **Row 2** (distance $\propto 10$, Column-0 value $= 0$) and **Row 3** (distance $\propto 18$, Column-0 value $= 4$). **Step 4:** Average their Column-0 values: $$\text{X\_trf}[1][0] = \frac{0 + 4}{2} = 2$$ **Key Takeaway / Tip:** Using columns 1 and 2, Row 1 (`[nan, 1, 5]`) is closest to Row 2 (`[0, 2, 8]`) and Row 3 (`[4, 4, 2]`), whose column-0 values average to $(0 + 4)/2 = 2$.

Report a correction for Q141

Question 142 MSQ · 2.0 marks

Source diagram or notation
6406532867293.
‘poly’,
6406532867294.
‘lasso’
6406532867295.
‘rbf’,
6406532867296.
‘scale’

Published solution

**Answer: A, C** **Topic:** Support Vector Machines — *Valid Kernel Parameter Values in sklearn.svm.SVC* ### Step-by-Step Solution **Step 1:** In `sklearn.svm.SVC(kernel=...)`, the valid string arguments for `kernel` are `'linear'`, `'poly'`, `'rbf'`, `'sigmoid'`, and `'precomputed'`. **Step 2:** Check the 4 options: - **A (`'poly'`)**: Valid polynomial kernel. - **B (`'lasso'`)**: Invalid (`lasso` is an $L_1$-regularized linear regression model, not an SVM kernel). - **C (`'rbf'`)**: Valid Radial Basis Function (Gaussian) kernel. - **D (`'scale'`)**: Invalid (`'scale'` is the default value for the `gamma` parameter, not `kernel`). **Step 3:** Therefore, **A and C** are correct. **Key Takeaway / Tip:** Don't confuse `gamma='scale'` (which sets the kernel coefficient) with the `kernel` parameter (`'linear'`, `'poly'`, `'rbf'`, `'sigmoid'`). A: **Correct:** Option A (‘poly’,) matches our derived result under Valid Kernel Parameter Values in sklearn.svm.SVC. Don't confuse `gamma='scale'` (which sets the kernel coefficient) with the `kernel` parameter (`'linear'`, `'poly'`, `'rbf'`, `'sigmoid'`). B: **Incorrect:** Option B (‘lasso’) does not satisfy the conditions derived in the step-by-step analysis for Valid Kernel Parameter Values in sklearn.svm.SVC (correct choice: A, C). C: **Correct:** Option C (‘rbf’,) matches our derived result under Valid Kernel Parameter Values in sklearn.svm.SVC. Don't confuse `gamma='scale'` (which sets the kernel coefficient) with the `kernel` parameter (`'linear'`, `'poly'`, `'rbf'`, `'sigmoid'`). D: **Incorrect:** Option D (‘scale’) does not satisfy the conditions derived in the step-by-step analysis for Valid Kernel Parameter Values in sklearn.svm.SVC (correct choice: A, C).

Report a correction for Q142

Question 143 MSQ · 2.0 marks

Which of the following **scikit-learn** model supports incremental learning through partial_fit method ?
6406532867308.
SGDClassifier
6406532867309.
LinearRegression
6406532867310.
Perceptron
6406532867311.
SVC

Published solution

**Answer: A, C** **Topic:** Incremental Learning — *Scikit-Learn Estimators Supporting partial_fit()* ### Step-by-Step Solution **Step 1:** In `scikit-learn`, out-of-core (incremental / online / mini-batch) learning via the `.partial_fit()` method is supported by stochastic gradient and online estimators: - **`SGDClassifier` (A)**: Supports `.partial_fit()` — **Correct**. - **`LinearRegression` (B)**: Uses a closed-form batch SVD/least-squares solver and does *not* have `.partial_fit()`. - **`Perceptron` (C)**: Is an online linear classifier (equivalent to `SGDClassifier(loss='perceptron', learning_rate='constant', eta0=1.0, penalty=None)`) and supports `.partial_fit()` — **Correct**. - **`SVC` (D)**: Uses a batch quadratic programming (`libsvm`) solver and does *not* support `.partial_fit()`. **Step 2:** Therefore, **A and C** support incremental learning via `partial_fit`. **Key Takeaway / Tip:** Online/stochastic estimators (`SGDClassifier`, `SGDRegressor`, `Perceptron`, `PassiveAggressiveClassifier`, `MultinomialNB`, `MiniBatchKMeans`) support `.partial_fit()`, whereas batch solvers (`LinearRegression`, `SVC`) do not. A: **Correct:** Option A (SGDClassifier) matches our derived result under Scikit-Learn Estimators Supporting partial_fit(). Online/stochastic estimators (`SGDClassifier`, `SGDRegressor`, `Perceptron`, `PassiveAggressiveClassifier`, `MultinomialNB`, `MiniBatchKMeans`) support `.partial_fit()`, whereas batch solvers (`LinearRegression`, `SVC`) do not. B: **Incorrect:** Option B (LinearRegression) does not satisfy the conditions derived in the step-by-step analysis for Scikit-Learn Estimators Supporting partial_fit() (correct choice: A, C). C: **Correct:** Option C (Perceptron) matches our derived result under Scikit-Learn Estimators Supporting partial_fit(). Online/stochastic estimators (`SGDClassifier`, `SGDRegressor`, `Perceptron`, `PassiveAggressiveClassifier`, `MultinomialNB`, `MiniBatchKMeans`) support `.partial_fit()`, whereas batch solvers (`LinearRegression`, `SVC`) do not. D: **Incorrect:** Option D (SVC) does not satisfy the conditions derived in the step-by-step analysis for Scikit-Learn Estimators Supporting partial_fit() (correct choice: A, C).

Report a correction for Q143

Question 144 MSQ · 3.0 marks

Which of the following options are true for regularization parameter C in sklearn.svm.SVC ?
6406532867297.
Large value of the regularization parameter C will overfit the training set and complex decision boundaries will form.
6406532867298.
Large value of the regularization parameter C will underfit the training set and smooth decision boundaries will form.
6406532867299.
Small value of the regularization parameter C will overfit the training set and complex decision boundaries will form.
6406532867300.
Small value of the regularization parameter C will underfit the training set and smooth decision boundaries will form.
6406532867301.
None of these       **MLT** **Section Id :** 64065360931 **Section Number :** 9 **Section type :** Online **Mandatory or Optional :** Mandatory **Number of Questions :** 11 **Number of Questions to be attempted :** 11 **Section Marks :** 40 **Display Number Panel :** Yes **Section Negative Marks :** 0 **Group All Questions :** No **Enable Mark as Answered Mark for Review and** No **Clear Response :** **Section Maximum Duration :** 0 **Section Minimum Duration :** 0

Published solution

**Answer: A, D** **Topic:** Support Vector Machines — *Effect of Regularization Parameter C in sklearn.svm.SVC* ### Step-by-Step Solution **Step 1:** In `sklearn.svm.SVC`, the parameter $C$ controls the trade-off between achieving a wide margin and ensuring that training points are classified on the correct side of the margin: - **Large $C$ (Option A)**: Places a high penalty on margin violations, yielding a narrower margin and a more complex decision boundary that can **overfit** the training set. - **Small $C$ (Option D)**: Encourages a wider margin at the cost of more training misclassifications, yielding a **smoother decision boundary that may underfit** the training set. **Step 2:** Therefore, **A and D** are true. **Key Takeaway / Tip:** Remember: Large $C \implies$ less regularization $\implies$ complex boundary (overfitting); Small $C \implies$ more regularization $\implies$ smooth boundary (underfitting). A: **Correct:** Option A (Large value of the regularization parameter C will overfit the training set and complex decision boundaries will form.) matches our derived result under Effect of Regularization Parameter C in sklearn.svm.SVC. Remember: Large $C \implies$ less regularization $\implies$ complex boundary (overfitting); Small $C \implies$ more regularization $\implies$ smooth boundary (underfitting). B: **Incorrect:** Option B (Large value of the regularization parameter C will underfit the training set and smooth decision boundaries will form.) does not satisfy the conditions derived in the step-by-step analysis for Effect of Regularization Parameter C in sklearn.svm.SVC (correct choice: A, D). C: **Incorrect:** Option C (Small value of the regularization parameter C will overfit the training set and complex decision boundaries will form.) does not satisfy the conditions derived in the step-by-step analysis for Effect of Regularization Parameter C in sklearn.svm.SVC (correct choice: A, D). D: **Correct:** Option D (Small value of the regularization parameter C will underfit the training set and smooth decision boundaries will form.) matches our derived result under Effect of Regularization Parameter C in sklearn.svm.SVC. Remember: Large $C \implies$ less regularization $\implies$ complex boundary (overfitting); Small $C \implies$ more regularization $\implies$ smooth boundary (underfitting). E: **Incorrect:** Option E (None of these       **MLT** **Section Id :** 64065360931 **Section Number :** 9 **Section type :** Online **Mandatory or Optional :** Mandatory **Number of Questions :** 11 **Nu...) does not satisfy the conditions derived in the step-by-step analysis for Effect of Regularization Parameter C in sklearn.svm.SVC (correct choice: A, D).

Report a correction for Q144