Quiz Space

January 2024 term · Machine Learning Practice · BSCS2008

Machine Learning Practice End Term: 28 April 2024 (January 2024 term)

The IIT Madras BS Machine Learning Practice (MLP) End Term paper sat on 28 Apr 2024, in the January 2024 term: 39 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
39
Marks
100
Duration
180 min
MCQ
19
MSQ
9
Numerical
11

Updated

Official paper: IIT M FOUNDATION DIPLOMA FN EXAM QDF1 28 Apr 2024 · No negative marking.

Question 1

+2 marksOne correct option

Select multilabel multiclass classification problems:

  1. A

    There is a collection of photographs. Each photograph can have multiple animals, e.g., cats, dogs and birds. Your model should indicate all the animals which are present.

  2. B

    From appropriate weather data, your model must predict, average temperature and average humidity for next seven days.

  3. C

    Predicting expected price of a second hand car with appropriate features.

  4. D

    None of these.

Show answer

Correct answer

  • A

    There is a collection of photographs. Each photograph can have multiple animals, e.g., cats, dogs and birds. Your model should indicate all the animals which are present.

Question 2

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

Correct answer

  • A

Question 3

+2 marksOne correct option

Which of the following can be used (with appropriate supporting code) to compute training error after each iteration?

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

Correct answer

  • A

Question 4

+2 marksOne correct option

For the given code below in which you use how many models will get trained or what will be the length of scores variable ?

python
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import LeaveOneOut
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import make_classification
X, y = make_classification(n_samples=1024, n_features=82, n_classes=2,
↪ random_state=42)
estimator = LogisticRegression()
loocv = LeaveOneOut()
scores = cross_val_score(estimator, X, y, cv=loocv)
  1. A

    1106

  2. B

    82

  3. C

    1024

  4. D

    5

  5. E

    None of these

Show answer

Correct answer

  • C

    1024

Question 5

+2 marksOne correct option

What is the purpose of k-fold cross-validation ?

  1. A

    To split data into training and testing sets.

  2. B

    To tune hyperparameters.

  3. C

    To evaluate model performance on multiple subsets.

  4. D

    To preprocess data.

Show answer

Correct answer

  • C

    To evaluate model performance on multiple subsets.

Question 6

+2 marksOne correct option
  1. A

    Statement 1 is True and Statement 2 is False

  2. B

    Statement 2 is True and Statement 1 is False

  3. C

    Both the statements are True

  4. D

    Both the statements are False

Show answer

Correct answer

  • A

    Statement 1 is True and Statement 2 is False

Question 7

+2 marksOne correct option

Which assumption does Naive Bayes make about the features?

  1. A

    They are independent of each other.

  2. B

    They are always a numerical representation of the text data.

  3. C

    They are linearly related.

  4. D

    They are categorical.

  5. E

    None of these.

Show answer

Correct answer

  • A

    They are independent of each other.

Question 8

+3 marksOne correct option

Given the following code snippet that preprocesses a dataset with both continuous and categorical features using sklearn.preprocessing tools, what will be the first row of the X_transformed array after preprocessing?

python
import numpy as np
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import MinMaxScaler, StandardScaler
from sklearn.compose import ColumnTransformer
X = np.array([[4.0, 'avocado'],
[3.0, 'dragon fruit'],
[2.0, 'sapodilla'],
[7.0, 'papaya']])
preprocessor = ColumnTransformer(
transformers=[('num1', MinMaxScaler(), [0]),
('cat', OneHotEncoder(), [1]),
('num2', StandardScaler(), [0]),])
X_transformed = preprocessor.fit_transform(X)
print(X_transformed[0])
  1. A
  2. B
  3. C
  4. D
  5. E
Show answer

Correct answer

  • A

Question 9

+3 marksOne correct option

You’re working on a dataset containing customer purchase data, and you want to segment the customers into distinct groups based on their purchasing behavior. Each data point represents a customer and includes features like “Total Amount Spent” and “Number of Items Purchased.” Which algorithm is suitable for this scenario?

  1. A

    Linear Regression

  2. B

    Decision Tree

  3. C

    K-means Clustering

  4. D

    Support Vector Machine

  5. E

    None of these

Show answer

Correct answer

  • C

    K-means Clustering

Question 10

+3 marksOne correct option
  1. A

    Increasing the number of neurons in hidden layers will always lead to better model performance.

  2. B

    Decreasing the number of neurons in hidden layers reduces the model’s capacity to capture complex patterns.

  3. C

    The number of neurons in hidden layers does not significantly affect the model’s performance.

  4. D

    Finding the optimal number of neurons is a trial-and-error process and may require experimentation.

Show answer

Correct answer

  • D

    Finding the optimal number of neurons is a trial-and-error process and may require experimentation.

Question 11

+3 marksOne correct option

How does agglomerative clustering handle outliers?

  1. A

    It ignores outliers during the clustering process.

  2. B

    It assigns outliers to the nearest cluster.

  3. C

    It creates separate clusters for outliers.

  4. D

    It removes outliers from the dataset before clustering.

Show answer

Correct answer

  • B

    It assigns outliers to the nearest cluster.

Question 12

+3 marksOne correct option

What is agglomerative clustering?

  1. A

    A hierarchical clustering technique that starts with each data point as its cluster and merges the closest clusters iteratively.

  2. B

    A method for partitioning data into a predefined number of clusters.

  3. C

    A clustering algorithm that uses centroids to iteratively assign data points to clusters.

  4. D

    A dimensionality reduction technique that projects data onto a lower- dimensional space.

Show answer

Correct answer

  • A

    A hierarchical clustering technique that starts with each data point as its cluster and merges the closest clusters iteratively.

Question 13

+3 marksOne correct option

What initialization method is best in KMeans to select initial cluster centroids?

  1. A

    Random initialization

  2. B

    K-means++ initialization

  3. C

    Hierarchical agglomerative initialization

  4. D

    Weighted initialization

Show answer

Correct answer

  • B

    K-means++ initialization

Question 14

+3 marksOne correct option
  1. A

    The distance between cluster centroids

  2. B

    The number of clusters formed

  3. C

    Sum of squared distances of samples to their closest cluster center.

  4. D

    The silhouette coefficient

Show answer

Correct answer

  • C

    Sum of squared distances of samples to their closest cluster center.

Question 15

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

Correct answer

  • A

Question 16

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

Correct answer

  • D

Question 17

+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=5)
bag_clf = BaggingClassifier(base_knn, n_estimators=50, max_samples=0.5,
↪ bootstrap=True, n_jobs=-1)

Which of the following statements is correct?

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

Correct answer

  • C

Question 18

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

Correct answer

  • C

Question 19

+2 marksOne or more correct options

What is the solution for overfitting?

Select all that apply.

  1. A

    To have less constraints/regularization

  2. B

    To have more constraints/regularization

  3. C

    Delete a significant portion of data

  4. D

    Increase the dataset size.

  5. E

    None of these.

Show answer

Correct answers

  • B

    To have more constraints/regularization

  • D

    Increase the dataset size.

Question 20

+2 marksOne or more correct options

Select all the correct options:

Select all that apply.

  1. A

    The more the SGD iterations, the lesser the fluctuations in training error.

  2. B

    More iterations require more computation time.

  3. C

    The tol (error tolerance) parameter restricts the number of iterations performed.

  4. D

    Training error might not consistently decrease while performing SGD iterations.

  5. E

    None of these

Show answer

Correct answers

  • A

    The more the SGD iterations, the lesser the fluctuations in training error.

  • B

    More iterations require more computation time.

  • C

    The tol (error tolerance) parameter restricts the number of iterations performed.

  • D

    Training error might not consistently decrease while performing SGD iterations.

Question 21

+2 marksOne or more correct options

Select all that apply.

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

Correct answers

  • B
  • C

Question 22

+2 marksOne or more correct options

Which of the following statements are true?

Select all that apply.

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

Correct answers

  • A
  • C

Question 23

+2 marksOne or more correct options

Which of the following options are correct regarding regularization?

Select all that apply.

  1. A

    It is a technique used to minimize the adjusted loss function and avoid underfitting.

  2. B

    It helps in increasing the bias of the training model.

  3. C

    It determines the rows to be selected as a training dataset.

  4. D

    Elastic net regularization is a combination of L1 and L2 regularization both.

Show answer

Correct answers

  • B

    It helps in increasing the bias of the training model.

  • D

    Elastic net regularization is a combination of L1 and L2 regularization both.

Question 24

+3 marksOne or more correct options

Which of the following techniques are used in decision trees to make decisions or to measure the quality of a split while training the model?

Select all that apply.

  1. A

    Entropy

  2. B

    RoC Curve

  3. C

    Cross Entropy

  4. D

    Gini Impurity

Show answer

Correct answers

  • A

    Entropy

  • D

    Gini Impurity

Question 25

+3 marksOne or more correct options

Which of the following approaches is(are) helpful to find a good value for k in k−means clustering algorithm?

Select all that apply.

  1. A

    Plotting an Elbow curve.

  2. B

    Using classifiers before making clusters.

  3. C

    Plotting Silhouette coefficient for various values of k.

  4. D

    Using k-fold cross validation

Show answer

Correct answers

  • A

    Plotting an Elbow curve.

  • C

    Plotting Silhouette coefficient for various values of k.

Question 26

+4 marksOne or more correct options

Consider the following block of code:

python
from sklearn.datasets import load_breast_cancer
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
X,y = load_breast_cancer(as_frame = True,
return_X_y = True)
X_train,X_test,y_train,y_test = train_test_split(X,y,
test_size = 0.2,
random_state = 1)
clf = DecisionTreeClassifier(min_samples_split = 5,
min_samples_leaf = 3,
random_state = 5)
clf.fit(X_train, y_train)
print(clf.score(X_test, y_test))

In which of the following scenarios, the split will NOT be made at node N?

Select all that apply.

  1. A

    10 number of samples at node N. If it is split, it can split such that 2 samples in the left child and 8 samples in the right child.

  2. B

    6 number of samples at node N. If it is split, it can split such that 3 samples in the left child and 3 samples in the right child.

  3. C

    12 number of samples at node N. If it is split, it can split such that 5 samples in the left child and 7 samples in the right child.

  4. D

    4 number of samples at node N. If it is split, it can split such that 3 samples in the left child and 1 samples in the right child.

Show answer

Correct answers

  • A

    10 number of samples at node N. If it is split, it can split such that 2 samples in the left child and 8 samples in the right child.

  • D

    4 number of samples at node N. If it is split, it can split such that 3 samples in the left child and 1 samples in the right child.

Question 27

+2 marksNumerical answer
Show answer

Correct answer: 0.5

Question 28

+2 marksNumerical answer

Consider following data points:

python
import numpy as np
X = np.array([[1,1],[10,11],[5,5],[25,18],[-1,-1]])
y = np.array([0,1,0,1,1]).reshape(-1,1)

What will be the highest accuracy a perceptron model can achieve on this dataset without any feature engineering?

Show answer

Correct answer: 0.8

Question 29

+2 marksNumerical answer
Show answer

Correct answer: 0.375 (accepted within ±0.005)

Question 30

+2 marksNumerical answer

Consider the following Python code snippet and the given dataset that has been stored in the data variable that demonstrates the use of GaussianNB from scikit-learn:

OutlookTemperatureHumidityWindyPlay Golf
0RainyHotHighFalseNo
1OvercastHotHighFalseYes
2SunnyCoolNormalFalseYes
3SunnyCoolNormalTrueNo
4OvercastCoolNormalTrueYes
5RainyCoolNormalFalseYes
6RainyHotHighTrueNo
7OvercastHotHighFalseYes
8SunnyCoolNormalTrueNo
9OvercastCoolNormalTrueYes
10RainyCoolNormalFalseYes
11OvercastHotNormalFalseYes
python
from sklearn.preprocessing import OneHotEncoder, LabelEncoder
from sklearn.naive_bayes import GaussianNB
X = data.drop("Play Golf", axis=1)
y = data["Play Golf"]
X = OneHotEncoder(sparse_output=False).fit_transform(X)
y = LabelEncoder().fit_transform(y)
estimator = GaussianNB()
estimator.fit(X,y)
print(estimator.class_prior_) # gives the priori of labels(y)

What is the prior probability of the label being “No”? i.e. p(y=“No”)p(y = \text{“}No\text{”})

Show answer

Correct answer: 0.335 (accepted within ±0.015)

Question 31

+2 marksNumerical answer

What is the output of the following code?

python
from sklearn.neighbors import KNeighborsClassifier
X = [[2,3], [5,6], [10, 11], [15,16], [20,21]]
y = [0, 1, 1, 1, 2]
knn = KNeighborsClassifier(n_neighbors=3,
metric='euclidean',
weights='uniform')
knn.fit (X, y)
print (knn.predict([[8,9]]))
Show answer

Correct answer: 1

Question 32

+3 marksNumerical answer

Consider the following code snippet:

python
from sklearn.datasets import fetch_california_housing, load_iris
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler, PolynomialFeatures
from sklearn.pipeline import Pipeline, FeatureUnion
X,y = load_iris(return_X_y= True)
polynomial_transform = PolynomialFeatures(degree=3,
interaction_only=False,
include_bias=False)
combined_features = FeatureUnion([('poly', polynomial_transform),
('pca', PCA(n_components=2))])
pipeline = Pipeline([('features', combined_features),
('scaler', MinMaxScaler())])
X_transformed = pipeline.fit_transform(X)
print(X_transformed.shape)

If the shape of X is (150,4)(150, 4), what will be the number of features in X_transformed?

Show answer

Correct answer: 36

Question 33

+3 marksNumerical answer

What will be the output of the following code snippet? Assume necessary imports.

python
X = np.array([[1,6],
[-2,0],
[-0.25, 3.5]])
pca_transform = PCA(n_components=2)
X_transformed = pca_transform.fit_transform(X)
print(pca_transform.explained_variance_ratio_[0])
Show answer

Correct answer: 1.00

Question 34

+3 marksNumerical answer

What will be the output of the following code snippet?

python
from sklearn.linear_model import Perceptron
# Sample data
X = [[0, 0], [0, 1], [1, 0], [1, 1]]
y = [0, 0, 0, 1]
clf = Perceptron(tol=None, shuffle=False)
clf.fit(X, y)
print(clf.predict([[2, 2]]))
Show answer

Correct answer: 1

Question 35

+2 marksOne or more correct options

Consider following code snippet, assume necessary imports:

python
df=pd.DataFrame(data={"Name":['Akash',
'Brajesh',
'Charu',
'Deepak'],
"Maths":[34,43,56,77],
"English":[23,45,67,82],
"Hindi":[53,35,np.nan,"hi"],},
index = range(11,15))

Based on the above data, answer the given subquestions.

Select all that apply.

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

Correct answers

  • A
  • C

Question 36

+2 marksNumerical answer

Consider following code snippet, assume necessary imports:

python
df=pd.DataFrame(data={"Name":['Akash',
'Brajesh',
'Charu',
'Deepak'],
"Maths":[34,43,56,77],
"English":[23,45,67,82],
"Hindi":[53,35,np.nan,"hi"],},
index = range(11,15))

Based on the above data, answer the given subquestions.

Show answer

Correct answer: 120

Question 37

+2 marksNumerical answer

Consider following code snippet, assume necessary imports:

python
df=pd.DataFrame(data={"Name":['Akash',
'Brajesh',
'Charu',
'Deepak'],
"Maths":[34,43,56,77],
"English":[23,45,67,82],
"Hindi":[53,35,np.nan,"hi"],},
index = range(11,15))

Based on the above data, answer the given subquestions.

Show answer

Correct answer: 3

Question 38

+2 marksNumerical answer

Consider following code snippet, assume necessary imports:

python
df=pd.DataFrame(data={"Name":['Akash',
'Brajesh',
'Charu',
'Deepak'],
"Maths":[34,43,56,77],
"English":[23,45,67,82],
"Hindi":[53,35,np.nan,"hi"],},
index = range(11,15))

Based on the above data, answer the given subquestions.

What is the output of the following code snippet:

python
def getPassing(aRow):
if aRow['Maths']>=35 and aRow['English']>=35:
return True
return False
df.apply(getPassing).sum()

Enter -1, if you think the given statement will generate an error.

Show answer

Correct answer: -1

Question 39

+2 marksOne correct option

Consider following code snippet, assume necessary imports:

python
df=pd.DataFrame(data={"Name":['Akash',
'Brajesh',
'Charu',
'Deepak'],
"Maths":[34,43,56,77],
"English":[23,45,67,82],
"Hindi":[53,35,np.nan,"hi"],},
index = range(11,15))

Based on the above data, answer the given subquestions.

  1. A

    The number of rows will decrease in the dataset.

  2. B

    The number of columns will decrease in the dataset.

  3. C

    The number of columns and number of rows, both, will decrease in the dataset.

  4. D

    There will be no change.

  5. E

    Insufficient information.

Show answer

Correct answer

  • A

    The number of rows will decrease in the dataset.