Quiz Space

May 2022 term · Machine Learning Practice · BSCS2008

Machine Learning Practice End Term: 7 August 2022 (May 2022 term)

The IIT Madras BS Machine Learning Practice (MLP) End Term paper sat on 7 Aug 2022, in the May 2022 term: 40 questions for 100 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
40
Marks
100
Duration
180 min
MCQ
31
MSQ
5
Numerical
4

Updated

Official paper: IIT M FOUNDATION DIPLOMA ENDTERM QPB1 07 Aug 2022 IBA NS · No negative marking.

Question 1

+2 marksOne correct option

The similarity between loaders and fetchers of sklearn is -

  1. A

    Both loaders and fetchers generate controlled synthetic datasets

  2. B

    Both loaders and fetchers return a Bunch object, which is a dictionary with two keys

  3. C

    Both techniques load small standard datasets

  4. D

    None of these options are correct

Show answer

Correct answer

  • B

    Both loaders and fetchers return a Bunch object, which is a dictionary with two keys

Question 2

+2 marksOne correct option

Which of the following options represent the main purpose of using the FeatureUnion?

  1. A

    Enables different transformations on various columns of data based on their types

  2. B

    Combines output from several transformer objects by creating a new transformer from them

  3. C

    To chain multiple estimators to execute a fixed sequence of steps in data preprocessing and modeling

  4. D

    None of these

Show answer

Correct answer

  • B

    Combines output from several transformer objects by creating a new transformer from them

Question 3

+2 marksOne correct option

What will be the output of the following block of code?

  1. A

    (10, 2)

  2. B

    (2, 10)

  3. C

    (10, 3)

  4. D

    (3, 10)

Show answer

Correct answer

  • A

    (10, 2)

Question 4

+2 marksOne correct option

Which of the following options is the correct method to load the wine dataset and print its shape?

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

Correct answer

  • D

Question 5

+2 marksOne correct option

What is the output of the following block of code?

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

Correct answer

  • A

Question 6

+2 marksOne correct option

What is the output of the following code snippet?

  1. A

    [0.75 0.5]

  2. B

    [0.25 0.5]

  3. C

    [0.5 0.75]

  4. D

    [0.5 0.5]

Show answer

Correct answer

  • C

    [0.5 0.75]

Question 7

+2 marksOne correct option

Which of the options will be the correct output for the following code snippet?

python
import numpy as np
x = np.array(
[[5, 4 ],
[3, 8 ],
[2, 0 ],
[9, 6 ]])
from sklearn.preprocessing import add_dummy_feature
x_new = add_dummy_feature(x)
print(x_new)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 8

+2 marksOne correct option

Which of the options will be the correct output for the following code snippet?

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

Correct answer

  • D

Question 9

+2 marksOne correct option

Which of the following options is correct explained variance score for the following code snippet applying PCA technique.

  1. A

    [1. 1.]

  2. B

    [1. 0.]

  3. C

    [0. 1.]

  4. D

    [0. 0.]

Show answer

Correct answer

  • B

    [1. 0.]

Question 10

+2 marksOne correct option

Which of the following options is the correct output of the following block of code?

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

Correct answer

  • A

Question 11

+2 marksOne correct option

Which of the following options is the correct method to shuffle training data after each epoch in SGDRegressor?

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

Correct answer

  • A

Question 12

+2 marksOne correct option

Which of the following options represent the correct output of the following block of code?

  1. A

    array([9.])

  2. B

    array([10.])

  3. C

    array([11.])

  4. D

    SyntaxError: unexpected EOF while parsing

Show answer

Correct answer

  • B

    array([10.])

Question 13

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

Correct answer

  • C

Question 14

+2 marksOne correct option

Which of the following options is the possible output for the following block of code?

  1. A

    0.94

  2. B

    1.25

  3. C

    1.94

  4. D

    -2.64

Show answer

Correct answer

  • A

    0.94

Question 15

+2 marksOne correct option

What operation does the following code implement?

  1. A

    It will perform linear regression on the given data.

  2. B

    It will generate synthetic regression data.

  3. C

    It will generate synthetic classification data.

  4. D

    It will perform classification on the given data.

Show answer

Correct answer

  • D

    It will perform classification on the given data.

Question 16

+2 marksOne correct option

Which of the following options represent the recall value for the class 2 in the confusion matrix shown in Figure 1 if y_true = [0, 1, 2, 2, 2], y_pred = [0, 0, 2, 2, 1] ?

  1. A

    0.67

  2. B

    1.00

  3. C

    0.50

  4. D

    0.25

Show answer

Correct answer

  • A

    0.67

Question 17

+2 marksOne correct option

Consider the following code block and mark the correct output.

  1. A

    [0 0 0 1 1 1]

  2. B

    [2 2 0 0 1 1]

  3. C

    [0 1 2 0 1 2]

  4. D

    [0 1 0 1 0 1]

Show answer

Correct answer

  • B

    [2 2 0 0 1 1]

Question 18

+2 marksOne correct option

Consider X and y as the training dataset. What will be the output of the following code?

  1. A

    logistic

  2. B

    relu

  3. C

    identity

  4. D

    softmax

Show answer

Correct answer

  • D

    softmax

Question 19

+2 marksOne or more correct options

Which of the following options represent the design philosophy of the sklearn API?

Select all that apply.

  1. A

    Nonproliferation of classes

  2. B

    Execution of all codes within 99.9 ms.

  3. C

    Sensible defaults

  4. D

    Direct accessibility of hyperparameters of all estimators

Show answer

Correct answers

  • A

    Nonproliferation of classes

  • C

    Sensible defaults

  • D

    Direct accessibility of hyperparameters of all estimators

Question 20

+2 marksOne or more correct options

Which of the following options represent(s) the correct method(s) to search for the best regularization parameter for ridge regression?

Select all that apply.

  1. A

    Search for the best regularization rate with built-in cross validation in RidgeCV estimator

  2. B

    Step 1: Instantiate object of Ridge estimator.
    Step 2: Set parameter alpha to the maximum regularization rate.

  3. C

    Use cross validation with Ridge to search for best regularization.

  4. D

    Apply cross validation with SGDRegressor for searching the best regularization parameter.

Show answer

Correct answers

  • A

    Search for the best regularization rate with built-in cross validation in RidgeCV estimator

  • C

    Use cross validation with Ridge to search for best regularization.

  • D

    Apply cross validation with SGDRegressor for searching the best regularization parameter.

Question 21

+2 marksOne or more correct options

Consider the following block of code and mark all possible correct options.

python
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier, VotingClassifier
clf1 = LogisticRegression()
clf2 = RandomForestClassifier()
vote=VotingClassifier(estimators=[('lr', clf1), ('rf', clf2)],
weights=None,
n_jobs= 1,
flatten_transform=True,
verbose=False,
voting='hard')
vote = vote.fit(X, y)
print(vote.predict(X))

Select all that apply.

  1. A

    Given model uses majority voting rule to predict class labels.

  2. B

    Given model predicts the class labels based on the argmax of the sums of the predicted probabilities.

  3. C

    Setting flatten_transform =True with voting=’soft’ will flatten the output shape of transform.

  4. D

    None of these are correct

Show answer

Correct answers

  • A

    Given model uses majority voting rule to predict class labels.

  • C

    Setting flatten_transform =True with voting=’soft’ will flatten the output shape of transform.

Question 22

+3 marksOne correct option

What will be the output of the following code block:

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

Correct answer

  • A

Question 23

+3 marksOne correct option

Which of the following options represent the output of the following block of code?

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

Correct answer

  • A

Question 24

+3 marksOne correct option

Which of the following statements will be true based on the following diagram?

  1. A

    The classifier will predict all positive classes as negatives and all negative classes as positives.

  2. B

    The classifier will perfectly distinguish between the positive and negative classes.

  3. C

    There is a good probability that the classifier can properly identify the classes.

  4. D

    We can not comment on the classifier performance based on the given figure

Show answer

Correct answer

  • B

    The classifier will perfectly distinguish between the positive and negative classes.

Question 25

+3 marksOne correct option

Which of the following options is the correct output of the following block of code?

  1. A

    array([2.25, 2.25, 2.25])

  2. B

    array([1., 1., 1.])

  3. C

    array([2., 2., 2.])

  4. D

    DummyRegressor()

Show answer

Correct answer

  • C

    array([2., 2., 2.])

Question 26

+3 marksOne correct option

Which of the following is likely to be the correct output of the code given below?

  1. A

    array([[1., 1., 1., 0.], [1., 1., 1., 0.], [0., 1., 0., 1.], [0., 1., 1., 1.]])

  2. B

    array([[1., 1., 1., 0.], [1., 1., 1., 0.], [0., 1., 0., 1.], [0., 1., 0., 1.]])

  3. C

    array([[1., 1., 0., 1.], [0., 1., 1., 0.], [0., 1., 1., 0.], [1., 0., 1., 1.]])

  4. D

    array([[1., 1., 1., 0.], [1., 1., 1., 0.], [0., 1., 1., 1.], [0., 1., 1., 1.]])

Show answer

Correct answer

  • D

    array([[1., 1., 1., 0.], [1., 1., 1., 0.], [0., 1., 1., 1.], [0., 1., 1., 1.]])

Question 27

+3 marksOne correct option

For the following block of code, we get the output as 0.9875. How would the output change if we decrease max depth value ?:

python
from sklearn.datasets import load_wine
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
X,y = load_wine(as_frame = True, return_X_y = True)
X_train,X_test,y_train,y_test = train_test_split(X,
y,
test_size = 0.10,
random_state = 12)
clf = DecisionTreeClassifier(max_depth = 6,
min_samples_split = 2,
min_samples_leaf=3,
random_state = 81)
clf.fit(X_train, y_train)
print(clf.score(X_train, y_train))
  1. A

    Output score will definitely increase.

  2. B

    Output score will definitely decrease.

  3. C

    Output score may decrease or remain the same.

  4. D

    Code will throw an error because max_depth can’t be less than 6.

Show answer

Correct answer

  • C

    Output score may decrease or remain the same.

Question 28

+3 marksOne correct option

Consider the following block of code and mark the correct option.

python
from sklearn.datasets import load_breast_cancer
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
X,y = load_breast_cancer(as_frame = True,
return_X_y = True)
X_train,X_test,y_train,y_test = train_test_split(X,
y,
test_size = 0.2,
random_state = 1)
clf = DecisionTreeClassifier(min_samples_split = 5,
random_state = 5)
clf.fit(X_train, y_train)
print(clf.score(X_test, y_test))
  1. A

    The minimum number of samples required to split a leaf node is 5.

  2. B

    The minimum number of samples required to split an internal node is 6.

  3. C

    The minimum number of samples required to be at a leaf node is 4.

  4. D

    The minimum number of samples required to split an internal node is 5.

Show answer

Correct answer

  • D

    The minimum number of samples required to split an internal node is 5.

Question 29

+3 marksOne correct option

Consider the following code snippet. What value should we fill at the blank place, so that given code block creates graph as shown below:

  1. A

    2

  2. B

    4

  3. C

    5

  4. D

    6

  5. E

    10

Show answer

Correct answer

  • C

    5

Question 30

+3 marksNumerical answer

Calculate the coefficient of determination (R²) [up to 1 decimal point] based on the following block of code.

Show answer

Correct answer: 0 (accepted within ±0.05)

Question 31

+3 marksNumerical answer

In the given block of code, the Iris dataset having shape (150,4) has been loaded for model training. What do you think will be the output of the code given below?

python
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
X,y = load_iris(as_frame = True, return_X_y = True)
X_train,X_test,y_train,y_test = train_test_split(X,
y,
test_size=0.2,
random_state=1)
clf = DecisionTreeClassifier(max_features=2,
max_depth = 6,
min_samples_split = 2,
min_samples_leaf = 3,
random_state = 81 )
clf.fit(X_train, y_train)
print(clf.n_features_in_)
Show answer

Correct answer: 4

Question 32

+3 marksNumerical answer

Code snippet written below plots a graph for some dataset X as shown below.

In the given dendrogram which sample is most similar to the sample having label as 1 ?

Show answer

Correct answer: 0

Question 33

+3 marksOne correct option

Go through the code snippet given below and answer the subquestions.

python
X = [[0,1],[3,4], [4,5],[1,2],[2,3], [5,6]]
y = [0, 1, 1,0,0,1]
from sklearn.neighbors import RadiusNeighborsClassifier
neigh = RadiusNeighborsClassifier(radius=1.0, P=1)
neigh.fit(X, y)
print(neigh.predict([[2.8,3.8]]))

Which of the following is likely to be the correct output of the given code ?

  1. A

    [2]

  2. B

    [0]

  3. C

    [1]

  4. D

    [3]

Show answer

Correct answer

  • C

    [1]

Question 34

+2 marksOne correct option

Go through the code snippet given below and answer the subquestions.

python
X = [[0,1],[3,4], [4,5],[1,2],[2,3], [5,6]]
y = [0, 1, 1,0,0,1]
from sklearn.neighbors import RadiusNeighborsClassifier
neigh = RadiusNeighborsClassifier(radius=1.0, P=1)
neigh.fit(X, y)
print(neigh.predict([[2.8,3.8]]))

Which of the following distance metrics is used in the given code.

  1. A

    Euclidean_distance

  2. B

    Manhattan_distance

  3. C

    Hamming Distance

  4. D

    None of these

Show answer

Correct answer

  • A

    Euclidean_distance

Question 35

+2 marksNumerical answer

Consider the following code snippet:

python
from sklearn.datasets import fetch_california_housing
from sklearn.neural_network import MLPRegressor
X,y = fetch_california_housing(as_frame = True,
return_X_y = True)
rs = MLPRegressor(activation='logistic',
hidden_layer_sizes=(12,15,13,11,12,8),
random_state=12)
rs.fit(X, y)

Based on the above data, answer the given subquestions.

What will be the output of the following code?

Show answer

Correct answer: 8

Question 36

+3 marksOne correct option

Consider the following code snippet:

python
from sklearn.datasets import fetch_california_housing
from sklearn.neural_network import MLPRegressor
X,y = fetch_california_housing(as_frame = True,
return_X_y = True)
rs = MLPRegressor(activation='logistic',
hidden_layer_sizes=(12,15,13,11,12,8),
random_state=12)
rs.fit(X, y)

Based on the above data, answer the given subquestions.

What will be the output of the following code?

  1. A

    (5, 12)

  2. B

    (6, 11)

  3. C

    (8, 15)

  4. D

    (12, 8)

Show answer

Correct answer

  • D

    (12, 8)

Question 37

+3 marksOne correct option

Go through the code snippet given below and answer the subquestions.

python
import numpy as np
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
X = np.array([[-8, -3], [3, 3], [5, 3], [-4, -3],])
y = np.array([-3, 3, 3, -3])
from sklearn.svm import SVC
clf = SVC(gamma='auto',kernel="linear")
clf.fit(X, y)
print(clf.predict([[-4, -3]]))

Which of the following is likely to be the correct output of the given code ?

  1. A

    [3]

  2. B

    [-1]

  3. C

    [1]

  4. D

    [-3]

Show answer

Correct answer

  • D

    [-3]

Question 38

+3 marksOne correct option

Go through the code snippet given below and answer the subquestions.

python
import numpy as np
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
X = np.array([[-8, -3], [3, 3], [5, 3], [-4, -3],])
y = np.array([-3, 3, 3, -3])
from sklearn.svm import SVC
clf = SVC(gamma='auto',kernel="linear")
clf.fit(X, y)
print(clf.predict([[-4, -3]]))

Which of the following is likely to be the correct output:

  1. A

    array([[-8., -3.], [ 3., 3.]])

  2. B

    array([[-4., -3.], [ 3., 3.]])

  3. C

    array([[-4., -3.], [ 5., 3.]])

  4. D

    array([[-8., -3.], [ 5., 3.]])

Show answer

Correct answer

  • B

    array([[-4., -3.], [ 3., 3.]])

Question 39

+4 marksOne or more correct options

Which of the following is/are true about the following block of the code?

python
from sklearn.neural_network import MLPClassifier
X = [[0., 0.], [1., 1.],[2., 3.],[5., 4.]]
y = [0, 0, 1, 1]
rs = MLPClassifier(solver='adam',
alpha=0.0001 ,
batch_size="auto",
hidden_layer_sizes=(8,12),
random_state=12)
rs.fit(X,y)
rs.score(X,y)

Select all that apply.

  1. A

    Given dataset belongs to binary classification.

  2. B

    Number of neurons in the 1^(st) hidden layer is 8.

  3. C

    Strength of the L1 regularization term is 0.0001

  4. D

    The activation function for the output layer in the given code is the ′logistic′ function.

Show answer

Correct answers

  • A

    Given dataset belongs to binary classification.

  • B

    Number of neurons in the 1^(st) hidden layer is 8.

  • D

    The activation function for the output layer in the given code is the ′logistic′ function.

Question 40

+5 marksOne or more correct options

Which of the following code blocks will throw an error ?

Select all that apply.

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

Correct answers

  • B
  • C