uiz Space

January 2025 term · Machine Learning Practice · BSCS2008

Machine Learning Practice End Term: 13 April 2025, Set QDD3 (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 QDD3: 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
20
MSQ
6
Numerical
4

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

    [0.25, 1, 0, 0]

  2. B

    [0.5, 0, 1, 0]

  3. C

    [0, 1, 0, 0]

  4. D

    [1, 0, 0, 1]

Show answer

Correct answer

  • A

    [0.25, 1, 0, 0]

Question 2

+1 markOne correct option

Consider the following code snippet:

python
from sklearn.datasets import fetch_california_housing
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler, PolynomialFeatures
from sklearn.pipeline import Pipeline, FeatureUnion
data = fetch_california_housing()
X = data.data
polynomial_transform = PolynomialFeatures(degree=2, include_bias=False)
pca_transform = PCA(n_components=5)
scaler = StandardScaler()
combined_features = FeatureUnion([ ('poly', polynomial_transform),
('pca', pca_transform)])
pipeline = Pipeline([ ('features', combined_features),
('scaler', scaler)])
X_transformed = pipeline.fit_transform(X)
print(X_transformed.shape)

If the shape of X is (20640,8)(20640, 8), what will be the shape of X_transformed?

  1. A

    (20640, 8)

  2. B

    (20640, 5)

  3. C

    (20640, 44)

  4. D

    (20640, 49)

Show answer

Correct answer

  • D

    (20640, 49)

Question 3

+1 markOne correct option

Consider you are using a Dummy Regression with strategy=mean. Consider the following dataset.

S.NoX1X_1X2X_2X3X_3YY
13.15.24.014.2
22.74.83.513.7
33.35.04.215.1
42.94.53.812.9
53.04.73.913.5
63.25.14.114.5

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

  1. A

    13.6

  2. B

    14.0

  3. C

    14.2

  4. D

    14.5

Show answer

Correct answer

  • B

    14.0

Question 4

+1 markOne correct option

You want to implement an SGDRegressor with the following specifications:

  • Maximum iterations: 1500
  • Early stopping enabled
  • Learning rate schedule: invscaling
  • Power tuning for invscaling learning rate: 0.6
  • Tolerance for stopping criteria: 1e-4
  • L1 regularization with strength: 0.005

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

+2 marksOne correct option

The following code attempts to implement Ridge regression on the Boston housing dataset but contains an error. The missing part should be correctly filled in to avoid issues during training.

python
import numpy as np
import pandas as pd
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import Ridge
from sklearn.pipeline import Pipeline
# Load dataset
data = load_boston()
X, y = data.data, data.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 Ridge regression model with standardization
model = Pipeline([
('scaler', StandardScaler()),
('ridge', Ridge(alpha=1.0))
])
# Missing part
# Make predictions
y_pred = model.predict(X_test)

Which of the following correctly fills the missing part while ensuring proper preprocessing?

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

Correct answer

  • A

Question 7

+2 marksOne correct option

Which of the following techniques can be used for hyperparameter tuning in SGD Regression?

  1. A

    GridSearchCV

  2. B

    ElasticNetCV

  3. C

    SelectKBest

  4. D

    Feature Scaling with StandardScaler

Show answer

Correct answer

  • A

    GridSearchCV

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([[1.5, 2.0], [3.0, 1.6]])))
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

  • B

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 decides how many features are to be considered by each of the estimators

  2. B

    It signifies the influence of each estimator towards the prediction

  3. C

    It offers the order in which each estimator is considered before making a prediction

  4. D

    It provides weights to different classes in a multiclass classification problem

Show answer

Correct answer

  • B

    It signifies the influence of each estimator towards the prediction

Question 14

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

Correct answer

  • D

Question 15

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

Correct answer

  • B

Question 16

+3 marksOne correct option

Consider the following Python code snippet that demonstrates the use of GaussianNB from scikit-learn:

python
from sklearn.naive_bayes import GaussianNB
import numpy as np
X = np.array([[1.0, 2.0],
[2.5, 3.5],
[3.0, 5.0]])
y = np.array([0, 1, 0])
classifier = GaussianNB()
classifier.fit(X, y)
new_data = np.array([[2.0, 3.0]])
predicted_proba = classifier.predict_proba(new_data)

In the context of the code above, what information does the array predicted_proba contain?

  1. A

    The predicted classes for the new data points.

  2. B

    The decision boundary values for the classes.

  3. C

    The posterior probabilities of the classes for the new data points.

  4. D

    The likelihood estimates for the new data points.

Show answer

Correct answer

  • C

    The posterior probabilities of the classes for the new data points.

Question 17

+3 marksOne or more correct options

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

Select all that apply.

  1. A

    The decision boundary of a logistic regression model is always a straight line.

  2. B

    The solver parameter in logistic regression determines the optimization algorithm used for training the model.

  3. C

    Logistic regression can naturally handle multi-class classification without any modifications.

  4. D

    The regularization strength in logistic regression can be controlled using the C parameter.

Show answer

Correct answers

  • B

    The solver parameter in logistic regression determines the optimization algorithm used for training the model.

  • D

    The regularization strength in logistic regression can be controlled using the C parameter.

Question 18

+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 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 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

    Tree Distance

  3. C

    Centroid Distance

  4. D

    Minkowski Distance

Show answer

Correct answers

  • A

    Euclidean Distance

  • D

    Minkowski Distance

Question 21

+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 22

+1 markOne or more correct options

You are training a Multi-Layer Perceptron (MLP) using Scikit-Learn's MLPRegressor for a regression task.

Consider the following code:

python
from sklearn.neural_network import MLPRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
X, y = make_regression(n_samples=1000, n_features=20, noise=0.1, 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 = ________________________
model.fit(X_train, y_train)

Which of the following can be placed in the blank portion (Select all that apply)?

Select all that apply.

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

Correct answers

  • A
  • C

Question 23

+1 markNumerical answer

What will be the output of the following code ?

python
from sklearn.preprocessing import MinMaxScaler, StandardScaler
data = [[0, 5],
[8, 3],
[3, 4],
[7, 2],
[7, 9]]
scaler = StandardScaler()
scaler.fit(data)
print(scaler.var_[0])
Show answer

Correct answer: 9.2

Question 24

+2 marksNumerical answer
Show answer

Correct answer: 0.20

Question 25

+1 markOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('titanic.csv')
>>> print(df)
sexagesibspparchfareclassembark_townalivealone
0male22.0107.2500ThirdSouthamptonnoFalse
1female38.01071.2833FirstCherbourgyesFalse
2female26.0007.9250ThirdSouthamptonyesTrue
3female35.01053.1000FirstSouthamptonyesFalse
4male35.0008.0500ThirdSouthamptonnoTrue
5maleNaN008.4583ThirdQueenstownnoTrue
6male54.00051.8625FirstSouthamptonnoTrue
7male2.03121.0750ThirdSouthamptonnoFalse
8female27.00211.1333ThirdSouthamptonyesFalse
9female14.01030.0708SecondCherbourgyesFalse
10female4.01116.7000ThirdSouthamptonyesFalse
11female58.00026.5500FirstSouthamptonyesTrue
12male20.0008.0500ThirdSouthamptonnoTrue
13male39.01531.2750ThirdSouthamptonnoFalse
14female14.0007.8542ThirdSouthamptonnoTrue
15female55.00016.0000SecondSouthamptonyesTrue

Based on the above data, answer the given subquestions.

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

Correct answer

  • A

Question 26

+1 markOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('titanic.csv')
>>> print(df)
sexagesibspparchfareclassembark_townalivealone
0male22.0107.2500ThirdSouthamptonnoFalse
1female38.01071.2833FirstCherbourgyesFalse
2female26.0007.9250ThirdSouthamptonyesTrue
3female35.01053.1000FirstSouthamptonyesFalse
4male35.0008.0500ThirdSouthamptonnoTrue
5maleNaN008.4583ThirdQueenstownnoTrue
6male54.00051.8625FirstSouthamptonnoTrue
7male2.03121.0750ThirdSouthamptonnoFalse
8female27.00211.1333ThirdSouthamptonyesFalse
9female14.01030.0708SecondCherbourgyesFalse
10female4.01116.7000ThirdSouthamptonyesFalse
11female58.00026.5500FirstSouthamptonyesTrue
12male20.0008.0500ThirdSouthamptonnoTrue
13male39.01531.2750ThirdSouthamptonnoFalse
14female14.0007.8542ThirdSouthamptonnoTrue
15female55.00016.0000SecondSouthamptonyesTrue

Based on the above data, answer the given subquestions.

Which option will help in filtering data to find females who are alive after titanic incident ?

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

Correct answer

  • A

Question 27

+1 markOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('titanic.csv')
>>> print(df)
sexagesibspparchfareclassembark_townalivealone
0male22.0107.2500ThirdSouthamptonnoFalse
1female38.01071.2833FirstCherbourgyesFalse
2female26.0007.9250ThirdSouthamptonyesTrue
3female35.01053.1000FirstSouthamptonyesFalse
4male35.0008.0500ThirdSouthamptonnoTrue
5maleNaN008.4583ThirdQueenstownnoTrue
6male54.00051.8625FirstSouthamptonnoTrue
7male2.03121.0750ThirdSouthamptonnoFalse
8female27.00211.1333ThirdSouthamptonyesFalse
9female14.01030.0708SecondCherbourgyesFalse
10female4.01116.7000ThirdSouthamptonyesFalse
11female58.00026.5500FirstSouthamptonyesTrue
12male20.0008.0500ThirdSouthamptonnoTrue
13male39.01531.2750ThirdSouthamptonnoFalse
14female14.0007.8542ThirdSouthamptonnoTrue
15female55.00016.0000SecondSouthamptonyesTrue

Based on the above data, answer the given subquestions.

What is the given code below trying to accomplish for the given titanic dataset ?

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

Correct answer

  • C

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 1.00 0.33 0.50 3
1 0.97 1.00 0.99 73
accuracy 0.97 76
macro avg 0.99 0.67 0.74 76
weighted avg 0.97 0.97 0.97 76

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 and select the corrrect option:
Assertion: This is a good model as we see a very high accuracy of 97%
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 1.00 0.33 0.50 3
1 0.97 1.00 0.99 73
accuracy 0.97 76
macro avg 0.99 0.67 0.74 76
weighted avg 0.97 0.97 0.97 76

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: 73

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 1.00 0.33 0.50 3
1 0.97 1.00 0.99 73
accuracy 0.97 76
macro avg 0.99 0.67 0.74 76
weighted avg 0.97 0.97 0.97 76

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.99