Quiz Space

May 2023 term · Machine Learning Practice · BSCS2008

MLP End Term: 3 September 2023, Set QPD1-S2 (May 2023 term)

The IIT Madras BS Machine Learning Practice (MLP) End Term paper sat on 3 Sept 2023, in the May 2023 term, set QPD1-S2: 34 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
34
Marks
100
Duration
180 min
Numerical
4
MCQ
24
MSQ
6

Updated

Official paper: IIT M DIPLOMA ET1 EXAM QPD1 S2 03 Sep · No negative marking.

Question 1

+2 marksNumerical answer
Show answer

Correct answer: 0.5

Question 2

+2 marksOne correct option

Given below a y_train list which consists of pizza’s ordered by the customers in a shop.

python
y_train = [['regular', 'veg'],
['medium', 'veg'],
['regular', 'non-veg'],
['medium', 'non-veg']]

MultiLabelBinarizer from sklearn library has been used to convert the y_train into numbers, so which of the following option matches with the output using the following code ?

python
from sklearn.preprocessing import MultiLabelBinarizer
mlb = MultiLabelBinarizer(classes=['regular','medium', 'veg', 'non-veg'])
print(mlb.fit_transform(y_train))
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 3

+2 marksOne correct option

You’re building a machine learning pipeline to preprocess data and train a model on a classification task. You decide to use a pipeline that includes data preprocessing and a support vector machine (SVM) classifier.

The following code snippet demonstrates the pipeline creation and usage:

python
from sklearn.pipeline import Pipeline
from sklearn.svm import SVC
from sklearn.preprocessing import StandardScaler
import numpy as np
# Simulated data (features: X, target: y)
X = np.array([[2, 3], [5, 7], [8, 10]])
y = np.array([0, 1, 0])
# Create a pipeline with StandardScaler and SVM classifier
pipeline = Pipeline([
('scaler', StandardScaler()),
('svm', SVC())])
# Fit the pipeline on training data
pipeline.fit(X, y)
# Make predictions using the trained pipeline
predictions = pipeline.predict(X)

What is the purpose of using the pipeline in this code snippet?

  1. A

    The pipeline combines multiple models for better model performance.

  2. B

    The pipeline allows for simultaneous training of the scaler and classifier.

  3. C

    The pipeline simplifies the code by encapsulating preprocessing and modeling steps.

  4. D

    The pipeline ensures that only linear SVM can be used for this classification task.

Show answer

Correct answer

  • C

    The pipeline simplifies the code by encapsulating preprocessing and modeling steps.

Question 4

+2 marksOne correct option

You’ve developed a binary classification model to predict whether an email is spam or not. You want to evaluate the model’s performance using appropriate metrics. The following options represent different evaluation metrics. Choose the one that is most suitable for assessing the model’s performance in this scenario:

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

Correct answer

  • C

Question 5

+2 marksOne correct option

You are building a sentiment analysis model using scikit-learn’s SGDClassifier to classify movie reviews as positive or negative. The dataset is quite large, and you’re dealing with a high-dimensional feature space. You want to fine-tune the hyperparameters of the classifier to achieve better convergence and classification performance.

Here’s how you’re setting up the SGDClassifier:

python
from sklearn.linear_model import SGDClassifier
classifier = SGDClassifier(loss='hinge', alpha=0.0001,
max_iter=1000, tol=1e-3, power_t=0.5)

In the context of the given code and scenario, what does the power_t parameter value of 0.5 influence during the training process?

  1. A

    It determines the degree of L2 regularization applied to the model’s weights.

  2. B

    It controls the decay rate of the learning rate during each iteration.

  3. C

    It sets the threshold for early stopping based on the loss function improvement.

  4. D

    It adjusts the aggressiveness of stochastic gradient updates for faster convergence.

Show answer

Correct answer

  • B

    It controls the decay rate of the learning rate during each iteration.

Question 6

+2 marksOne correct option

What is the output of the following code?

python
corpus = [‘An overfitted model is a mathematical model that contains more
parameters than can be justified by the data.’]
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
vectors = vectorizer.fit_transform(corpus)
print(vectors.shape)
  1. A

    (16,1)

  2. B

    (8,2)

  3. C

    (4,4)

  4. D

    (1,16)

Show answer

Correct answer

  • D

    (1,16)

Question 7

+2 marksOne correct option
  1. A

    It ensures that the model will always produce the same predictions for any input data.

  2. B

    It guarantees that the model will converge to the global optimum during training.

  3. C

    It prevents overfitting by adding randomness to the model’s predictions.

  4. D

    It allows for reproducibility, ensuring consistent results across different runs.

Show answer

Correct answer

  • D

    It allows for reproducibility, ensuring consistent results across different runs.

Question 8

+3 marksOne or more correct options

Consider the following code involving the use of LabelEncoder from sklearn.preprocessing:

python
from sklearn.preprocessing import LabelEncoder
data = ["apple", "orange", "banana", "apple", "grape", "orange", "grape"]
encoder = LabelEncoder()
encoded_data = encoder.fit_transform(data)
print(encoded_data)

Which of the following statements is true based on the code?

Select all that apply.

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

Correct answers

  • A
  • D

Question 9

+3 marksOne or more correct options

Which of the following statements are true?

Select all that apply.

  1. A

    KNeighborsClassifier with high values of n_neighbors produces complex decision boundaries.

  2. B

    KNeighborsClassifier with high values of n_neighbors produces smooth decision boundaries.

  3. C

    In KNeighborsClassifier the scale of the features(columns) can impact the decision boundaries.

  4. D

    None of these

Show answer

Correct answers

  • B

    KNeighborsClassifier with high values of n_neighbors produces smooth decision boundaries.

  • C

    In KNeighborsClassifier the scale of the features(columns) can impact the decision boundaries.

Question 10

+3 marksOne or more correct options

Which of the following option(s) are correct regarding regularization?

Select all that apply.

  1. A

    Regularization is the error given by any model while predicting the values for the test set.

  2. B

    It helps in decreasing the bias of the training model.

  3. C

    Compare to without regularized model regularization decreases the variance of the training model

  4. D

    Predictions made with the Ridge Regression are less sensitive to
    weights(coefficients) than the Linear Regression.

Show answer

Correct answers

  • C

    Compare to without regularized model regularization decreases the variance of the training model

  • D

    Predictions made with the Ridge Regression are less sensitive to
    weights(coefficients) than the Linear Regression.

Question 11

+3 marksOne correct option

Consider the following sklearn code snippet that employs a Pipeline for data preprocessing:

python
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import MinMaxScaler, Binarizer
data = [[1, 5], [5, 15], [0, 10], [1, 15]]
pipeline = Pipeline([('scaler', MinMaxScaler()),
('binarize', Binarizer(threshold=0.1))])
transformed_data = pipeline.fit_transform(data)

What will be the output of the following code?

python
print(transformed_data[0])
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 12

+3 marksOne correct option

Consider the following code snippet that uses PCA from sklearn.decomposition for dimensionality reduction on a dataset with 10 features:

python
import numpy as np
from sklearn.decomposition import PCA
np.random.seed(42)
X = np.random.rand(100, 10)
pca = PCA(n_components=4)
X_pca = pca.fit_transform(X)
explained_variance = np.sum(pca.explained_variance_ratio_)

After executing this code, which of the following statements is true regarding the explained_variance?

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

Correct answer

  • B

Question 13

+3 marksOne correct option

You’ve built a linear regression model to predict the salary of employees based on their years of experience and education level. The model’s coefficients for the features are as follows: - Coefficient for Years of Experience: 5000
- Coefficient for Education Level: 3000
What does the coefficient for ”Years of Experience” (5000) represent in this context?

  1. A

    For each additional year of experience, an employee’s salary is expected to increase by 5000.

  2. B

    For each additional year of experience, an employee’s salary is expected to decrease by 5000.

  3. C

    Education level has a stronger impact on salary than years of experience.

  4. D

    The coefficient doesn’t have any meaningful interpretation in this scenario.

Show answer

Correct answer

  • A

    For each additional year of experience, an employee’s salary is expected to increase by 5000.

Question 14

+3 marksOne correct option

You’re working on a dataset that includes data points for a single feature and a target variable. You decide to use polynomial regression with a degree of 3 to capture potential cubic relationships. The following code snippet demonstrates the process:

python
from sklearn.preprocessing import PolynomialFeatures
import numpy as np
# Simulated data (feature: X)
X = np.array([1, 2, 3, 4, 5])
# Reshape the features
X = X.reshape(-1, 1)
# Transform features into polynomial features
poly = PolynomialFeatures(degree=3)
X_poly = poly.fit_transform(X)

What will be the shape of the X_poly matrix after transforming the feature ‘X‘ into polynomial features of degree 3?

  1. A

    (5, 1)

  2. B

    (5, 3)

  3. C

    (5, 4)

  4. D

    (5, 6)

Show answer

Correct answer

  • C

    (5, 4)

Question 15

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

Correct answer

  • C

Question 16

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

Correct answer

  • C

Question 17

+3 marksOne correct option

Imagine you’re training a Perceptron using sklearn with the following code:

python
from sklearn.linear_model import Perceptron
X = [[0, 0.5], [1, 1.5], [1, 2], [2, 3]]
y = [-1, -1, 1, 1]
clf = Perceptron( tol=None, shuffle=True, random_state=42)
clf.fit(X, y)
iterations = clf.n_iter_

Given the linearly separable nature of the data, how many iterations would it most likely take for the perceptron to converge? What will be the value of iterations?

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

Correct answer

  • C

Question 18

+3 marksOne correct option
  1. A

    A higher alpha value results in stronger regularization, leading to larger feature coefficients.

  2. B

    The alpha value has no impact on the regularization strength in
    ‘RidgeClassifier‘.

  3. C

    Cross-validation can be used to find the optimal alpha value.

  4. D

    ‘RidgeClassifier‘ automatically determines the alpha value based on the data distribution.

Show answer

Correct answer

  • C

    Cross-validation can be used to find the optimal alpha value.

Question 19

+3 marksOne correct option

You’re applying the K-means clustering algorithm to a dataset with a large number of data points. You decide to use the K-means++ initialization method for better convergence and clustering quality. What is the primary advantage of using K-means ++ initialization over random initialization?

  1. A

    K-means++ initialization guarantees finding the global optimum of the clustering solution.

  2. B

    K-means++ initialization speeds up the convergence of the algorithm.

  3. C

    K-means++ initialization reduces the number of clusters needed for accurate results.

  4. D

    K-means++ initialization helps avoid local optima during clustering.

Show answer

Correct answer

  • D

    K-means++ initialization helps avoid local optima during clustering.

Question 20

+3 marksOne correct option

Suppose you are working on a classification task involving handwritten digit recognition using scikit-learn’s MLPClassifier. You have a large dataset of digit images and want to train a neural network for this task. However, you’re concerned about overfitting and want to make sure the training process stops at the right time to avoid this issue. In the context of training an MLPClassifier for handwritten digit recognition,how does the early stopping parameter help prevent overfitting?

  1. A

    It terminates the training process as soon as the specified number of hidden layers are trained.

  2. B

    It automatically decreases the learning rate during training to slow down the optimization process.

  3. C

    It pauses the training when the model’s performance on a validation set stops improving.

  4. D

    It enforces a maximum limit on the number of epochs during the training process.

Show answer

Correct answer

  • C

    It pauses the training when the model’s performance on a validation set stops improving.

Question 21

+3 marksOne correct option

You’re training a multi-layer perceptron (MLP) classifier on a dataset for a multi-class classification task. The following code snippet demonstrates the process using the ‘MLPClassifier’ from scikit-learn:

python
from sklearn.neural_network import MLPClassifier
import numpy as np
# Simulated data (features: X, target: y)
X = np.array([[1, 2], [3, 4], [5, 6]])
y = np.array([0, 1, 2])
# Create an MLPClassifier with a specified maximum number of iterations
model = MLPClassifier(max_iter=100, random_state=42)
# Fit the model on the training data
model.fit(X, y)
# Get the number of iterations used in training
iterations_used = model.n_iter_

What does the parameter max_iter=100 in the MLPClassifier signify?

  1. A

    It specifies the maximum number of features to be used during training.

  2. B

    It determines the maximum number of neurons in the hidden layers.

  3. C

    It sets the maximum number of iterations for the training process.

  4. D

    It controls the maximum number of epochs for the training process.

Show answer

Correct answer

  • C

    It sets the maximum number of iterations for the training process.

Question 22

+3 marksOne correct option

You’re working on a multi-class classification task using the ‘MLPClassifier’ from scikit-learn. The dataset contains features with varying scales, and you’re considering whether to scale the features before training the model. How might feature scaling impact the prediction accuracy of the ‘MLPClassifier’?

  1. A

    Feature scaling has no effect on the accuracy of ‘MLPClassifier‘ predictions.

  2. B

    Scaling features is only relevant if the dataset contains categorical features.

  3. C

    Feature scaling can lead to overfitting and decreased prediction accuracy.

  4. D

    Scaling features can help the model converge faster and improve prediction accuracy.

Show answer

Correct answer

  • D

    Scaling features can help the model converge faster and improve prediction accuracy.

Question 23

+3 marksNumerical answer

For LinearRegression with equation Y=W0X0+W1X1+W2X2+ϵY = W_0X_0 + W_1X_1 + W_2X_2 + \epsilon and given that W2=65∗W1W_2 = \frac{6}{5} * W_1 and ϵ=0\epsilon = 0. What will be the value of the W1W_1 for the below code? (Write 3 digits after the decimal)

Where X1X_1 and X2X_2 are column1 and column2 respectively and W1W_1 and W2W_2 are weights associated to the respected columns while fitting

python
from sklearn.linear_model import LinearRegression
X_train = [[0,0], [2,2.4], [4,4.8], [6,7.2]]
y_train = [0,1,2,3]
reg = LinearRegression(fit_intercept=False) #intercept = 0
reg.fit(X_train,y_train)
print(reg.coef_[0])
Show answer

Correct answer: 0.20455 (accepted within ±0.00065)

Question 24

+3 marksNumerical answer
Show answer

Correct answer: 0.287 (accepted within ±0.004)

Question 25

+3 marksNumerical answer
Show answer

Correct answer: 2

Question 26

+4 marksOne or more correct options

Consider the following code snippet that employs LogisticRegression from sklearn on a feature matrix X and corresponding label vector y:

python
from sklearn.linear_model import LogisticRegression
model = LogisticRegression(C=0.8, multi_class='multinomial', max_iter=1000)
model.fit(X, y)

Given the code above, which of the following statements is true?

Select all that apply.

  1. A

    The logistic regression model is set up for binary classification.

  2. B

    The model does not use any regularization because the parameter C is set.

  3. C

    The model has been specifically set up to handle a multi-class classification problem using a softmax regression approach.

  4. D

    The model will iterate over the data a maximum of 1000 times, irrespective of convergence.

Show answer

Correct answers

  • C

    The model has been specifically set up to handle a multi-class classification problem using a softmax regression approach.

  • D

    The model will iterate over the data a maximum of 1000 times, irrespective of convergence.

Question 27

+2 marksOne or more correct options

Select all that apply.

  1. A

    MultinomialNB

  2. B

    RandomForestRegressor

  3. C

    MiniBatchKMeans

  4. D

    LogisticRegressor

Show answer

Correct answers

  • A

    MultinomialNB

  • C

    MiniBatchKMeans

Question 28

+2 marksOne or more correct options

Select all that apply.

  1. A

    ‘poly’,

  2. B

    ‘lasso’

  3. C

    ‘scale’

  4. D

    ‘sigmoid’

Show answer

Correct answers

  • A

    ‘poly’,

  • D

    ‘sigmoid’

Question 29

+4 marksOne correct option

Consider the following code snippet where two decision trees are trained on the same dataset:

python
from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import load_digits
data = load_digits()
X, y = data.data, data.target
tree_1 = DecisionTreeClassifier(splitter='best', max_leaf_nodes=5)
tree_1.fit(X, y)
tree_2 = DecisionTreeClassifier(splitter='random', max_leaf_nodes=None)
tree_2.fit(X, y)

Given the configurations of tree_1 and tree_2, which decision tree is more likely to overfit the training data?

  1. A
  2. B
Show answer

Correct answer

  • B

Question 30

+4 marksOne correct option

Given the following code using BaggingClassifier with KNeighborsClassifier as the base estimator:

python
from sklearn.ensemble import BaggingClassifier
from sklearn.neighbors import KNeighborsClassifier
base_knn = KNeighborsClassifier(n_neighbors=3, weights='distance')
bag_clf = BaggingClassifier(base_knn, n_estimators=30, max_samples=100,
bootstrap=False, random_state=42)

Which of the following statements is correct?

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

Correct answer

  • B

Question 31

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

Correct answer

  • D

Question 32

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

Correct answer

  • A

Question 33

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

Correct answer

  • D

Question 34

+4 marksOne correct option

You’re evaluating the results of a clustering algorithm and you calculate the silhouette score for the clustering solution. The obtained silhouette score is -0.15. What can you infer from this silhouette score?

  1. A

    The clustering solution has well-defined and distinct clusters.

  2. B

    The silhouette score indicates a random distribution of data points across clusters.

  3. C

    The data points are equally spaced across clusters.

  4. D

    The clustering solution is flawed and the data points might be assigned to incorrect clusters.

Show answer

Correct answer

  • D

    The clustering solution is flawed and the data points might be assigned to incorrect clusters.