uiz Space

September 2024 term · Machine Learning Practice · BSCS2008

Machine Learning Practice Quiz 2: 1 December 2024 (September 2024 term)

The IIT Madras BS Machine Learning Practice (MLP) Quiz 2 paper sat on 1 Dec 2024, in the September 2024 term: 21 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
21
Marks
50
Duration
120 min
MCQ
13
MSQ
4
Numerical
4

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 01 Dec 2024 · No negative marking.

Question 1

+3 marksOne correct option

Consider the following code for Ridge Regression:

python
from sklearn.linear_model import Ridge
import numpy as np
X = np.array([[1, 2], [2, 4], [3, 6], [4, 8]])
y = np.array([1, 2, 3, 4])
model = Ridge(alpha=10)
model.fit(X, y)
coefficients = model.coef_
print(np.round(coefficients,2))

What will be the output for the coefficients?

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

Correct answer

  • E

Question 2

+3 marksOne correct option

Consider the following code for Stochastic Gradient Descent (SGD) Classifier:

python
from sklearn.linear_model import SGDClassifier
from sklearn.datasets import make_classification
X_train, y_train = make_classification(n_samples=1000, n_features=20,
n_classes=2, random_state=42)
model = SGDClassifier(penalty='elasticnet', l1_ratio=0.5, alpha=0.01)
model.fit(X_train, y_train)

What is the significance of l1_ratio=0.5l1\_ratio = 0.5 in this context?

  1. A

    It assigns equal weightage to L1 and L2 regularizations.

  2. B

    It applies only L2 regularization.

  3. C

    It applies only L1 regularization.

  4. D

    It disables regularization completely.

Show answer

Correct answer

  • A

    It assigns equal weightage to L1 and L2 regularizations.

Question 3

+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)
y_pred = model.predict(X_poly)
print(y_pred)

What will be the output of the code?

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

Correct answer

  • A

Question 4

+3 marksOne correct option

Consider the following code implementation that utilizes sklearn to set up a machine learning model with preprocessing:

python
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV
pipeline = Pipeline([('scaler', StandardScaler()),
('classifier', SVC())])
param_grid = {'scaler__with_mean': [True, False],
'classifier__C': [0.1, 1, 10],
'classifier__kernel': ['linear', 'rbf'],
'classifier__gamma': [0.1, 1, 10]}
grid_search = GridSearchCV(estimator=pipeline,
param_grid=param_grid,
cv=5,
scoring='accuracy',
verbose=2)
grid_search.fit(X_train, y_train)

Which of the following statements correctly describes the effect of setting scaler_with_mean=False?

  1. A

    The data will be standardized without centering, preserving the mean of the dataset.

  2. B

    The data will be centered but not scaled, leading to variance issues.

  3. C

    The parameter has no effect; the data will always be centered regardless of this setting.

  4. D

    The scaling operation will be disabled entirely, leaving the data unchanged.

Show answer

Correct answer

  • A

    The data will be standardized without centering, preserving the mean of the dataset.

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

Consider the following code:

python
from sklearn.datasets import make_classification
from sklearn.linear_model import Perceptron
X_train, y_train = make_classification(n_samples=1000, n_features=5,
n_classes=2, random_state=42)
clf = Perceptron(max_iter=50, warm_start=True, random_state=42)
clf.fit(X_train, y_train)

What will be the behavior of the code?

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

Correct answer

  • B

Question 7

+2 marksOne correct option
  1. A

    0.75

  2. B

    0.80

  3. C

    0.50

  4. D

    0.67

Show answer

Correct answer

  • D

    0.67

Question 8

+2 marksOne correct option
  1. A

    LogisticRegression

  2. B

    Perceptron

  3. C

    RidgeClassifier

  4. D

    Support Vector Machine (SVM)

  5. E

    LassoClassifer

Show answer

Correct answer

  • C

    RidgeClassifier

Question 9

+2 marksOne correct option

You are working on a classification project using the Wine dataset. After fitting a Gaussian Naive Bayes model, you want to assess the probability of each class for the test samples.

python
from sklearn.datasets import load_wine
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
wine = load_wine()
X = wine.data
y = wine.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size
=0.3, random_state=42)
gnb = GaussianNB()
gnb.fit(X_train, y_train)

Which of the following methods will correctly return the class probabilities for the test samples after fitting the Gaussian Naive Bayes model?

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

Correct answer

  • B

Question 10

+2 marksOne correct option
  1. A

    The boundaries become more complex and tightly fitted to the training data.

  2. B

    The boundaries become more regular and smooth.

  3. C

    Decision boundaries are unaffected by C.

  4. D

    The number of support vectors decreases.

Show answer

Correct answer

  • A

    The boundaries become more complex and tightly fitted to the training data.

Question 11

+2 marksOne correct option
  1. A

    0.99

  2. B

    0.87

  3. C

    0.95

  4. D

    0.80

Show answer

Correct answer

  • C

    0.95

Question 12

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

Correct answer

  • A

Question 13

+2 marksOne correct option
  1. A

    It defines the tolerance for stopping criteria.

  2. B

    It defines the learning rate schedule.

  3. C

    It controls regularization strength.

  4. D

    It controls the number of iterations.

Show answer

Correct answer

  • A

    It defines the tolerance for stopping criteria.

Question 14

+2 marksOne or more correct options

Select all that apply.

  1. A

    ’linear’

  2. B

    ’quadratic’

  3. C

    ’rbf’

  4. D

    ’sigmoid’

Show answer

Correct answers

  • A

    ’linear’

  • C

    ’rbf’

  • D

    ’sigmoid’

Question 15

+2 marksOne or more correct options

You are a data scientist working on a binary classification problem to predict whether customers will buy a product based on various features such as age, income, and browsing history. You decide to use LogisticRegression from scikit-learn for this task. After some experimentation, you notice that the model is overfitting the training data, resulting in poor performance on the validation set.

Which of the following actions should you take to mitigate overfitting in your Logistic Regression model?

python
from sklearn.linear_model import LogisticRegression
model = LogisticRegression(penalty='...', C=...)

Select all that apply.

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

Correct answers

  • B
  • C
  • D

Question 16

+2 marksOne or more correct options

Consider the following RidgeClassifier implementation in Python:

python
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import MinMaxScaler
from sklearn.linear_model import RidgeClassifier
X = [[1, 2], [2, 3], [3, 4]]
y = [0, 1, 0]
pipeline = make_pipeline(MinMaxScaler(), RidgeClassifier(alpha=1.0,
fit_intercept=True))
pipeline.fit(X, y)

Which of the following statements are correct? (Select all that apply)

Select all that apply.

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

Correct answers

  • A
  • C
  • D

Question 17

+3 marksOne or more correct options

Select all that apply.

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

Correct answers

  • A
  • B

Question 18

+3 marksNumerical answer
Show answer

Correct answer: 0.017 (accepted within ±0.005)

Question 19

+3 marksNumerical answer

What will be the output of the following code?

python
import numpy as np
from sklearn.neighbors import KNeighborsRegressor
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([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110])
X_test = np.array([[2, 200]])
knn = KNeighborsRegressor(n_neighbors=len(y_train),
metric="euclidean",
weights='uniform')
knn.fit(X_train, y_train)
print(knn.predict(X_test))
Show answer

Correct answer: 60

Question 20

+3 marksNumerical answer

In the following code snippet, how many bigrams will be generated when using CountVectorizer with ngram_range=(2, 2)?

python
from sklearn.feature_extraction.text import CountVectorizer
documents = [
"The quick brown fox",
"jumps over the lazy dog"
]
vectorizer = CountVectorizer(ngram_range=(2, 2))
X = vectorizer.fit_transform(documents)
bigrams = vectorizer.vocabulary_
print(f"Number of bigrams: {len(bigrams)}")

Enter your answer (number of bigrams):

Show answer

Correct answer: 7

Question 21

+2 marksNumerical answer
Show answer

Correct answer: 3.5