Machine Learning Practice · Quiz 1 · Sep 2024
Machine Learning Practice · Quiz 1 · Sep 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.
24 / 24 published solutions
(0,1)
(2,3)
(3,2)
(2,4)
**Answer: D**
**Topic:** Clustering — *k-means++ Cluster Center Selection*
### Step-by-Step Solution
**Step 1:** In k-means++ initialization (from the preceding MLT question), each candidate point is assigned a score equal to its squared Euclidean distance $\min_j \|x - \mu_j\|^2$ to the nearest existing cluster center.
**Step 2:** The point that achieves the maximum squared distance score among the candidates is **`(2, 4)`**, which is selected as $\mu_2^0$.
**Step 3:** Therefore, **D** (`(2,4)`) is correct.
**Key Takeaway / Tip:** In deterministic/greedy k-means++, the next cluster center is the point with the largest squared distance to the closest already-chosen center.
A: **Incorrect:** Option A ((0,1)) does not satisfy the conditions derived in the step-by-step analysis for k-means++ Cluster Center Selection (correct choice: D).
B: **Incorrect:** Option B ((2,3)) does not satisfy the conditions derived in the step-by-step analysis for k-means++ Cluster Center Selection (correct choice: D).
C: **Incorrect:** Option C ((3,2)) does not satisfy the conditions derived in the step-by-step analysis for k-means++ Cluster Center Selection (correct choice: D).
D: **Correct:** Option D ((2,4)) matches our derived result under k-means++ Cluster Center Selection. In deterministic/greedy k-means++, the next cluster center is the point with the largest squared distance to the closest already-chosen center.
Question 27 MCQ · 4.0 marks
Which point has the lowest probability of being chosen as the 3rd cluster mean? Use squared
distance to calculate the scores.
(1,0)
(2,3)
(3,2)
(1,2)
**MLP**
**Section Id :** 64065369402
**Section Number :** 3
**Section type :** Online
**Mandatory or Optional :** Mandatory
**Number of Questions :** 18
**Number of Questions to be attempted :** 18
**Section Marks :** 50
**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
**Section Time In :** Minutes
**Maximum Instruction Time :** 0
Published solution
**Answer: B**
**Topic:** Clustering — *Lowest Probability Point in k-means++ Initialization*
### Step-by-Step Solution
**Step 1:** In k-means++, the probability of choosing a point $x$ as the 3rd cluster mean is proportional to $\min(\|x - \mu_1\|^2, \|x - \mu_2\|^2)$, where $\mu_2 = (2, 4)$ from Question 26.
**Step 2:** Compare the candidates `(1,0)`, `(2,3)`, `(3,2)`, and `(1,2)`:
- The point **`(2, 3)`** is at distance $1$ ($1^2 = 1$) from $\mu_2 = (2, 4)$, which gives it the smallest minimum squared distance to the existing centers.
**Step 3:** Therefore, **`(2, 3)`** (**B**) has the lowest probability of being chosen as the 3rd cluster mean.
**Key Takeaway / Tip:** Since $\mu_2 = (2, 4)$ was just selected in Question 26, its immediate neighbor `(2, 3)` has squared distance $(2-2)^2 + (3-4)^2 = 1$, the smallest score among the options.
A: **Incorrect:** Option A ((1,0)) does not satisfy the conditions derived in the step-by-step analysis for Lowest Probability Point in k-means++ Initialization (correct choice: B).
B: **Correct:** Option B ((2,3)) matches our derived result under Lowest Probability Point in k-means++ Initialization. Since $\mu_2 = (2, 4)$ was just selected in Question 26, its immediate neighbor `(2, 3)` has squared distance $(2-2)^2 + (3-4)^2 = 1$, the smallest score among the options.
C: **Incorrect:** Option C ((3,2)) does not satisfy the conditions derived in the step-by-step analysis for Lowest Probability Point in k-means++ Initialization (correct choice: B).
D: **Incorrect:** Option D ((1,2) **MLP** **Section Id :** 64065369402 **Section Number :** 3 **Section type :** Online **Mandatory or Optional :** Mandatory **Number of Questions :** 18 **Number of ...) does not satisfy the conditions derived in the step-by-step analysis for Lowest Probability Point in k-means++ Initialization (correct choice: B).
Question 29 MCQ · 2.0 marks
Based on the above data, answer the given subquestions.
Which option will give the total count of canceled flights in the dataset?
Published solution
**Answer: A**
**Topic:** Pandas Data Analysis — *Counting Boolean True Values with .sum()*
### Step-by-Step Solution
**Step 1:** In the given DataFrame `df`, the `'Cancelled'` column contains boolean values (`True` if the flight was cancelled, `False` otherwise).
**Step 2:** Compare the four Pandas expressions:
- **`df['Cancelled'].sum()` (A)**: Treats `True` as `1` and `False` as `0`, returning the exact total count of cancelled (`True`) flights.
- **`df['Cancelled'].count()` (B)**: Counts all non-null rows (both `True` and `False`), returning `12`.
- **`df['Cancelled'].isnull().sum()` (C)**: Counts missing (`NaN`) values in `'Cancelled'`, returning `0`.
- **`df['Cancelled'].len()` (D)**: Raises an `AttributeError` (`Series` has no `.len()` method).
**Step 3:** Therefore, **A** is correct.
**Key Takeaway / Tip:** Calling `.sum()` on a boolean Pandas Series counts the number of `True` entries, whereas `.count()` counts all non-NA entries.
A: **Correct:** Option A (
Source diagram or notation unavailable. Please report this question for correction.) matches our derived result under Counting Boolean True Values with .sum(). Calling `.sum()` on a boolean Pandas Series counts the number of `True` entries, whereas `.count()` counts all non-NA entries.
B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Counting Boolean True Values with .sum() (correct choice: A).
C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Counting Boolean True Values with .sum() (correct choice: A).
D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Counting Boolean True Values with .sum() (correct choice: A).
Question 30 MCQ · 2.0 marks
Based on the above data, answer the given subquestions.
Which of the following code snippets will add a new column ’OnTime’ that shows True if the flight
was not delayed, else False?
Published solution
**Answer: A**
**Topic:** Pandas Data Analysis — *Creating a Boolean Column from a Numeric Condition*
### Step-by-Step Solution
**Step 1:** A flight is considered **not delayed (on time or early)** when its `DelayMinutes` is less than or equal to $0$ (`DelayMinutes <= 0`, such as `-10`, `-5`, `-8`).
**Step 2:** Evaluating `df['DelayMinutes'] <= 0` produces a boolean Series that is `True` when the flight was not delayed and `False` when `DelayMinutes > 0`.
**Step 3:** Assigning `df['OnTime'] = df['DelayMinutes'] <= 0` (**A**) creates the desired column.
**Key Takeaway / Tip:** Negative values in `DelayMinutes` represent early arrivals, so `df['DelayMinutes'] <= 0` captures all non-delayed flights.
A: **Correct:** Option A (
Source diagram or notation unavailable. Please report this question for correction.) matches our derived result under Creating a Boolean Column from a Numeric Condition. Negative values in `DelayMinutes` represent early arrivals, so `df['DelayMinutes'] <= 0` captures all non-delayed flights.
B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Creating a Boolean Column from a Numeric Condition (correct choice: A).
C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Creating a Boolean Column from a Numeric Condition (correct choice: A).
D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Creating a Boolean Column from a Numeric Condition (correct choice: A).
Question 31 MSQ · 3.0 marks
Based on the above data, answer the given subquestions.
How can you filter the flights that have a delay due to ’Weather’?
Published solution
**Answer: B, C**
**Topic:** Pandas Data Analysis — *Filtering DataFrame Rows by Exact String Match*
### Step-by-Step Solution
**Step 1:** Examine the four candidate expressions for filtering rows where `DelayReason` is `'Weather'`:
- **A (`df[df['DelayReason'].str.contains('Weather')]`)**: Because the `'DelayReason'` column contains `NaN` values (rows 3, 5, 10), `.str.contains('Weather')` without `na=False` returns `NaN` for those rows, causing boolean indexing `df[...]` to raise a `ValueError: Cannot mask with non-boolean array containing NA / NaN values`!
- **B (`df.loc[df['DelayReason'] == 'Weather']`)**: Equality comparison `== 'Weather'` safely evaluates `NaN == 'Weather'` as `False` and filters the rows via `.loc[]` — **Correct**.
- **C (`df[df['DelayReason'] == 'Weather']`)**: Standard boolean indexing with `== 'Weather'` also safely evaluates `NaN` as `False` — **Correct**.
- **D (`df[df['Weather'] == True]`)**: Raises a `KeyError` because there is no column named `'Weather'`.
**Step 2:** Therefore, **B and C** are correct.
**Key Takeaway / Tip:** When a string column contains `NaN` values, `df['col'] == 'val'` returns `False` for `NaN`s, whereas `df['col'].str.contains('val')` returns `NaN` unless `na=False` is specified.
A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Filtering DataFrame Rows by Exact String Match (correct choice: B, C).
B: **Correct:** Option B (
Source diagram or notation unavailable. Please report this question for correction.) matches our derived result under Filtering DataFrame Rows by Exact String Match. When a string column contains `NaN` values, `df['col'] == 'val'` returns `False` for `NaN`s, whereas `df['col'].str.contains('val')` returns `NaN` unless `na=False` is specified.
C: **Correct:** Option C (
Source diagram or notation unavailable. Please report this question for correction.) matches our derived result under Filtering DataFrame Rows by Exact String Match. When a string column contains `NaN` values, `df['col'] == 'val'` returns `False` for `NaN`s, whereas `df['col'].str.contains('val')` returns `NaN` unless `na=False` is specified.
D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Filtering DataFrame Rows by Exact String Match (correct choice: B, C).
Question 32 MCQ · 3.0 marks
Based on the above data, answer the given subquestions.
Which option will sort the flights first by `Airline` in ascending order, then by DelayMinutes in
descending order?
Published solution
**Answer: A**
**Topic:** Pandas Data Analysis — *Multi-Column Sorting with Mixed Ascending/Descending Order*
### Step-by-Step Solution
**Step 1:** In Pandas, sorting a DataFrame by values uses the `.sort_values()` method (the old `.sort()` method in Options B and D does not exist in modern Pandas).
**Step 2:** To sort first by `'Airline'` in **ascending** order (`True`) and then by `'DelayMinutes'` in **descending** order (`False`), pass a list of column names to `by` and a matching list of booleans to `ascending`:
`df.sort_values(by=['Airline', 'DelayMinutes'], ascending=[True, False])`
**Step 3:** This matches Option **A**.
**Key Takeaway / Tip:** Pass a list of booleans `ascending=[True, False]` to specify different sort directions for each column in `by`.
A: **Correct:** Option A (
Source diagram or notation unavailable. Please report this question for correction.) matches our derived result under Multi-Column Sorting with Mixed Ascending/Descending Order. Pass a list of booleans `ascending=[True, False]` to specify different sort directions for each column in `by`.
B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Multi-Column Sorting with Mixed Ascending/Descending Order (correct choice: A).
C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Multi-Column Sorting with Mixed Ascending/Descending Order (correct choice: A).
D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Multi-Column Sorting with Mixed Ascending/Descending Order (correct choice: A).
Question 33 MCQ · 3.0 marks
Based on the above data, answer the given subquestions.
Which option will give the count of flights that have a delay greater than the average delay?
Published solution
**Answer: A**
**Topic:** Pandas Data Analysis — *Counting Rows Exceeding the Column Mean*
### Step-by-Step Solution
**Step 1:** First, filter the DataFrame to keep only flights whose delay exceeds the average delay: `df[df['DelayMinutes'] > df['DelayMinutes'].mean()]`.
**Step 2:** To get the single integer count of matching rows:
- `.shape[0]` (**Option A**) returns the number of rows in the filtered DataFrame as an integer.
- Calling `.count()` on a DataFrame (Option C) returns a *Series* of non-null counts for every column rather than a single integer count (and `DelayReason` has `NaN`s!).
**Step 3:** Therefore, **A** (`df[df['DelayMinutes'] > df['DelayMinutes'].mean()].shape[0]`) is correct.
**Key Takeaway / Tip:** Use `.shape[0]` or `len(...)` on a filtered DataFrame to get the exact row count as a single integer.
A: **Correct:** Option A (
Source diagram or notation unavailable. Please report this question for correction.) matches our derived result under Counting Rows Exceeding the Column Mean. Use `.shape[0]` or `len(...)` on a filtered DataFrame to get the exact row count as a single integer.
B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Counting Rows Exceeding the Column Mean (correct choice: A).
C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Counting Rows Exceeding the Column Mean (correct choice: A).
D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Counting Rows Exceeding the Column Mean (correct choice: A).
Question 34 MCQ · 2.0 marks
Based on the above data, answer the given subquestions.
(4, 5)
(4, 6)
(4, 7)
(4, 8)
None of these
Published solution
**Answer: A**
**Topic:** Pipelines and ColumnTransformer — *Output Shape of a ColumnTransformer with KNNImputer, MinMaxScaler, and OneHotEncoder*
### Step-by-Step Solution
**Step 1:** Inspect the input array `X` of shape `(4, 3)` ($4$ rows, $3$ columns):
- Columns `[0, 2]` (2 numeric columns) are passed through `pipe` (`KNNImputer` + `MinMaxScaler`), which preserves the **2** columns.
- Column `[1]` (`['red', 'blue', 'green', 'red']`) has **3** unique categories (`'blue'`, `'green'`, `'red'`), so `OneHotEncoder()` (without `drop`) expands it into **3** binary one-hot columns.
**Step 2:** `ColumnTransformer` concatenates the 2 scaled numeric columns and the 3 one-hot encoded columns horizontally, producing $2 + 3 = 5$ columns for the 4 samples.
**Step 3:** Thus, `transformed_X.shape` is **`(4, 5)`**, which matches **A**.
**Key Takeaway / Tip:** Add the number of numeric columns ($2$) and the number of unique categories in the categorical column ($3$: `'blue', 'green', 'red'`) to get $2 + 3 = 5$ output columns.
A: **Correct:** Option A ((4, 5)) matches our derived result under Output Shape of a ColumnTransformer with KNNImputer, MinMaxScaler, and OneHotEncoder. Add the number of numeric columns ($2$) and the number of unique categories in the categorical column ($3$: `'blue', 'green', 'red'`) to get $2 + 3 = 5$ output columns.
B: **Incorrect:** Option B ((4, 6)) does not satisfy the conditions derived in the step-by-step analysis for Output Shape of a ColumnTransformer with KNNImputer, MinMaxScaler, and OneHotEncoder (correct choice: A).
C: **Incorrect:** Option C ((4, 7)) does not satisfy the conditions derived in the step-by-step analysis for Output Shape of a ColumnTransformer with KNNImputer, MinMaxScaler, and OneHotEncoder (correct choice: A).
D: **Incorrect:** Option D ((4, 8)) does not satisfy the conditions derived in the step-by-step analysis for Output Shape of a ColumnTransformer with KNNImputer, MinMaxScaler, and OneHotEncoder (correct choice: A).
E: **Incorrect:** Option E (None of these) does not satisfy the conditions derived in the step-by-step analysis for Output Shape of a ColumnTransformer with KNNImputer, MinMaxScaler, and OneHotEncoder (correct choice: A).
Question 35 MCQ · 3.0 marks
Based on the above data, answer the given subquestions.
0.0
0.5
-0.5
1
None of these
Published solution
**Answer: D**
**Topic:** Pipelines and ColumnTransformer — *Indexing a Transformed Array from ColumnTransformer*
### Step-by-Step Solution
**Step 1:** In `ct = ColumnTransformer([('num', pipe, [0, 2]), ('cat', OneHotEncoder(), [1])])`, the columns of `transformed_X` are ordered as:
- Column `0`: scaled feature `0`
- Column `1`: imputed and scaled feature `2`
- Columns `2, 3, 4`: one-hot encoded columns for feature `1` sorted alphabetically by category name: **`'blue'` (Col 2)**, **`'green'` (Col 3)**, **`'red'` (Col 4)**.
**Step 2:** We want `transformed_X[1, 2]`, which is Row `1` (`[2.85, 'blue', np.nan]`) and Column `2` (the first one-hot category, `'blue'`).
**Step 3:** Since Row `1` has category `'blue'`, its `'blue'` one-hot indicator at Column `2` is **`1`** (`1.0`), which matches **D**.
**Key Takeaway / Tip:** `OneHotEncoder` sorts category strings alphabetically (`'blue'`, `'green'`, `'red'`), so `'blue'` occupies the very first one-hot column (index `2`).
A: **Incorrect:** Option A (0.0) does not satisfy the conditions derived in the step-by-step analysis for Indexing a Transformed Array from ColumnTransformer (correct choice: D).
B: **Incorrect:** Option B (0.5) does not satisfy the conditions derived in the step-by-step analysis for Indexing a Transformed Array from ColumnTransformer (correct choice: D).
C: **Incorrect:** Option C (-0.5) does not satisfy the conditions derived in the step-by-step analysis for Indexing a Transformed Array from ColumnTransformer (correct choice: D).
D: **Correct:** Option D (1) matches our derived result under Indexing a Transformed Array from ColumnTransformer. `OneHotEncoder` sorts category strings alphabetically (`'blue'`, `'green'`, `'red'`), so `'blue'` occupies the very first one-hot column (index `2`).
E: **Incorrect:** Option E (None of these) does not satisfy the conditions derived in the step-by-step analysis for Indexing a Transformed Array from ColumnTransformer (correct choice: D).
Question 36 MSQ · 2.0 marks
Which of the following preprocessing techniques helps in handling categorical features in a
dataset?
One-hot encoding
StandardScaler
Label encoding
MinMaxScaler
Published solution
**Answer: A, C**
**Topic:** Data Preprocessing — *Encoding Categorical Features*
### Step-by-Step Solution
**Step 1:** Identify which preprocessing techniques convert categorical (non-numeric) features into numeric representations:
- **One-hot encoding (A)**: Converts a categorical column with $K$ categories into $K$ binary ($0/1$) indicator columns — **Correct**.
- **StandardScaler (B)**: Standardizes continuous numeric features to mean $0$ and variance $1$ — Incorrect.
- **Label encoding (C)**: Maps each category to an integer $0, 1, \dots, K-1$ — **Correct**.
- **MinMaxScaler (D)**: Scales continuous numeric features to $[0, 1]$ — Incorrect.
**Step 2:** Therefore, **A and C** are correct.
**Key Takeaway / Tip:** `OneHotEncoder` and `LabelEncoder`/`OrdinalEncoder` handle categorical data, whereas `StandardScaler` and `MinMaxScaler` scale numeric data.
A: **Correct:** Option A (One-hot encoding) matches our derived result under Encoding Categorical Features. `OneHotEncoder` and `LabelEncoder`/`OrdinalEncoder` handle categorical data, whereas `StandardScaler` and `MinMaxScaler` scale numeric data.
B: **Incorrect:** Option B (StandardScaler) does not satisfy the conditions derived in the step-by-step analysis for Encoding Categorical Features (correct choice: A, C).
C: **Correct:** Option C (Label encoding) matches our derived result under Encoding Categorical Features. `OneHotEncoder` and `LabelEncoder`/`OrdinalEncoder` handle categorical data, whereas `StandardScaler` and `MinMaxScaler` scale numeric data.
D: **Incorrect:** Option D (MinMaxScaler) does not satisfy the conditions derived in the step-by-step analysis for Encoding Categorical Features (correct choice: A, C).
Question 37 MSQ · 2.0 marks
Which of the following imputation strategies can be used for handling missing values?
Filling with mean or median
Deleting the rows with missing values
Using a predictive model to estimate missing values
Using a random generator to fill missing values
Published solution
**Answer: A, B, C**
**Topic:** Data Imputation — *Valid Strategies for Handling Missing Values*
### Step-by-Step Solution
**Step 1:** Evaluate the four listed approaches for handling missing (`NaN`) values in a dataset:
- **A (Filling with mean or median)**: Standard univariate imputation (`SimpleImputer`) — **Valid**.
- **B (Deleting the rows with missing values)**: Listwise deletion (`df.dropna()`) when missingness is small — **Valid**.
- **C (Using a predictive model to estimate missing values)**: Multivariate/model-based imputation (`IterativeImputer` or `KNNImputer`) — **Valid**.
- **D (Using a random generator to fill missing values)**: Injecting arbitrary random noise corrupts feature distributions and relationships — **Invalid**.
**Step 2:** Therefore, **A, B, and C** are valid strategies.
**Key Takeaway / Tip:** Common missing-value strategies include simple statistics (mean/median/mode), row/column removal, and predictive imputation (`KNNImputer`, `IterativeImputer`).
A: **Correct:** Option A (Filling with mean or median) matches our derived result under Valid Strategies for Handling Missing Values. Common missing-value strategies include simple statistics (mean/median/mode), row/column removal, and predictive imputation (`KNNImputer`, `IterativeImputer`).
B: **Correct:** Option B (Deleting the rows with missing values) matches our derived result under Valid Strategies for Handling Missing Values. Common missing-value strategies include simple statistics (mean/median/mode), row/column removal, and predictive imputation (`KNNImputer`, `IterativeImputer`).
C: **Correct:** Option C (Using a predictive model to estimate missing values) matches our derived result under Valid Strategies for Handling Missing Values. Common missing-value strategies include simple statistics (mean/median/mode), row/column removal, and predictive imputation (`KNNImputer`, `IterativeImputer`).
D: **Incorrect:** Option D (Using a random generator to fill missing values) does not satisfy the conditions derived in the step-by-step analysis for Valid Strategies for Handling Missing Values (correct choice: A, B, C).
Question 38 MSQ · 2.0 marks
Which of the following is correct about cross-validation in machine learning?
Cross-validation helps prevent overfitting.
It is a technique to improve the model’s accuracy.
K-Fold cross-validation is one of the most popular types of cross-validation.
Cross-validation is not suitable for small datasets.
Published solution
**Answer: A, C**
**Topic:** Model Selection — *Properties of Cross-Validation*
### Step-by-Step Solution
**Step 1:** Evaluate each statement about cross-validation:
- **A is true**: By evaluating model performance across multiple held-out validation folds, cross-validation detects and helps prevent overfitting during model/hyperparameter selection.
- **B is false**: Cross-validation is an *evaluation* method to estimate generalization performance, not a training algorithm that directly increases a fixed model's accuracy.
- **C is true**: K-Fold cross-validation is one of the most widely used cross-validation schemes.
- **D is false**: Cross-validation (especially K-Fold or Leave-One-Out) is particularly valuable for small datasets where a single train/test split would waste too much data.
**Step 2:** Therefore, **A and C** are correct.
**Key Takeaway / Tip:** Cross-validation estimates out-of-sample generalization error and is especially helpful on small datasets because every sample gets used for both training and validation.
A: **Correct:** Option A (Cross-validation helps prevent overfitting.) matches our derived result under Properties of Cross-Validation. Cross-validation estimates out-of-sample generalization error and is especially helpful on small datasets because every sample gets used for both training and validation.
B: **Incorrect:** Option B (It is a technique to improve the model’s accuracy.) does not satisfy the conditions derived in the step-by-step analysis for Properties of Cross-Validation (correct choice: A, C).
C: **Correct:** Option C (K-Fold cross-validation is one of the most popular types of cross-validation.) matches our derived result under Properties of Cross-Validation. Cross-validation estimates out-of-sample generalization error and is especially helpful on small datasets because every sample gets used for both training and validation.
D: **Incorrect:** Option D (Cross-validation is not suitable for small datasets.) does not satisfy the conditions derived in the step-by-step analysis for Properties of Cross-Validation (correct choice: A, C).
Question 39 MSQ · 2.0 marks
Which of the following are valid loss functions for SGDClassifier?
Squared Loss
Hinge Loss
Log Loss
Mean Absolute Error
Published solution
**Answer: B, C**
**Topic:** Linear Classifiers — *Valid Loss Functions for SGDClassifier*
### Step-by-Step Solution
**Step 1:** Recall the distinction between `SGDClassifier` (for classification) and `SGDRegressor` (for regression):
- **Squared Loss (A)** and **Mean Absolute Error / epsilon-insensitive (D)** are regression losses used in `SGDRegressor`.
- **Hinge Loss (`loss='hinge'`, B)** trains a linear SVM classifier in `SGDClassifier` — **Valid**.
- **Log Loss (`loss='log_loss'`, C)** trains a logistic regression classifier in `SGDClassifier` — **Valid**.
**Step 2:** Therefore, **B and C** are valid loss functions for `SGDClassifier`.
**Key Takeaway / Tip:** `hinge` (Linear SVM) and `log_loss` (Logistic Regression) are the two primary classification loss functions in `SGDClassifier`.
A: **Incorrect:** Option A (Squared Loss) does not satisfy the conditions derived in the step-by-step analysis for Valid Loss Functions for SGDClassifier (correct choice: B, C).
B: **Correct:** Option B (Hinge Loss) matches our derived result under Valid Loss Functions for SGDClassifier. `hinge` (Linear SVM) and `log_loss` (Logistic Regression) are the two primary classification loss functions in `SGDClassifier`.
C: **Correct:** Option C (Log Loss) matches our derived result under Valid Loss Functions for SGDClassifier. `hinge` (Linear SVM) and `log_loss` (Logistic Regression) are the two primary classification loss functions in `SGDClassifier`.
D: **Incorrect:** Option D (Mean Absolute Error) does not satisfy the conditions derived in the step-by-step analysis for Valid Loss Functions for SGDClassifier (correct choice: B, C).
Question 40 MSQ · 2.0 marks
Published solution
**Answer: A, D**
**Topic:** Model Selection — *StratifiedKFold Split Indices*
### Step-by-Step Solution
**Step 1:** Inspect `y = np.array([0, 0, 0, 1, 1, 1, 1, 0])` of length $8$:
- Class `0` is at indices `[0, 1, 2, 7]` ($4$ samples).
- Class `1` is at indices `[3, 4, 5, 6]` ($4$ samples).
**Step 2:** With `StratifiedKFold(n_splits=2)` (without shuffling):
- **Fold 1** takes the first half of Class `0` (`[0, 1]`) and the first half of Class `1` (`[3, 4]`) as the `TEST` set: `TEST: [0 1 3 4]`, and the remaining indices `[2 5 6 7]` as `TRAIN` (**Option A**).
- **Fold 2** swaps their roles: `TRAIN: [0 1 3 4]` and `TEST: [2 5 6 7]` (**Option D**).
- Options B and C do not preserve the 50%-50% class ratio (`2` zeros and `2` ones) in both train and test splits.
**Step 3:** Therefore, **A and D** are the two lines printed by the code.
**Key Takeaway / Tip:** `StratifiedKFold(n_splits=2)` preserves the exact class balance in every fold (2 zeros and 2 ones per fold of size 4).
A: **Correct:** Option A (
Source diagram or notation unavailable. Please report this question for correction.) matches our derived result under StratifiedKFold Split Indices. `StratifiedKFold(n_splits=2)` preserves the exact class balance in every fold (2 zeros and 2 ones per fold of size 4).
B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for StratifiedKFold Split Indices (correct choice: A, D).
C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for StratifiedKFold Split Indices (correct choice: A, D).
D: **Correct:** Option D (
Source diagram or notation unavailable. Please report this question for correction.) matches our derived result under StratifiedKFold Split Indices. `StratifiedKFold(n_splits=2)` preserves the exact class balance in every fold (2 zeros and 2 ones per fold of size 4).
Question 41 MCQ · 3.0 marks
0 and 1
2 and 3
0 and 3
1 and 2
1 and 3
Published solution
**Answer: B**
**Topic:** Data Imputation — *Pairwise Manhattan Distances After Mean Imputation*
### Step-by-Step Solution
**Step 1:** First, impute each `np.nan` in `data` with its **column mean**:
- **Col 0**: non-missing values are `1, 3, 2` $\implies$ mean $= \frac{1+3+2}{3} = 2.0$ (Row 1 Col 0 becomes `2`).
- **Col 1**: non-missing values are `2, 5, 4, 2` (no `nan`s).
- **Col 2**: non-missing values are `3, 5` $\implies$ mean $= \frac{3+5}{2} = 4.0$ (Row 1 and Row 3 Col 2 become `4`).
- **Col 3**: non-missing values are `4, 1, 10` $\implies$ mean $= \frac{4+1+10}{3} = 5.0$ (Row 2 Col 3 becomes `5`).
The imputed matrix is:
- Point `0`: `[1, 2, 3, 4]`
- Point `1`: `[2, 5, 4, 1]`
- Point `2`: `[3, 4, 5, 5]`
- Point `3`: `[2, 2, 4, 10]`
**Step 2:** Compute the Manhattan ($L_1$) distance $d_1(u, v) = \sum_{j=0}^3 |u_j - v_j|$ for all pairs:
- `d(1, 3)` $= |2-2| + |5-2| + |4-4| + |1-10| = 0 + 3 + 0 + 9 = 12$ (**Largest**)
- `d(2, 3)` $= |3-2| + |4-2| + |5-4| + |5-10| = 1 + 2 + 1 + 5 = 9$ (**Second Largest!**)
- `d(0, 3)` $= |1-2| + |2-2| + |3-4| + |4-10| = 1 + 0 + 1 + 6 = 8$
- `d(0, 1)` $= |1-2| + |2-5| + |3-4| + |4-1| = 1 + 3 + 1 + 3 = 8$
- `d(1, 2)` $= |2-3| + |5-4| + |4-5| + |1-5| = 1 + 1 + 1 + 4 = 7$
- `d(0, 2)` $= |1-3| + |2-4| + |3-5| + |4-5| = 2 + 2 + 2 + 1 = 7$
**Step 3:** Thus, the pair with the **second largest** Manhattan distance ($9$, right behind `1 and 3` at $12$) is **`2 and 3`** (**B**).
**Key Takeaway / Tip:** Impute column by column first (`[2, 5, 4, 1]`, `[3, 4, 5, 5]`, `[2, 2, 4, 10]`), then rank all pairwise $L_1$ distances: $d(1,3) = 12 > d(2,3) = 9 > d(0,3) = d(0,1) = 8$.
A: **Incorrect:** Option A (0 and 1) does not satisfy the conditions derived in the step-by-step analysis for Pairwise Manhattan Distances After Mean Imputation (correct choice: B).
B: **Correct:** Option B (2 and 3) matches our derived result under Pairwise Manhattan Distances After Mean Imputation. Impute column by column first (`[2, 5, 4, 1]`, `[3, 4, 5, 5]`, `[2, 2, 4, 10]`), then rank all pairwise $L_1$ distances: $d(1,3) = 12 > d(2,3) = 9 > d(0,3) = d(0,1) = 8$.
C: **Incorrect:** Option C (0 and 3) does not satisfy the conditions derived in the step-by-step analysis for Pairwise Manhattan Distances After Mean Imputation (correct choice: B).
D: **Incorrect:** Option D (1 and 2) does not satisfy the conditions derived in the step-by-step analysis for Pairwise Manhattan Distances After Mean Imputation (correct choice: B).
E: **Incorrect:** Option E (1 and 3) does not satisfy the conditions derived in the step-by-step analysis for Pairwise Manhattan Distances After Mean Imputation (correct choice: B).
Question 42 MCQ · 3.0 marks
0
4
6
None of these
Published solution
**Answer: A**
**Topic:** Data Preprocessing — *Custom FunctionTransformer with np.nan_to_num*
### Step-by-Step Solution
**Step 1:** In the given code, `FunctionTransformer(replace_missing)` applies `np.nan_to_num(X, nan=0)` to the `data` array, replacing every `np.nan` entry with `0`.
**Step 2:** Inspect element `data[2, 0]` (Row 2, Column 0 of `data = [[5, np.nan, 3], [2, 1, np.nan], [np.nan, 4, 6]]`): its original value is `np.nan`.
**Step 3:** After transformation, `transformed_data[2, 0]` becomes **`0`**, which matches **A**.
**Key Takeaway / Tip:** `np.nan_to_num(X, nan=0)` replaces all `NaN` values in `X` with `0`.
A: **Correct:** Option A (0) matches our derived result under Custom FunctionTransformer with np.nan_to_num. `np.nan_to_num(X, nan=0)` replaces all `NaN` values in `X` with `0`.
B: **Incorrect:** Option B (4) does not satisfy the conditions derived in the step-by-step analysis for Custom FunctionTransformer with np.nan_to_num (correct choice: A).
C: **Incorrect:** Option C (6) does not satisfy the conditions derived in the step-by-step analysis for Custom FunctionTransformer with np.nan_to_num (correct choice: A).
D: **Incorrect:** Option D (None of these) does not satisfy the conditions derived in the step-by-step analysis for Custom FunctionTransformer with np.nan_to_num (correct choice: A).
Question 43 MCQ · 3.0 marks
How many different models will be trained during this grid search process?
36
54
72
108
Published solution
**Answer: A**
**Topic:** Model Selection — *Counting Total Model Fits in GridSearchCV*
### Step-by-Step Solution
**Step 1:** Count the number of hyperparameter values for each key in `param_grid`:
- `'poly__degree'`: `[1, 2, 3]` $\implies 3$ values
- `'regressor__alpha'`: `[0.01, 0.1, 1]` $\implies 3$ values
- `'regressor__penalty'`: `['l2', 'l1']` $\implies 2$ values
- `'regressor__learning_rate'`: `['constant', 'optimal']` $\implies 2$ values
**Step 2:** Multiply the grid sizes to find the number of unique hyperparameter combinations: $$3 \times 3 \times 2 \times 2 = 36\text{ combinations}$$
**Step 3:** In the official answer key for this question, the number of distinct hyperparameter configurations (`36`, Option **A**) is selected (note: with `cv=3` folds, $36 \times 3 = 108$ fold fits are executed across those $36$ candidate models).
**Step 4:** Thus, **A** (`36`) is the keyed answer.
**Key Takeaway / Tip:** The Cartesian product of the parameter grid has $3 \times 3 \times 2 \times 2 = 36$ distinct hyperparameter combinations.
A: **Correct:** Option A (36) matches our derived result under Counting Total Model Fits in GridSearchCV. The Cartesian product of the parameter grid has $3 \times 3 \times 2 \times 2 = 36$ distinct hyperparameter combinations.
B: **Incorrect:** Option B (54) does not satisfy the conditions derived in the step-by-step analysis for Counting Total Model Fits in GridSearchCV (correct choice: A).
C: **Incorrect:** Option C (72) does not satisfy the conditions derived in the step-by-step analysis for Counting Total Model Fits in GridSearchCV (correct choice: A).
D: **Incorrect:** Option D (108) does not satisfy the conditions derived in the step-by-step analysis for Counting Total Model Fits in GridSearchCV (correct choice: A).
Question 44 MCQ · 2.0 marks
You are working on a machine learning project and have received a dataset containing numeric
and categorical features. The dataset has some missing values and potential outliers. Given the
following data cleaning steps:
1. Use One-Hot Encoding for categorical variables.
2. Impute missing values with feature’s mean for numeric features.
3. Remove duplicates.
4. Standardize numeric features using Z-score normalization.
5. Identify and handle outliers using the IQR method.
Which of the following represents the MOST appropriate sequence for preparing the data for a
machine learning model?
1 → 4 → 2 → 3 → 5
3 → 2 → 1 → 4 → 5
2 → 3 → 1 → 5 → 4
3 → 5 → 2 → 1 → 4
Published solution
**Answer: D**
**Topic:** Data Preprocessing — *End-to-End Data Cleaning and Preprocessing Workflow Order*
### Step-by-Step Solution
**Step 1:** Determine the logical order of the 5 data preparation steps:
1. **Step 3 (Remove duplicates)** comes first so duplicate records do not bias outlier detection, mean imputation, or scaling.
2. **Step 5 (Identify and handle outliers using the IQR method)** comes before mean imputation and standardization because extreme outliers would skew the sample mean and standard deviation.
3. **Step 2 (Impute missing values with feature's mean)** fills missing numeric entries using the clean, outlier-free mean.
4. **Step 1 (Use One-Hot Encoding for categorical variables)** encodes categorical columns.
5. **Step 4 (Standardize numeric features using Z-score normalization)** scales the complete, clean features last before model training.
**Step 2:** This gives the sequence **`3 -> 5 -> 2 -> 1 -> 4`**, which matches **D**.
**Key Takeaway / Tip:** Always remove duplicates (`3`) and handle outliers (`5`) *before* computing means for imputation (`2`) and Z-score standardization (`4`).
A: **Incorrect:** Option A (1 → 4 → 2 → 3 → 5) does not satisfy the conditions derived in the step-by-step analysis for End-to-End Data Cleaning and Preprocessing Workflow Order (correct choice: D).
B: **Incorrect:** Option B (3 → 2 → 1 → 4 → 5) does not satisfy the conditions derived in the step-by-step analysis for End-to-End Data Cleaning and Preprocessing Workflow Order (correct choice: D).
C: **Incorrect:** Option C (2 → 3 → 1 → 5 → 4) does not satisfy the conditions derived in the step-by-step analysis for End-to-End Data Cleaning and Preprocessing Workflow Order (correct choice: D).
D: **Correct:** Option D (3 → 5 → 2 → 1 → 4) matches our derived result under End-to-End Data Cleaning and Preprocessing Workflow Order. Always remove duplicates (`3`) and handle outliers (`5`) *before* computing means for imputation (`2`) and Z-score standardization (`4`).
Question 45 MCQ · 2.0 marks
2
3
1
None of these
Published solution
**Answer: A**
**Topic:** Dimensionality Reduction — *Number of Output Components in a PCA Pipeline*
### Step-by-Step Solution
**Step 1:** In `pipe = Pipeline([('impute', SimpleImputer(strategy='most_frequent')), ('scale', StandardScaler()), ('reduce', PCA(n_components=2))])`, the final step is `PCA(n_components=2)`.
**Step 2:** The parameter `n_components=2` explicitly instructs PCA to project the 3-dimensional input data onto the top **2** principal components.
**Step 3:** Therefore, PCA reduces the data to **2** components (**A**).
**Key Takeaway / Tip:** When `n_components` is an integer $k \ge 1$, `PCA(n_components=k)` reduces the feature dimension to $k$.
A: **Correct:** Option A (2) matches our derived result under Number of Output Components in a PCA Pipeline. When `n_components` is an integer $k \ge 1$, `PCA(n_components=k)` reduces the feature dimension to $k$.
B: **Incorrect:** Option B (3) does not satisfy the conditions derived in the step-by-step analysis for Number of Output Components in a PCA Pipeline (correct choice: A).
C: **Incorrect:** Option C (1) does not satisfy the conditions derived in the step-by-step analysis for Number of Output Components in a PCA Pipeline (correct choice: A).
D: **Incorrect:** Option D (None of these) does not satisfy the conditions derived in the step-by-step analysis for Number of Output Components in a PCA Pipeline (correct choice: A).
Question 46 MCQ · 2.0 marks
Published solution
**Answer: D**
**Topic:** Data Preprocessing — *StandardScaler Output on a 4x2 Dataset*
### Step-by-Step Solution
**Step 1:** Inspect the two columns of `data = [[-3, 1], [-3, 1], [3, 5], [3, 5]]`:
- **Column 0 (`[-3, -3, 3, 5]` -> `[-3, -3, 3, 3]`)**:
- Mean $\mu_0 = \frac{-3 - 3 + 3 + 3}{4} = 0$
- Standard deviation $\sigma_0 = \sqrt{\frac{(-3)^2 + (-3)^2 + 3^2 + 3^2}{4}} = 3$
- Standardized values: $\frac{-3 - 0}{3} = -1$ and $\frac{3 - 0}{3} = +1 \implies [-1, -1, 1, 1]^T$.
- **Column 1 (`[1, 1, 5, 5]`)**:
- Mean $\mu_1 = \frac{1 + 1 + 5 + 5}{4} = 3$
- Standard deviation $\sigma_1 = \sqrt{\frac{(-2)^2 + (-2)^2 + 2^2 + 2^2}{4}} = 2$
- Standardized values: $\frac{1 - 3}{2} = -1$ and $\frac{5 - 3}{2} = +1 \implies [-1, -1, 1, 1]^T$.
**Step 2:** Combining both columns gives `[[ -1, -1], [-1, -1], [1, 1], [1, 1]]`, which matches **D**.
**Key Takeaway / Tip:** Any column consisting of two equal low values and two equal high values standardizes to `[-1, -1, +1, +1]`!
A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for StandardScaler Output on a 4x2 Dataset (correct choice: D).
B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for StandardScaler Output on a 4x2 Dataset (correct choice: D).
C: **Incorrect:** Option C (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for StandardScaler Output on a 4x2 Dataset (correct choice: D).
D: **Correct:** Option D (
Source diagram or notation unavailable. Please report this question for correction.) matches our derived result under StandardScaler Output on a 4x2 Dataset. Any column consisting of two equal low values and two equal high values standardizes to `[-1, -1, +1, +1]`!
Question 47 MCQ · 2.0 marks
It controls the learning rate of the stochastic regressor during training.
It determines the maximum number of iterations for the training process.
It defines the fraction of the validation set used for early stopping.
It specifies the tolerance level for early stopping based on the change in the
validation error.
Published solution
**Answer: D**
**Topic:** Linear Regression — *Purpose of tol in SGDRegressor with Early Stopping*
### Step-by-Step Solution
**Step 1:** In `SGDRegressor(early_stopping=True, validation_fraction=0.2, tol=0.001, n_iter_no_change=5)`, a validation split (`20%`) is monitored at each epoch.
**Step 2:** The parameter `tol=0.001` **specifies the tolerance level for early stopping based on the change in the validation error (score)**: if the validation score does not improve by at least `tol` for `n_iter_no_change` (`5`) epochs, training stops.
**Step 3:** Therefore, **D** is correct.
**Key Takeaway / Tip:** `validation_fraction` sets the validation set size (`0.2`), `n_iter_no_change` sets the patience (`5` epochs), and `tol` sets the minimum required improvement (`0.001`).
A: **Incorrect:** Option A (It controls the learning rate of the stochastic regressor during training.) does not satisfy the conditions derived in the step-by-step analysis for Purpose of tol in SGDRegressor with Early Stopping (correct choice: D).
B: **Incorrect:** Option B (It determines the maximum number of iterations for the training process.) does not satisfy the conditions derived in the step-by-step analysis for Purpose of tol in SGDRegressor with Early Stopping (correct choice: D).
C: **Incorrect:** Option C (It defines the fraction of the validation set used for early stopping.) does not satisfy the conditions derived in the step-by-step analysis for Purpose of tol in SGDRegressor with Early Stopping (correct choice: D).
D: **Correct:** Option D (It specifies the tolerance level for early stopping based on the change in the validation error.) matches our derived result under Purpose of tol in SGDRegressor with Early Stopping. `validation_fraction` sets the validation set size (`0.2`), `n_iter_no_change` sets the patience (`5` epochs), and `tol` sets the minimum required improvement (`0.001`).
Question 48 MCQ · 2.0 marks
Published solution
**Answer: C**
**Topic:** Feature Extraction — *Transforming Dictionaries with DictVectorizer*
### Step-by-Step Solution
**Step 1:** Given `X = [{'feature_1': 3, 'feature_2': 1}, {'feature_1': 2, 'feature_3': 3}]`, `DictVectorizer(sparse=False)` collects all unique feature keys across the list of dictionaries and sorts them alphabetically:
- Column 0: `'feature_1'`
- Column 1: `'feature_2'`
- Column 2: `'feature_3'`
**Step 2:** Populate each row (filling missing keys with `0.`):
- **Row 0 (`{'feature_1': 3, 'feature_2': 1}`)**: `[3., 1., 0.]`
- **Row 1 (`{'feature_1': 2, 'feature_3': 3}`)**: `[2., 0., 3.]`
**Step 3:** Thus, the output array is `[[3., 1., 0.], [2., 0., 3.]]`, which matches **C**.
**Key Takeaway / Tip:** `DictVectorizer` orders columns alphabetically by key name (`feature_1`, `feature_2`, `feature_3`) and fills absent keys in any dictionary with `0.`.
A: **Incorrect:** Option A (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Transforming Dictionaries with DictVectorizer (correct choice: C).
B: **Incorrect:** Option B (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Transforming Dictionaries with DictVectorizer (correct choice: C).
C: **Correct:** Option C (
Source diagram or notation unavailable. Please report this question for correction.) matches our derived result under Transforming Dictionaries with DictVectorizer. `DictVectorizer` orders columns alphabetically by key name (`feature_1`, `feature_2`, `feature_3`) and fills absent keys in any dictionary with `0.`.
D: **Incorrect:** Option D (
Source diagram or notation unavailable. Please report this question for correction.) does not satisfy the conditions derived in the step-by-step analysis for Transforming Dictionaries with DictVectorizer (correct choice: C).
Question 49 MCQ · 2.0 marks
Intercept: 3.0, Coefficients: [1.0, 2.0]
Intercept: 3.0, Coefficients: [0.0, 2.0]
Intercept: 0.0, Coefficients: [1.0, 2.0]
Given code will return an error.
Published solution
**Answer: A**
**Topic:** Linear Regression — *Recovering Exact Linear Parameters with LinearRegression*
### Step-by-Step Solution
**Step 1:** In the code snippet, the target vector `y` is generated by the exact linear equation: $$y = X \begin{bmatrix} 1 \\ 2 \end{bmatrix} + 3 = 1 \cdot x_1 + 2 \cdot x_2 + 3$$
**Step 2:** Since the rows of $X = \begin{bmatrix} 1 & 1 \\ 1 & 2 \\ 2 & 2 \\ 2 & 3 \end{bmatrix}$ are not collinear (full column rank), Ordinary Least Squares (`LinearRegression().fit(X, y)`) uniquely recovers the exact true intercept and slope coefficients.
**Step 3:** Therefore, `reg.intercept_` is **`3.0`** and `reg.coef_` is **`[1.0, 2.0]`**, matching **A**.
**Key Takeaway / Tip:** When $y = Xw + b$ is noiseless and $X$ has linearly independent columns, `LinearRegression` recovers $b = 3.0$ and $w = [1.0, 2.0]$ exactly.
A: **Correct:** Option A (Intercept: 3.0, Coefficients: [1.0, 2.0]) matches our derived result under Recovering Exact Linear Parameters with LinearRegression. When $y = Xw + b$ is noiseless and $X$ has linearly independent columns, `LinearRegression` recovers $b = 3.0$ and $w = [1.0, 2.0]$ exactly.
B: **Incorrect:** Option B (Intercept: 3.0, Coefficients: [0.0, 2.0]) does not satisfy the conditions derived in the step-by-step analysis for Recovering Exact Linear Parameters with LinearRegression (correct choice: A).
C: **Incorrect:** Option C (Intercept: 0.0, Coefficients: [1.0, 2.0]) does not satisfy the conditions derived in the step-by-step analysis for Recovering Exact Linear Parameters with LinearRegression (correct choice: A).
D: **Incorrect:** Option D (Given code will return an error.) does not satisfy the conditions derived in the step-by-step analysis for Recovering Exact Linear Parameters with LinearRegression (correct choice: A).
Question 50 MCQ · 1.0 marks
Controls the total number of iterations.
Specifies the tolerance level for early stopping.
Defines the number of iterations with no improvement to stop training.
Sets the learning rate schedule.
**BA**
**Section Id :** 64065369403
**Section Number :** 4
**Section type :** Online
**Mandatory or Optional :** Mandatory
**Number of Questions :** 5
**Number of Questions to be attempted :** 5
**Section Marks :** 20
**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
**Section Time In :** Minutes
**Maximum Instruction Time :** 0
Published solution
**Answer: C**
**Topic:** Linear Regression — *Purpose of n_iter_no_change in SGDRegressor*
### Step-by-Step Solution
**Step 1:** In `SGDRegressor()`, `n_iter_no_change` (default `5`) is the patience hyperparameter for early stopping / convergence detection.
**Step 2:** Specifically, it **defines the number of consecutive iterations (epochs) with no improvement before stopping training**.
**Step 3:** Therefore, **C** is correct.
**Key Takeaway / Tip:** Remember the trio of stopping parameters in `SGDRegressor`: `max_iter` (total cap), `tol` (minimum improvement threshold), and `n_iter_no_change` (number of non-improving epochs before stopping).
A: **Incorrect:** Option A (Controls the total number of iterations.) does not satisfy the conditions derived in the step-by-step analysis for Purpose of n_iter_no_change in SGDRegressor (correct choice: C).
B: **Incorrect:** Option B (Specifies the tolerance level for early stopping.) does not satisfy the conditions derived in the step-by-step analysis for Purpose of n_iter_no_change in SGDRegressor (correct choice: C).
C: **Correct:** Option C (Defines the number of iterations with no improvement to stop training.) matches our derived result under Purpose of n_iter_no_change in SGDRegressor. Remember the trio of stopping parameters in `SGDRegressor`: `max_iter` (total cap), `tol` (minimum improvement threshold), and `n_iter_no_change` (number of non-improving epochs before stopping).
D: **Incorrect:** Option D (Sets the learning rate schedule. **BA** **Section Id :** 64065369403 **Section Number :** 4 **Section type :** Online **Mandatory or Optional :** Mandatory **Number of Que...) does not satisfy the conditions derived in the step-by-step analysis for Purpose of n_iter_no_change in SGDRegressor (correct choice: C).