uiz Space

September 2024 term · Machine Learning Practice · BSCS2008

Machine Learning Practice End Term: 22 December 2024, Set QDD1 (September 2024 term)

The IIT Madras BS Machine Learning Practice (MLP) End Term paper sat on 22 Dec 2024, in the September 2024 term, set QDD1: 37 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
37
Marks
100
Duration
180 min
MCQ
21
MSQ
12
Numerical
4

Updated

Official paper: IIT M IMPROVEMENT FN EXAM QDD1 22 Dec 2024 · No negative marking.

Question 1

+1 markOne correct option

Dataset: Employee Details

NameAgeDepartmentSalaryJoining_YearPerformance_Score
Alice25HR50000201885
Bob30Finance60000201590
Charlie35IT55000201988
Diana28HR52000202075
Eve22Finance48000202180
Frank40IT65000201092

Based on the above data, answer the given subquestions.

Which of the following commands will return the average age of employees?

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

Correct answer

  • D

Question 2

+3 marksOne or more correct options

Dataset: Employee Details

NameAgeDepartmentSalaryJoining_YearPerformance_Score
Alice25HR50000201885
Bob30Finance60000201590
Charlie35IT55000201988
Diana28HR52000202075
Eve22Finance48000202180
Frank40IT65000201092

Based on the above data, answer the given subquestions.

Which of the following commands will return the number of employees in the 'HR ’ department?

Select all that apply.

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

Correct answers

  • A
  • B

Question 3

+3 marksOne or more correct options

Dataset: Employee Details

NameAgeDepartmentSalaryJoining_YearPerformance_Score
Alice25HR50000201885
Bob30Finance60000201590
Charlie35IT55000201988
Diana28HR52000202075
Eve22Finance48000202180
Frank40IT65000201092

Based on the above data, answer the given subquestions.

Which of the following methods can be used to filter employees with a salary greater than 50,000?

Select all that apply.

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

Correct answers

  • A
  • B
  • C

Question 4

+1 markOne correct option

Dataset: Employee Details

NameAgeDepartmentSalaryJoining_YearPerformance_Score
Alice25HR50000201885
Bob30Finance60000201590
Charlie35IT55000201988
Diana28HR52000202075
Eve22Finance48000202180
Frank40IT65000201092

Based on the above data, answer the given subquestions.

What does the following code return?

  1. A

    The row with the employee who has the lowest performance score.

  2. B

    The row with the employee who has the highest performance score.

  3. C

    The row with the highest salary.

  4. D

    None of these.

Show answer

Correct answer

  • B

    The row with the employee who has the highest performance score.

Question 5

+4 marksOne correct option

Which of the following code snippets will plot the learning curve for training over 100 epochs? Assume that all necessary imports, parameter settings, and initializations are correctly done, and the variable names suggest the data they hold or point to.

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

Correct answer

  • A

Question 6

+4 marksOne correct option

Consider the following initialization of a DecisionTreeClassifier:

python
clf = DecisionTreeClassifier(max_depth=3, random_state=42, splitter='best')

If the training data consists of 100 samples and 10 features, what is the maximum possible number of leaf nodes that can exist in the decision tree, assuming the following conditions:

  • The tree is a perfectly balanced binary tree.
  • There is no pruning applied.
  • There are no additional stopping criteria (e.g., min_samples_split, min_samples_leaf, max_leaf_nodes).
  1. A

    8

  2. B

    16

  3. C

    32

  4. D

    100

Show answer

Correct answer

  • A

    8

Question 7

+3 marksOne correct option

Consider the following code:

python
import numpy as np
from sklearn.linear_model import LinearRegression
X = np.array([[2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]])
# y = 4 * x_0 + 5 * x_1 + 6
y = np.dot(X, np.array([4, 5])) + 6
reg1 = LinearRegression(fit_intercept=True).fit(X, y)
s1 = reg1.score(X, y)
reg2 = LinearRegression(fit_intercept=False).fit(X, y)
s2 = reg2.score(X, y)

Which of the following is true in this case?

  1. A
  2. B
  3. C
Show answer

Correct answer

  • A

Question 8

+3 marksOne correct option

Consider the following code:

python
from sklearn.preprocessing import PolynomialFeatures
import numpy as np
X = np.array([[1], [2], [3]])
poly = PolynomialFeatures(degree=2)
X_poly = poly.fit_transform(X)
print(X_poly)

What will be the output of the above code?

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

Correct answer

  • B

Question 9

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

Correct answer

  • A

Question 10

+3 marksOne correct option

The following code produces an output of 0.9125 on the training data. What is the expected effect on the training accuracy if we increase the max_depth value ?:

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)
clf = DecisionTreeClassifier(max_depth = 2,
min_samples_split = 2,
min_samples_leaf=3,
random_state = 81)
clf.fit(X_train, y_train)
print(clf.score(X_train, y_train))
  1. A

    Output score is likely to increase.

  2. B

    Output score is likely to decrease.

  3. C

    Output score may increase or decrease depending on other factors.

  4. D

    Output score will remain the same.

Show answer

Correct answer

  • A

    Output score is likely to increase.

Question 11

+3 marksOne correct option
  1. A

    The number of base estimators to be trained.

  2. B

    The size of each sample batch for testing.

  3. C

    The maximum number of features used for training.

  4. D

    The number of samples to draw from X to train each base estimator

Show answer

Correct answer

  • D

    The number of samples to draw from X to train each base estimator

Question 12

+3 marksOne correct option
  1. A

    Performs hierarchical clustering and outputs cluster distances.

  2. B

    Outputs the silhouette score for the data points.

  3. C

    Groups data points into 2 clusters and outputs the labels of the clusters for each data point.

  4. D

    Reduces the dimensionality of the dataset to 2 dimensions.

Show answer

Correct answer

  • C

    Groups data points into 2 clusters and outputs the labels of the clusters for each data point.

Question 13

+3 marksOne correct option

You're working on a binary classification task using the ‘MLPClassifier’ to predict whether a customer will make a purchase based on their browsing behavior. You're concerned about overfitting due to the complexity of the model. You decide to increase the ‘alpha’ parameter to control overfitting. The following code snippet shows the application of ‘MLPClassifier’:

python
from sklearn.neural_network import MLPClassifier
import numpy as np
data = np.array([[10, 3], [20, 5], [5, 1], [15, 4], [8, 2]])
# Corresponding target labels (0: No Purchase, 1: Purchase)
target = np.array([0, 1, 0, 1, 0])
# Initialize MLPClassifier with alpha parameter
clf = MLPClassifier(alpha=0.01, random_state=42)
clf.fit(data, target)
# Predict class labels
predicted_labels = clf.predict(data)

What is the effect of increasing the alpha parameter to 0.1 in the MLPClassifier?

  1. A

    It increases the model’s capacity to fit the training data closely, potentially causing overfitting.

  2. B

    It adds a stronger regularization term to the loss function, reducing the model’s complexity and helping prevent overfitting.

  3. C

    It makes the model more prone to overfitting by increasing its sensitivity to noise in the training data.

  4. D

    It directly affects the learning rate, controlling how fast the model converges during training.

Show answer

Correct answer

  • B

    It adds a stronger regularization term to the loss function, reducing the model’s complexity and helping prevent overfitting.

Question 14

+2 marksOne correct option

What will be the output of the following code?

  1. A

    4

  2. B

    5

  3. C

    3

  4. D

    6

Show answer

Correct answer

  • D

    6

Question 15

+2 marksOne correct option

What will be the output of the following code?

  1. A

    [5, 6]

  2. B

    [4, 5]

  3. C

    [3, 4]

  4. D

    [2, 3]

Show answer

Correct answer

  • A

    [5, 6]

Question 16

+2 marksOne correct option

You have loaded a dataset with 500 samples and 50 features into a Pandas DataFrame. Some samples have missing values for a few features. If you want to remove rows with more than 5 missing values, what method would you use?

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

Correct answer

  • C

Question 17

+2 marksOne correct option
  1. A

    Statement 1 False, Statement 2 False

  2. B

    Statement 1 True, Statement 2 False

  3. C

    Statement 1 False, Statement 2 True

  4. D

    Both statements are True

Show answer

Correct answer

  • D

    Both statements are True

Question 18

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

Correct answer

  • C

Question 19

+2 marksOne correct option

What will be the output of the code?

  1. A

    1.25

  2. B

    2.56

  3. C

    4.25

  4. D

    3.25

  5. E

    Given code will return an error.

Show answer

Correct answer

  • B

    2.56

Question 20

+2 marksOne correct option

Consider the following code snippet:

python
import numpy as np
from sklearn.linear_model import SGDRegressor
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]])
y = np.array([3, 6, 9, 12, 15])
model = SGDRegressor(learning_rate='constant', eta0=0.1, max_iter=1000)
model.fit(X, y)

What does the learning_rate='constant' parameter in the SGDRegressor() function control?

  1. A

    It adjusts the learning rate based on the number of iterations.

  2. B

    It specifies the learning rate to decrease as the model converges.

  3. C

    It specifies the fraction of the dataset used for each step in the stochastic gradient descent.

  4. D

    It defines the initial value for the learning rate and keeps it constant throughout training.

Show answer

Correct answer

  • D

    It defines the initial value for the learning rate and keeps it constant throughout training.

Question 21

+2 marksOne correct option

Which of the following is NOT a hyperparameter in machine learning?

  1. A

    Learning rate in gradient descent

  2. B

    Bias in a linear regression model

  3. C

    Number of clusters in k-means

  4. D

    Minimum leaf size in decision trees

Show answer

Correct answer

  • B

    Bias in a linear regression model

Question 22

+2 marksOne correct option

Given below code to load a huge file name as filename.csv and this file is not loading at once in the system which parameter should be added to pd.read_csv to load this file ?

python
import pandas as pd
from sklearn.linear_model import SGDRegressor
for train_df in pd.read_csv("filename.csv", __________=1024):
X = train_df.iloc[:, :-1]
y = train_df.iloc[:, -1]
model = SGDRegressor()
model.partial_fit(prep_X,y)
  1. A
  2. B
  3. C
  4. D
  5. E
  6. F
Show answer

Correct answer

  • C

Question 23

+2 marksOne correct option
  1. A

    It decreases the variance among individual trees.

  2. B

    It increases the variance among individual trees.

  3. C

    It reduces the number of samples used for training each tree.

  4. D

    It reduces overfitting by restricting tree depth.

Show answer

Correct answer

  • B

    It increases the variance among individual trees.

Question 24

+4 marksOne or more correct options

Consider the following code:

python
import numpy as np
from sklearn.model_selection import KFold
X = np.array([47, 31, 18, 95, 85, 77])
kf = KFold(n_splits=3)
for train, test in kf.split(X):
print(X[train])

Which of the following sets of training data can not be printed during the iteration of StratifiedKFold splits, considering the stratification constraint?

Select all that apply.

  1. A

    [47, 31, 18, 95, 77]

  2. B

    [31, 41, 85, 31]

  3. C

    [47, 31, 18]

  4. D

    [47, 31, 85, 77]

  5. E

    [31, 41, 18, 95, 85, 77]

  6. F

    [18, 95, 85, 77]

Show answer

Correct answers

  • A

    [47, 31, 18, 95, 77]

  • B

    [31, 41, 85, 31]

  • C

    [47, 31, 18]

  • E

    [31, 41, 18, 95, 85, 77]

Question 25

+4 marksOne or more correct options

What happens when the following code is executed?

python
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import GridSearchCV
import numpy as np
# Example training data (100 samples, 10 features)
X = np.random.rand(100, 10)
y = np.random.randint(0, 2, 100)
param_grid = {'n_estimators': [50, 100], 'learning_rate': [0.1, 0.01]}
grid = GridSearchCV(GradientBoostingClassifier(), param_grid, cv=3)
grid.fit(X, y)

Select all that apply.

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

Correct answers

  • A
  • C

Question 26

+4 marksOne or more correct options

Select all that apply.

  1. A

    The neural network contains 3 hidden layers with 5 neurons in each hidden layer

  2. B

    The neural network contains 5 hidden layers with 3 neurons in each hidden layer

  3. C

    The neural network contains 2 hidden layers with 3 neurons in the second hidden layer

  4. D

    The neural network contains 2 hidden layers with 5 neurons in the first hidden layer

  5. E

    None of the given options are correct

Show answer

Correct answers

  • C

    The neural network contains 2 hidden layers with 3 neurons in the second hidden layer

  • D

    The neural network contains 2 hidden layers with 5 neurons in the first hidden layer

Question 27

+3 marksOne or more correct options

Consider the following code snippet using scikit-learn:

python
sgd_regressor = SGDRegressor()
param_dist = { 'loss': ['squared_loss', 'huber', 'epsilon_insensitive'],
'alpha': loguniform(1e-4, 1e0),
'penalty': ['l1', 'l2', 'elasticnet'],
'epsilon': loguniform(1e-4, 1e-1),}
random_search = RandomizedSearchCV(sgd_regressor, param_distributions=param_dist, n_iter=10, cv=3, scoring='neg_mean_squared_error')
random_search.fit(X, y)

Assume all the necessary imports and X,yX, y to be the training dataset. Which of the following statements about the given code are correct?

Select all that apply.

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

Correct answers

  • A
  • C
  • D

Question 28

+3 marksOne or more correct options

Select all that apply.

  1. A

    GaussianNB

  2. B

    LogisticRegression

  3. C

    SGDClassifier

  4. D

    RandomForestClassifier

Show answer

Correct answers

  • A

    GaussianNB

  • C

    SGDClassifier

Question 29

+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 30

+3 marksOne or more correct options

What parameters of the k-means clustering algorithm should be tuned to optimize the model performance?

Select all that apply.

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

Correct answers

  • A
  • B
  • C

Question 31

+3 marksOne or more correct options

Consider the following options for evaluating the optimal number of clusters in k-means. Which approaches are valid?

Select all that apply.

  1. A

    Using an Elbow Curve.

  2. B

    Computing Silhouette Scores.

  3. C

    Cross-validation with multiple folds.

  4. D

    All of these

Show answer

Correct answers

  • A

    Using an Elbow Curve.

  • B

    Computing Silhouette Scores.

Question 32

+3 marksOne or more correct options

Which of the following statements are correct about the Silhouette Coefficient?

Select all that apply.

  1. A

    It measures how well each sample is clustered.

  2. B

    A higher score indicates better-defined clusters.

  3. C

    It requires ground truth labels (target variable) to compute.

  4. D

    It can be used to evaluate the quality of any clustering algorithm.

Show answer

Correct answers

  • A

    It measures how well each sample is clustered.

  • B

    A higher score indicates better-defined clusters.

  • D

    It can be used to evaluate the quality of any clustering algorithm.

Question 33

+2 marksOne or more correct options

Select all that apply.

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

Correct answers

  • A
  • B
  • D

Question 34

+3 marksNumerical answer

Given a dataset with shape 4×34 \times 3 (4 samples and 3 features), apply the VarianceThreshold method with a threshold of 0.1. What will be the output of the following code?

python
from sklearn.feature_selection import VarianceThreshold
data = [
[1, 2, 3],
[1, 2, 3],
[1, 2, 4],
[1, 2, 3]
]
# Apply VarianceThreshold with threshold 0.1
vf = VarianceThreshold(threshold=0.1)
# Fit the VarianceThreshold and transform the data
selected_data = vf.fit_transform(data)
# Hint: Columns with variance below the threshold will be removed
selected_data.shape[1]
Show answer

Correct answer: 1

Question 35

+3 marksNumerical answer

What will be the output of the following code snippet?

python
from sklearn.neighbors import KNeighborsClassifier
X_train = [[1, 50], [2, 60], [3, 70], [4, 80]]
y_train = [0, 0, 1, 1]
knn = KNeighborsClassifier(n_neighbors=3)
knn.fit(X_train, y_train)
X_test = [[2.5, 66]]
print(knn.predict(X_test))
Show answer

Correct answer: 1

Question 36

+3 marksNumerical answer

What will be the output of the following code?

python
from sklearn.tree import DecisionTreeClassifier
X_train = [[2, 50], [3, 75], [4, 100], [5, 150], [6, 200]]
y_train = [0, 0, 1, 1, 1]
clf = DecisionTreeClassifier(max_depth=2, random_state=42)
clf.fit(X_train, y_train)
X_test = [[4, 120]]
print(clf.predict(X_test))
Show answer

Correct answer: 1

Question 37

+2 marksNumerical answer

Consider the following code and its output:

Keep the following symbols in mind:

  • >>>: Represents input code
  • # : Represents comment in a code
  • ... : Represents code continuation
  • Without any symbols at the beginning of a line, it is the output of the just above input line of code.
python
>>> from sklearn.datasets import load_digits
>>> from sklearn.svm import SVC
>>> X, y = load_digits(return_X_y=True)
>>> clf = SVC(random_state=0).fit(X, y)
>>> print(y[50:60])
[0 1 0 0 1 4 4 1 4 7]
>>> print(clf.predict(X[50:60, :]))
[0 1 0 0 1 4 4 1 4 7]
>>> print(clf.score(X[50:60, :], y[50:60]))

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

Show answer

Correct answer: 1.0