uiz Space

January 2025 term · Machine Learning Practice · BSCS2008

Machine Learning Practice End Term: 13 April 2025, Set QDD1 (January 2025 term)

The IIT Madras BS Machine Learning Practice (MLP) End Term paper sat on 13 Apr 2025, in the January 2025 term, set QDD1: 30 questions for 50 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
30
Marks
50
Duration
180 min
MCQ
16
Numerical
7
MSQ
7

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD3 13 Apr 2025 · No negative marking.

Question 1

+1 markOne correct option

Given the following code snippet that preprocesses a dataset with both continuous and categorical features using sklearn.preprocessing tools, what will be the first row of the X_transformed array after preprocessing?

python
import numpy as np
from sklearn.preprocessing import MinMaxScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
X = np.array([[2.0, 'apple'],
[5.0, 'banana'],
[1.0, 'apple'],
[4.0, 'cherry']])
preprocessor = ColumnTransformer(
transformers=[('num', MinMaxScaler(), [0]),
('cat', OneHotEncoder(), [1])])
X_transformed = preprocessor.fit_transform(X)
print(X_transformed[0])
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 2

+1 markOne correct option

What will be the output of the following code?

python
import pandas as pd
from sklearn.preprocessing import StandardScaler
data = pd.DataFrame({
'col1': [1, 2, 3, 4, 5],
'col2': [10, 20, 30, 40, 50]
})
ss = StandardScaler()
scaled_data = ss.fit_transform(data)
print(ss.var_)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 3

+1 markOne correct option

Imagine you are using a Dummy Regressor with strategy=median. Given the following dataset:

S.NoX1X_1X2X_2X3X_3YY
12.34.53.210.5
21.83.24.112.3
32.54.12.911.1
42.03.83.59.8
51.93.63.010.9
62.44.23.311.5

What will be the predicted output for an input X = [2.1,3.9,3.2] ?

  1. A

    10.5

  2. B

    11.0

  3. C

    11.5

  4. D

    12.3

Show answer

Correct answer

  • B

    11.0

Question 4

+1 markOne correct option

You want to implement an SGDRegressor using scikit-learn with the following specifications:

  • Maximum iterations: 1000
  • Early stopping enabled
  • Learning rate schedule: Adaptive
  • Power tuning for adaptive learning rate: 0.75
  • Tolerance for stopping criteria: 1e-3
  • L2 regularization with strength: 0.01

Which of the following code snippets correctly implements this?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 5

+1 markOne correct option

What is the primary computational bottleneck of the KNeighborsClassifier?

  1. A

    Training the model.

  2. B

    Choosing the best k value.

  3. C

    Storing and searching through all training samples at prediction time.

  4. D

    Calculating class probabilities.

Show answer

Correct answer

  • C

    Storing and searching through all training samples at prediction time.

Question 6

+1 markOne correct option
  1. A

    Increasing the number of hidden layers always improves regression accuracy.

  2. B

    Using the ReLU activation function in hidden layers is a good choice for MLP regression.

  3. C

    The output layer should use a softmax activation to predict continuous house prices.

  4. D

    MLPRegressor does not require feature scaling since neural networks automatically normalize input data.

Show answer

Correct answer

  • B

    Using the ReLU activation function in hidden layers is a good choice for MLP regression.

Question 7

+2 marksOne correct option

The following code attempts to implement polynomial regression (degree 4) on the California housing dataset. Please select the appropriate option to complete the missing part correctly

python
import numpy as np
import pandas as pd
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import Pipeline
# Load dataset
housing = fetch_california_housing()
X, y = housing.data, housing.target
# Split into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Define the polynomial regression model
model = Pipeline([
('poly', PolynomialFeatures(degree=4)),
('linear', LinearRegression())
])
# Missing part
# Make predictions
y_pred = model.predict(X_test)

Which of the following correctly fills the missing part blank while ensuring correct preprocessing and avoiding common pitfalls?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 8

+2 marksOne correct option

Given the following information, what will be the output of the code snippet?

  • continuous: yy is an array-like of floats that are not all integers, and is 1D or a column vector.
  • continuous-multioutput: yy is a 2D array of floats that are not all integers, and both dimensions are of size >1> 1.
  • binary: yy contains ≤2\leq 2 discrete values and is 1D or a column vector.
  • multiclass: yy contains more than two discrete values, is not a sequence of sequences, and is 1D or a column vector.
  • multiclass-multioutput: yy is a 2D array that contains more than two discrete values, is not a sequence of sequences, and both dimensions are of size >1> 1.
  • multilabel-indicator: yy is a label indicator matrix, an array of two dimensions with at least two columns, and at most 2 unique values.
  • unknown: yy is array-like but none of the above, such as a 3D array, sequence of sequences, or an array of non-sequence objects.
python
from sklearn.utils.multiclass import type_of_target
import numpy as np
print(type_of_target(['a', 'b', 'a']))
print(type_of_target(np.array([['horror','fantasy'],
['adventure','fantasy'],
['adventure','fantasy']])))
print(type_of_target(np.array([[2.0, 3.0], [3.0, 2.0]])))
print(type_of_target(np.array([[0, 1], [1, 1]])))
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 9

+2 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 10

+2 marksOne correct option

What will be the output of the following code snippet?

python
from sklearn.neighbors import KNeighborsClassifier
X = [[0], [1], [2], [3]]
y = [0, 0, 1, 1]
knn_clf = KNeighborsClassifier(n_neighbors=3,p=1,metric='minkowski')
knn_clf.fit(X, y)
print(len(knn_clf.classes_))
print(knn_clf.effective_metric_)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 11

+2 marksOne correct option

The following code snippet shows the use of two models built on the data XX and label yy:

python
import numpy as np
from sklearn.preprocessing import MinMaxScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.pipeline import Pipeline
X = np.array([[0, 0], [0.25, 0.25], [0.5, 0.5], [0.75, 0.75], [1, 1]])
y = np.array([0, 0, 1, 1, 0])
model_1 = Pipeline([
('knn', KNeighborsClassifier(n_neighbors=3))
])
model_2 = Pipeline([
('scaler', MinMaxScaler()),
('knn', KNeighborsClassifier(n_neighbors=3))
])
model_1.fit(X, y)
model_2.fit(X, y)

For the given data, which of the following options is correct?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 12

+2 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 13

+2 marksOne correct option
  1. A

    It can only be used with classifiers that output probabilities.

  2. B

    When voting=‘hard’, it chooses the class with the highest sum of predicted probabilities.

  3. C

    When voting=‘soft’, it averages the predicted probabilities and picks the class with the highest probability.

  4. D

    It cannot be used with Pipeline objects.

Show answer

Correct answer

  • C

    When voting=‘soft’, it averages the predicted probabilities and picks the class with the highest probability.

Question 14

+2 marksOne correct option
  1. A

    Convert images to grayscale.

  2. B

    Scaling the data using Min-Max Scaling

  3. C

    Apply PCA to reduce feature dimensions.

  4. D

    One-Hot encode the target labels (digits 0-9)

Show answer

Correct answer

  • B

    Scaling the data using Min-Max Scaling

Question 15

+3 marksNumerical answer

Consider the following Python code snippet and the given dataset that has been stored in the data variable that demonstrates the use of GaussianNB from scikit-learn:

python
data.head() # output shown below
OutlookTemperatureHumidityWindyPlay Golf
0RainyHotHighFalseNo
1OvercastHotHighFalseYes
2SunnyCoolNormalFalseYes
3SunnyCoolNormalTrueNo
4OvercastCoolNormalTrueYes
5RainyCoolNormalFalseYes
6RainyHotHighTrueNo
7OvercastHotHighFalseYes
8SunnyCoolNormalTrueNo
9OvercastCoolNormalTrueYes
10RainyCoolNormalFalseYes
11OvercastHotNormalFalseYes
python
from sklearn.preprocessing import OneHotEncoder, LabelEncoder
from sklearn.naive_bayes import GaussianNB
X = data.drop("Play Golf", axis=1)
y = data["Play Golf"]
X = OneHotEncoder(sparse_output=False).fit_transform(X)
y = LabelEncoder().fit_transform(y)
estimator = GaussianNB()
estimator.fit(X,y)
print(estimator.class_prior_) # gives the priori of labels(y)

What is the prior probability of the label being “Yes”? i.e. p(y=“Yes”)p(y = \text{“}Yes\text{”})

Show answer

Correct answer: 0.6695 (accepted within ±0.0105)

Question 16

+3 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 17

+2 marksOne or more correct options

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • A
  • C

Question 18

+2 marksOne or more correct options

Which of the following techniques can be used for hyperparameter tuning in Ridge Regression? Select all correct options.

Select all that apply.

  1. A

    GridSearchCV

  2. B

    ElasticNetCV

  3. C

    RandomizedSearchCV

  4. D

    Mini batch gradient descent

Show answer

Correct answers

  • A

    GridSearchCV

  • C

    RandomizedSearchCV

Question 19

+2 marksOne or more correct options

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • A
  • B
  • C

Question 20

+2 marksOne or more correct options

In top-down (divisive) hierarchical clustering, clusters are recursively split until each data point is its own cluster. The choice of a distance metric plays a crucial role in determining the quality of clustering.
Which of the following distance (similarity) metrics are commonly used in hierarchical clustering?

Select all that apply.

  1. A

    Euclidean Distance

  2. B

    Manhattan Distance

  3. C

    Jaccard Similarity

  4. D

    Cosine Distance

Show answer

Correct answers

  • A

    Euclidean Distance

  • B

    Manhattan Distance

  • D

    Cosine Distance

Question 21

+2 marksOne or more correct options

You are training a Multi-Layer Perceptron (MLP) using Scikit-Learn's MLPClassifier for a binary classification task. However, some implementations contain syntax errors. Which of the following implementations are syntactically correct? Select all that apply.

python
from sklearn.neural_network import MLPClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
X, y = make_classification(n_samples=1500, n_features=30, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
model = ----------------- #fill in the blank
model.fit(X_train, y_train)

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • A
  • C

Question 22

+3 marksOne or more correct options

Which of the following statements are true with regard to logistic regression?

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • B
  • C

Question 23

+1 markNumerical answer

Consider the following code snippet:

python
from sklearn.datasets import fetch_california_housing, load_iris
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler, PolynomialFeatures
from sklearn.pipeline import Pipeline, FeatureUnion
X,y = load_iris(return_X_y= True)
polynomial_transform = PolynomialFeatures(degree=3,
interaction_only=False,
include_bias=False)
combined_features = FeatureUnion([('poly', polynomial_transform),
('pca', PCA(n_components=2))])
pipeline = Pipeline([('features', combined_features),
('scaler', MinMaxScaler())])
X_transformed = pipeline.fit_transform(X)
print(X_transformed.shape)

If the shape of X is (150,4)(150, 4), what will be the number of features in X_transformed?

Show answer

Correct answer: 36

Question 24

+2 marksNumerical answer

Use the confusion matrix given below. What is the recall score for the label (class) 1 ?

Show answer

Correct answer: 0.10

Question 25

+1 markOne or more correct options

Based on the above data, answer the given subquestions.

Select all that apply.

  1. A
  2. B
  3. C
  4. D
  5. E
Show answer

Correct answers

  • A
  • C

Question 26

+1 markNumerical answer

Based on the above data, answer the given subquestions.

Show answer

Correct answer: 120

Question 27

+1 markNumerical answer

Based on the above data, answer the given subquestions.

What is the output of the following code snippet:

python
def getPassing(aRow):
if aRow['Maths']>=40 and aRow['History']>=40:
return True
return False
df.apply(getPassing).sum()

Enter -1, if you think the above statement will generate an error.

Show answer

Correct answer: -1

Question 28

+1 markOne correct option

Consider following common data:

python
print("Classification Report:\n", classification_report(y_test, y_pred))
text
Classification Report:
precision recall f1-score support
0 0.86 0.67 0.75 9
1 0.97 0.99 0.98 105
accuracy 0.96 114
macro avg 0.91 0.83 0.87 114
weighted avg 0.96 0.96 0.96 114

Consider the above classification report on a model where y_test contains the original labels and y_pred contains the predicted labels.

Based on the above data, answer the given subquestions.

Consider the following assertion & reason and select the correct option:
Assertion: This is a good model as we see a very high accuracy of 96%
Reason: In the case of imbalanced datasets, accuracy might not be the best metric for evaluating a model

  1. A

    Both the assertion and reason are correct, and the reason is a correct explanation of the assertion

  2. B

    Both the assertion and reason are correct, but the reason is not a correct explanation of the assertion.

  3. C

    The assertion is correct, but the reason is incorrect.

  4. D

    The assertion is incorrect, but the reason is correct.

Show answer

Correct answer

  • D

    The assertion is incorrect, but the reason is correct.

Question 29

+1 markNumerical answer

Consider following common data:

python
print("Classification Report:\n", classification_report(y_test, y_pred))
text
Classification Report:
precision recall f1-score support
0 0.86 0.67 0.75 9
1 0.97 0.99 0.98 105
accuracy 0.96 114
macro avg 0.91 0.83 0.87 114
weighted avg 0.96 0.96 0.96 114

Consider the above classification report on a model where y_test contains the original labels and y_pred contains the predicted labels.

Based on the above data, answer the given subquestions.

How many points belong to class 1 in the original dataset?

Show answer

Correct answer: 105

Question 30

+1 markNumerical answer

Consider following common data:

python
print("Classification Report:\n", classification_report(y_test, y_pred))
text
Classification Report:
precision recall f1-score support
0 0.86 0.67 0.75 9
1 0.97 0.99 0.98 105
accuracy 0.96 114
macro avg 0.91 0.83 0.87 114
weighted avg 0.96 0.96 0.96 114

Consider the above classification report on a model where y_test contains the original labels and y_pred contains the predicted labels.

Based on the above data, answer the given subquestions.

Show answer

Correct answer: 0.98