uiz Space

September 2023 term · Machine Learning Practice · BSCS2008

Machine Learning Practice Quiz 2: 3 December 2023 (September 2023 term)

The IIT Madras BS Machine Learning Practice (MLP) Quiz 2 paper sat on 3 Dec 2023, in the September 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
MCQ
13
MSQ
8
Numerical
2

Updated

Official paper: IIT M DIPLOMA AN2 EXAM QDD2 03 Dec 2023 · No negative marking.

Question 1

+1 markOne correct option

You are working with a dataset containing 1000 samples, aiming to classify them using the KNeighborsClassifier from scikit-learn. After trying an initial configuration, you observe that the model seems to be overfitting, with the following accuracies:

python
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score
# Initial Configuration
knn = KNeighborsClassifier(n_neighbors=3)
knn.fit(X_train, y_train)
train_acc = accuracy_score(y_train, knn.predict(X_train))
val_acc = accuracy_score(y_val, knn.predict(X_val))
  • Training accuracy: 98%
  • Validation accuracy: 65%

After observing such performance of the model, Which of the following values for n_neighbors would be more suitable to try next?

  1. A

    1

  2. B

    2

  3. C

    10

  4. D

    500

Show answer

Correct answer

  • C

    10

Question 2

+1 markOne correct option

Consider the following code segment which uses CountVectorizer on a set of documents:

python
from sklearn.feature_extraction.text import CountVectorizer
documents = [
'apple orange banana',
'apple apple',
'banana orange',
'apple banana orange orange'
]
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(documents)

After executing the code, what will be the shape of matrix X?

  1. A

    (4, 3)

  2. B

    (3, 4)

  3. C

    (4, 4)

  4. D

    (3, 3)

Show answer

Correct answer

  • A

    (4, 3)

Question 3

+2 marksOne correct option

Assume train data (X_train, y_train) and test data (X_test) is given as numpy array and you build and train a LogisticRegression model. Which of the following options might possibly be the predicted class of first two samples(rows) of the test data according to the code given below?

python
>>> from sklearn.linear_model import LogisticRegression
>>> log_reg = LogisticRegression()
>>> log_reg.fit(X_train,y_train)
>>> print(log_reg.classes_)
[0,1,2] #output of above code
>>> print(log_reg.predict_proba(X_test[[0]]))
[[2.73e-45, 1.21e-51, 1.00e+00]] #output of above code
>>> print(log_reg.predict_proba(X_test[[1]]))
[[7.09e-29, 1.00e+00, 2.02e-36]] #output of above code
>>> print(log_reg.predict(X_test[0:2]))
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 4

+2 marksOne correct option

Consider the block of code given below:

python
from sklearn.metrics import confusion_matrix
y_true = ["cat", "ant", "cat", "cat", "ant", "bird"]
y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"]
cm = confusion_matrix(y_true, y_pred, labels=["ant", "bird", "cat"])
print(cm)

Which of the following option represents the print output :

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

Correct answer

  • A

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
  1. A

    It will perform regression on the given data.

  2. B

    It will generate synthetic regression data.

  3. C

    It will perform classification on the given data.

  4. D

    It will generate synthetic classification data.

Show answer

Correct answer

  • C

    It will perform classification on the given data.

Question 7

+2 marksOne correct option

Which method of classification needs more than n classifiers, where n is the number of classes?

  1. A

    OneVsRestClassifier

  2. B

    OneVsOneClassifier

  3. C

    OutputCodeClassifier

  4. D

    MultiOutputClassifier

Show answer

Correct answer

  • B

    OneVsOneClassifier

Question 8

+2 marksOne correct option
  1. A

    alpha

  2. B

    tol

  3. C

    solver

  4. D

    learner

  5. E

    algo

  6. F

    algorithm

Show answer

Correct answer

  • C

    solver

Question 9

+2 marksOne correct option

Consider the following code?

python
from sklearn.neighbors import KNeighborsClassifier
import numpy as np
X_train = np.array([[1, 0.5], [2, 1], [3, 1.5], [4, 2], [5, 2.5],
[6, 3], [7, 3.5], [8, 4], [9, 4.5], [10, 5]])
y_train = [0, 0, 1, 1, 2, 2, 2, 2, 2, 2]
knn = KNeighborsClassifier(n_neighbors=7)
knn.fit(X_train, y_train)

Given a single test data point X_test, what will be the output of the following code?

python
print(knn.predict(X_test))
  1. A

    0

  2. B

    1

  3. C

    2

  4. D

    Can not be determined without knowing the test data point.

Show answer

Correct answer

  • C

    2

Question 10

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

Correct answer

  • B

Question 11

+3 marksOne correct option

Consider the following classifier and select the correct option.

python
estimator = SGDClassifier(loss='log',
penalty='l2',
max_iter=1,
warm_start=True,
eta0=0.01,
alpha=0,
learning_rate='constant',
random_state=1729)
  1. A

    It applies the perceptron classification with regularization.

  2. B

    It applies the perceptron classification without regularization.

  3. C

    It applies the logistic regression with regularization.

  4. D

    It applies the logistic regression without regularization.

Show answer

Correct answer

  • D

    It applies the logistic regression without regularization.

Question 12

+3 marksOne correct option

Consider below code for a given training data:

python
from sklearn.model_selection import RandomizedSearchCV
from sklearn.ensemble import RandomForestClassifier
param_distributions = {"n_estimators" : range(3,100,2),
"max_depth": range(3,40,2),
"min_samples_split" : [3,4,5,6,7]}
RS_CV = RandomizedSearchCV(estimator=RandomForestClassifier(random_state=0),
param_distributions=param_distributions,
cv=3,
n_iter=12)
RS_CV.fit(X_train,y_train)

Which of the following option(s) are True ?

  1. A

    A total of 12 estimators will be trained, with each estimator using 3-fold crossvalidation

  2. B

    The parameter combination will be the same in every run because random_state is set to 0.

  3. C

    Given code will throw an error because all the parameters are not presented as a list

  4. D

    All of the options are incorrect

Show answer

Correct answer

  • A

    A total of 12 estimators will be trained, with each estimator using 3-fold crossvalidation

Question 13

+4 marksOne correct option

According to DecisionTreeClassifier parameters which of the following option will have least fitting(underfit) for the same data.

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

Correct answer

  • C

Question 14

+2 marksOne or more correct options

For the given X_train (in pandas DataFrame) below which of the following options can successfully impute the null values ?

WeightEducation
0NaNSchool
156.0High-School
245.0Bachelor
3NaNMasters
440.0School
540.0High-School
620.0Bachelor
767.0NaN
820.0School
935.0NaN

Select all that apply.

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

Correct answers

  • C
  • D

Question 15

+2 marksOne or more correct options

Which of the following is/are true about DummyClassifier?

Select all that apply.

  1. A

    DummyClassifier makes predictions that ignore the input features.

  2. B

    DummyClassifier serves as a simple baseline to compare against other more complex classifiers.

  3. C

    The predictions of DummyClassifier typically depend on values observed in the y parameter passed to fit().

  4. D

    The predictions of DummyClassifier typically depend on values observed in the X parameter passed to fit().

  5. E

    All of these.

Show answer

Correct answers

  • A

    DummyClassifier makes predictions that ignore the input features.

  • B

    DummyClassifier serves as a simple baseline to compare against other more complex classifiers.

  • C

    The predictions of DummyClassifier typically depend on values observed in the y parameter passed to fit().

Question 16

+2 marksOne or more correct options

Select all that apply.

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

Correct answers

  • A
  • B

Question 17

+2 marksOne or more correct options

You are analyzing a dataset with features XtrainX_{\text{train}} and targets ytrainy_{\text{train}}. After standardizing the feature set, you decide to apply the KNeighborsClassifier from scikit-learn to classify data points. You use the following code:

python
from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier(n_neighbors=5,
weights='distance',
metric='minkowski', p=1)
model.fit(X_train, y_train)

Given the above code configuration for KNeighborsClassifier, which of the following statements are true? (Select all that apply)

Select all that apply.

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

Correct answers

  • C
  • D

Question 18

+2 marksOne or more correct options

Consider the following Python code where you are using the SVC classifier to categorize data from a binary classification problem:

python
from sklearn.svm import SVC
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
clf = make_pipeline(StandardScaler(),
SVC(C=1.0, kernel='rbf', gamma='scale'))
clf.fit(X_train, y_train)
prediction = clf.predict(X_test)

Assume that X_train, y_train, and X_test are training feature matrix, label vector, and test feature matrix, respectively. Which of the following statements is/are true using the code given above?

Select all that apply.

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

Correct answers

  • B
  • C

Question 19

+2 marksOne or more correct options

Which of the following are advantages of using ensemble methods in machine learning?

Select all that apply.

  1. A

    Improved model performance

  2. B

    Reduced overfitting

  3. C

    Faster model training

  4. D

    Simplicity of model interpretation

Show answer

Correct answers

  • A

    Improved model performance

  • B

    Reduced overfitting

Question 20

+3 marksOne or more correct options

Which of the following option(s) are True ?

Select all that apply.

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

Correct answers

  • B
  • D

Question 21

+3 marksOne or more correct options

Suppose In a classification problem you want to use BaggingClassifier, which of the following estimator(s) could be used as base estimator in that?

Select all that apply.

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

Correct answers

  • A
  • C

Question 22

+2 marksNumerical answer

Consider given below confusion matrix code :

python
from sklearn.metrics import confusion_matrix
y_true = ["cat", "ant", "cat", "cat", "ant", "bird"]
y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"]
cm = confusion_matrix(y_true, y_pred, labels=["ant", "bird", "cat"])

Determine the recall score for class “ant” in the given confusion_matrix?

Show answer

Correct answer: 1

Question 23

+2 marksNumerical answer
Show answer

Correct answer: 0.5