uiz Space

May 2024 term · Machine Learning Practice · BSCS2008

Machine Learning Practice Quiz 2: 4 August 2024 (May 2024 term)

The IIT Madras BS Machine Learning Practice (MLP) Quiz 2 paper sat on 4 Aug 2024, in the May 2024 term: 22 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
22
Marks
50
Duration
120 min
MCQ
16
Numerical
3
MSQ
3

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 4 Aug 2024 · No negative marking.

Question 1

+3 marksOne correct option

Given the following code for Polynomial Regression:

python
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array([1, 2, 3, 4, 5]).reshape(-1, 1)
y = np.array([1, 4, 9, 16, 25])
poly = PolynomialFeatures(degree=2,interaction_only=False)
X_poly = poly.fit_transform(X)
model = LinearRegression()
model.fit(X_poly, y)
print(model.coef_)

What are the coefficients of the model?

  1. A

    [0, 1, 1]

  2. B

    [0, 2, 1]

  3. C

    [0, 0, 1]

  4. D

    [0, 0, 2]

Show answer

Correct answer

  • C

    [0, 0, 1]

Question 2

+3 marksOne correct option

What is ‘naive’ assumption in classifiers based on Naive Bayes?

  1. A

    All the classes are conditionally independent of each other.

  2. B

    All the classes are conditionally dependent on each other.

  3. C

    All the features are conditionally dependent on each other.

  4. D

    All the features are conditionally independent of each other.

Show answer

Correct answer

  • D

    All the features are conditionally independent of each other.

Question 3

+3 marksOne correct option
  1. A

    cv

  2. B

    reg_rate

  3. C

    alpha

  4. D

    tol

  5. E

    lambda

  6. F

    None of these

Show answer

Correct answer

  • C

    alpha

Question 4

+2 marksOne correct option

What is the effect of increasing the regularization parameter alpha in Ridge Regression?

  1. A

    It increases the complexity of the model.

  2. B

    It reduces the complexity of the model.

  3. C

    It has no effect on the model.

  4. D

    It increases the model’s sensitivity to the training data.

Show answer

Correct answer

  • B

    It reduces the complexity of the model.

Question 5

+2 marksOne correct option

Given the code below:

python
from sklearn.datasets import fetch_california_housing
from sklearn.linear_model import LinearRegression
data = fetch_california_housing()
X, y = data.data, data.target
model = LinearRegression()
model.fit(X, y)
print(model.coef_)

What do the coefficients represents?

  1. A

    The importance of each feature in predicting the target.

  2. B

    The residuals of the model.

  3. C

    The intercept of the regression line.

  4. D

    It represents the values of hyperparameters of the model.

Show answer

Correct answer

  • A

    The importance of each feature in predicting the target.

Question 6

+2 marksOne correct option

How can we use both Ridge and Lasso Regularization in a machine learning model?

  1. A

    By setting penalty parameter to l2

  2. B

    By setting penalty parameter to l1

  3. C

    By setting penalty parameter to elasticnet

  4. D

    By setting penalty parameter to l3

Show answer

Correct answer

  • C

    By setting penalty parameter to elasticnet

Question 7

+2 marksOne correct option

Which of the following types of classification problems is being solved when a model predicts multiple labels(greater than 2) for each instance?

  1. A

    Binary class, single label classification.

  2. B

    Multi class, multi label classification.

  3. C

    Binary class, multi label classification.

  4. D

    Multi class, single label classification.

Show answer

Correct answer

  • B

    Multi class, multi label classification.

Question 8

+2 marksOne correct option

Given the code snippet and assume if any necessary requirements:

python
from sklearn.model_selection import GridSearchCV
from sklearn.linear_model import LogisticRegression
param_grid = {'C': [0.1, 1, 10],
'penalty': ['l1', 'l2'],
'solver': ['liblinear']}
clf = GridSearchCV(LogisticRegression(), param_grid, cv=5)
clf.fit(X_train, y_train)
print(clf.best_params_)

What does cv=5 signify in this context?

  1. A

    The training data is split into 5 different datasets, each used to train a separate model.

  2. B

    The model is trained and evaluated using 5-fold cross-validation for hyperparameter tuning

  3. C

    Five different models are trained on 5 resampled datasets of training data.

  4. D

    The dataset is divided into 5 parts and trained in a single pass without cross- validation.

Show answer

Correct answer

  • B

    The model is trained and evaluated using 5-fold cross-validation for hyperparameter tuning

Question 9

+2 marksOne correct option

Consider the following code and assume all the imports being made:

python
from sklearn.linear_model import Perceptron
X_train, X_test, y_train, y_test = MNIST()
clf = Perceptron()
clf.fit(X_train, y_train)
print(clf.score(X_test, y_test))

What does the score method compute in this context?

  1. A

    The number of correctly classified samples.

  2. B

    The accuracy of the classifier.

  3. C

    The loss function value.

  4. D

    The number of misclassified samples.

Show answer

Correct answer

  • B

    The accuracy of the classifier.

Question 10

+2 marksOne correct option

Given the following code snippet for a multi-label classification problem:

python
from sklearn.multioutput import MultiOutputClassifier
from sklearn.linear_model import LogisticRegression
model = MultiOutputClassifier(LogisticRegression())
model.fit(X_train, y_train)
y_pred = model.predict(X_test)

What does MultiOutputClassifier do in this context?

  1. A

    Trains a single Logistic Regression model for all labels.

  2. B

    Combines Logistic Regression with another model.

  3. C

    Trains a separate Logistic Regression model for each label.

  4. D

    Applies Logistic Regression in a one-vs-rest strategy for multi-class classification.

Show answer

Correct answer

  • C

    Trains a separate Logistic Regression model for each label.

Question 11

+2 marksOne correct option

What is the main advantage of using RandomizedSearchCV over GridSearchCV ?

  1. A

    RandomizedSearchCV is always faster.

  2. B

    RandomizedSearchCV evaluates all possible combinations of
    hyperparameters.

  3. C

    RandomizedSearchCV can sample a larger hyperparameter space with fewer iterations.

  4. D

    RandomizedSearchCV always finds the best model.

Show answer

Correct answer

  • C

    RandomizedSearchCV can sample a larger hyperparameter space with fewer iterations.

Question 12

+2 marksOne correct option
  1. A

    LogisticRegression

  2. B

    Perceptron

  3. C

    RidgeClassifier

  4. D

    Support Vector Machine (SVM)

Show answer

Correct answer

  • C

    RidgeClassifier

Question 13

+2 marksOne correct option

What type of classification problem is the Perceptron algorithm best suited for?

  1. A

    Linearly separable binary classification problems.

  2. B

    Non-linear classification problems.

  3. C

    Regression problems.

  4. D

    Unsupervised Learning Problems

Show answer

Correct answer

  • A

    Linearly separable binary classification problems.

Question 14

+2 marksOne correct option

What will be the output of the following code? Given that output of iris.target_names is ['setosa', 'versicolor', 'virginica']

python
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
iris = load_iris()
X = iris.data
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.4,
random_state=1)
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
gnb.fit(X_train, y_train)
gnb.classes_
  1. A

    [0, 1, 2]

  2. B

    [0, 1]

  3. C

    ['setosa', 'versicolor', 'virginica']

  4. D

    ['setosa', 'versicolor’']

  5. E

    None of these

Show answer

Correct answer

  • A

    [0, 1, 2]

Question 15

+2 marksOne correct option

What is the default loss value in SGDClassifier API and it gives which classifier?

  1. A

    ‘log loss’, LogisticRegressor

  2. B

    ‘log loss’, LogisticClassifier

  3. C

    ‘hinge’, SVM

  4. D

    ‘hinge’, Perceptron

Show answer

Correct answer

  • C

    ‘hinge’, SVM

Question 16

+2 marksOne 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=4)
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 most suitable to try next?

  1. A

    1

  2. B

    2

  3. C

    10

  4. D

    500

Show answer

Correct answer

  • C

    10

Question 17

+3 marksNumerical answer
Show answer

Correct answer: 0.67

Question 18

+3 marksNumerical answer

What will be the output of the following code ?

python
import numpy as np
from sklearn.neighbors import KNeighborsClassifier
X_train = np.array([[1,100],[4,400],[5,500],[6,600],[8,800],[9,900],
[11,1100],[12,1200],[15,1500], [18,1800],[19,1900]])
y_train = np.array([0,0,1,1,1,2,2,2,2,2,2])
X_test = np.array([[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 19

+2 marksNumerical answer
Show answer

Correct answer: 2

Question 20

+2 marksOne or more correct options

Select all that apply.

  1. A

    ‘poly’,

  2. B

    ‘lasso’

  3. C

    ‘rbf’,

  4. D

    ‘scale’

Show answer

Correct answers

  • A

    ‘poly’,

  • C

    ‘rbf’,

Question 21

+2 marksOne or more correct options

Which of the following scikit-learn model supports incremental learning through partial_fit method ?

Select all that apply.

  1. A

    SGDClassifier

  2. B

    LinearRegression

  3. C

    Perceptron

  4. D

    SVC

Show answer

Correct answers

  • A

    SGDClassifier

  • C

    Perceptron

Question 22

+3 marksOne or more correct options

Which of the following options are true for regularization parameter C in sklearn.svm.SVC ?

Select all that apply.

  1. A

    Large value of the regularization parameter C will overfit the training set and complex decision boundaries will form.

  2. B

    Large value of the regularization parameter C will underfit the training set and smooth decision boundaries will form.

  3. C

    Small value of the regularization parameter C will overfit the training set and complex decision boundaries will form.

  4. D

    Small value of the regularization parameter C will underfit the training set and smooth decision boundaries will form.

  5. E

    None of these

Show answer

Correct answers

  • A

    Large value of the regularization parameter C will overfit the training set and complex decision boundaries will form.

  • D

    Small value of the regularization parameter C will underfit the training set and smooth decision boundaries will form.