uiz Space

May 2023 term · Machine Learning Practice · BSCS2008

Machine Learning Practice Quiz 2: 6 August 2023 (May 2023 term)

The IIT Madras BS Machine Learning Practice (MLP) Quiz 2 paper sat on 6 Aug 2023, in the May 2023 term: 23 questions for 50 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
23
Marks
50
Duration
120 min
Numerical
5
MCQ
13
MSQ
5

Updated

Official paper: IIT M DIPLOMA AN2 EXAM QPD2 06 Aug 2023 · No negative marking.

Question 1

+2 marksNumerical answer

Consider the following code and its output:

Code:

python
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
X, y = load_iris(return_X_y=True)
clf = LogisticRegression(random_state=0).fit(X, y)
print(y[70:80])
print(clf.predict(X[70:80, :]))

Output:

text
[1 1 1 1 1 1 1 1 1 1]
[2 1 1 1 1 1 1 2 1 1]

What will be the output of the following code? Enter your answer correct to one decimal place.

python
print(clf.score(X[70:80, :], y[70:80]))
Show answer

Correct answer: 0.8

Question 2

+2 marksNumerical answer
Show answer

Correct answer: 1.00

Question 3

+2 marksNumerical answer

What will be the output of the following code ?

python
from sklearn.neighbors import KNeighborsClassifier
X_train = [[1,100],[4,400],[5,500],[6,600],[8,800],[9,900],
[11,1100],[12,1200],[15,1500], [18,1800],[19,1900]]
y_train = [0,0,1,1,1,2,2,2,2,2,2]
X_test = [[2,200]]
knn = KNeighborsClassifier(n_neighbors= len(y_train),
metric="euclidean",
weights= 'uniform')
knn.fit(X_train,y_train)
print(knn.predict(X_test))
Show answer

Correct answer: 2

Question 4

+2 marksNumerical answer

What will be the output of the following code?

python
import numpy as np
from sklearn.impute import KNNImputer
X = np.array([[5,6,3],[np.nan,1,5],[0,2,8],[4,4,2]])
knn = KNNImputer(n_neighbors=2,weights="uniform")
X_trf= knn.fit_transform(X)
print(X_trf[1][0])
Show answer

Correct answer: 2

Question 5

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

Correct answer

  • B

Question 6

+2 marksOne correct option

Your task to design a model that can predict label of an article, in order to help an online news website. The labels could be “political”, “sports” and “international”.

Following is the label matrix for random 3 articles:

[100110001]\begin{bmatrix} 1 & 0 & 0 \\ 1 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

What type of classification problem is this?

  1. A

    Binary class, single label classification.

  2. B

    Binary class, multi label classification.

  3. C

    Multi class, multi label classification.

  4. D

    Multi class, single label classification.

Show answer

Correct answer

  • C

    Multi class, multi label classification.

Question 7

+2 marksOne correct option

How does strong correlation between features given the labels impact the classification performance in Naive Bayes?

  1. A

    It has no impact because Naive Bayes assumes feature independence.

  2. B

    It improves the classification performance.

  3. C

    It degrades the classification performance.

  4. D

    It depends on the type of Naive Bayes variant used.

Show answer

Correct answer

  • C

    It degrades the classification performance.

Question 8

+2 marksOne correct option

When might the Precision-Recall curve be more informative than the ROC curve?

  1. A

    When the dataset is imbalanced.

  2. B

    When the dataset has equal numbers of positive and negative instances.

  3. C

    When the classifier has high accuracy.

  4. D

    When the classifier produces balanced precision and recall values.

Show answer

Correct answer

  • A

    When the dataset is imbalanced.

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

Which of the following parameters learned by the KNN(KNeighborRegressor) model while training?

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

Correct answer

  • D

Question 11

+2 marksOne correct option
  1. A

    > 1

  2. B

    < 1

  3. C

    =1

  4. D

    Cannot be determined

Show answer

Correct answer

  • C

    =1

Question 12

+2 marksOne correct option

Consider below code which of the following option is true for that

python
from sklearn.neighbors import NearestNeighbors
neigh = NearestNeighbors(n_neighbors=4)
neigh.fit(X_train)
print(neigh.kneighbors(X_test[0:1]))

Assume X_train and X_test are of type numpy.ndarray.

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

Correct answer

  • C

Question 13

+2 marksOne correct option

Which of these may NOT help in handling overfitting in decision trees?

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

Correct answer

  • D

Question 14

+2 marksOne correct option
  1. A

    Any predictor

  2. B

    only a decision tree predictor

  3. C

    only a linear model predictor

  4. D

    only a support vector predictor

Show answer

Correct answer

  • A

    Any predictor

Question 15

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

Correct answer

  • B

Question 16

+2 marksOne or more correct options

Select all that apply.

  1. A

    There are 10,000 images, each contains either a cat or a dog. Exactly 500 contain cats and others contain dogs. Your task is to train a binary classifier.

  2. B

    Train a binary classifier to detect if an MRI image contains carcinogenic cells or not. Number of true positives are 2%.

  3. C

    Predicting if a chest x-ray belongs to a male patient or a female patient. There are nearly equal number of samples of each category.

  4. D

    Based on a student’s senior secondary marks and other features, predicting if he will fail a particular exam. The exam clearing rate is 98.23%.

Show answer

Correct answers

  • A

    There are 10,000 images, each contains either a cat or a dog. Exactly 500 contain cats and others contain dogs. Your task is to train a binary classifier.

  • B

    Train a binary classifier to detect if an MRI image contains carcinogenic cells or not. Number of true positives are 2%.

  • D

    Based on a student’s senior secondary marks and other features, predicting if he will fail a particular exam. The exam clearing rate is 98.23%.

Question 17

+2 marksOne or more correct options

Which of the following is correct?

Select all that apply.

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

Correct answers

  • B
  • D

Question 18

+2 marksOne or more correct options

Which of the following option is true?

Select all that apply.

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

Correct answer

  • C

Question 19

+2 marksOne or more correct options

Select all that apply.

  1. A

    0.0001

  2. B

    1

  3. C

    1000

  4. D

    Cannot be determined

Show answer

Correct answer

  • C

    1000

Question 20

+1 markNumerical answer

What will be the output of the following code:

python
from sklearn.feature_extraction.text import HashingVectorizer
corpus = ['You can have it all. Just not all at once.',
'Train your mind to see the good in every situation.',
'What we think, we become.',
'If I got rid of my demons, I’d lose my angels.',]
vectorizer = HashingVectorizer(n_features= 12,lowercase=True)
X = vectorizer.fit_transform(corpus)
print(X.shape[1])
Show answer

Correct answer: 12

Question 21

+4 marksOne correct option

Consider the following code. How many different parameter combinations will be tried in GridSearchCV?

python
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import load_iris
X, y = load_iris(as_frame = True, return_X_y = True)
param_grid = [{'max_depth':range(1, 10, 2),
'min_samples_split': range(2, 10, 3)},
{'min_samples_leaf': range(1, 11, 3)}]
gs = GridSearchCV(DecisionTreeClassifier(),
param_grid, cv = 5)
gs.fit(X,y)
  1. A

    12

  2. B

    80

  3. C

    60

  4. D

    19

Show answer

Correct answer

  • D

    19

Question 22

+3 marksOne correct option

Which of the following is the most expected output for the code given below:

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)
clf1 = DecisionTreeClassifier(ccp_alpha = 0.1,
random_state = 81)
clf2 = DecisionTreeClassifier(ccp_alpha = 0.25,
random_state = 81)
clf1.fit(X_train, y_train)
clf2.fit(X_train, y_train)
print(clf1.score(X_train, y_train))
print(clf2.score(X_train, y_train))
print(clf1.get_depth())
print(clf2.get_depth())
  1. A

    0.9875
    0.9125
    2
    3

  2. B

    0.9125
    0.9875
    2
    3

  3. C

    0.9875
    0.9125
    3
    2

  4. D

    0.9125
    0.9875
    3
    2

Show answer

Correct answer

  • C

    0.9875
    0.9125
    3
    2

Question 23

+4 marksOne or more correct options

Consider the following block of code:

python
from sklearn.datasets import load_wine
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 = 8,
min_samples_leaf = 5,
random_state = 5)
clf.fit(X_train, y_train)
print(clf.score(X_test, y_test))

In which of the following scenarios, the split will be done at a node N?

Select all that apply.

  1. A

    Number of samples at node N = 5. If it is split, it will result in 3 samples in the left child and 2 samples in the right child.

  2. B

    Number of samples at node N = 10. If it is split, it will result in 5 samples in the left child and 5 samples in the right child.

  3. C

    Number of samples at node N = 15. If it is split, it will result in 9 samples in the left child and 6 samples in the right child.

  4. D

    Number of samples at node N = 8. If it is split, it will result in 5 samples in the left child and 3 samples in the right child.

Show answer

Correct answers

  • B

    Number of samples at node N = 10. If it is split, it will result in 5 samples in the left child and 5 samples in the right child.

  • C

    Number of samples at node N = 15. If it is split, it will result in 9 samples in the left child and 6 samples in the right child.