uiz Space

January 2025 term · Machine Learning Practice · BSCS2008

Machine Learning Practice Quiz 1: 23 February 2025 (January 2025 term)

The IIT Madras BS Machine Learning Practice (MLP) Quiz 1 paper sat on 23 Feb 2025, in the January 2025 term: 20 questions for 40 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
20
Marks
40
Duration
120 min
MCQ
11
MSQ
4
Numerical
5

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 23 Feb 2025 · No negative marking.

Question 1

+2 marksOne correct option

What is the primary risk of not performing a train-test split in a machine learning workflow?

  1. A

    The training time will increase.

  2. B

    The model might overfit the training data and perform poorly on new data.

  3. C

    The dataset may become unbalanced.

  4. D

    The model may fail to converge.

Show answer

Correct answer

  • B

    The model might overfit the training data and perform poorly on new data.

Question 2

+2 marksOne correct option

Why is data preprocessing necessary before using it for model building?

  1. A

    The data may contain outliers or missing values due to errors in data collection.

  2. B

    Features may have different scales, affecting model performance.

  3. C

    The dataset may include non-numerical features that need to be converted to numerical representations.

  4. D

    All of these

Show answer

Correct answer

  • D

    All of these

Question 3

+2 marksOne correct option

What is the purpose of the tol parameter in the fit method of the stochastic regressor?

python
from sklearn.linear_model import SGDRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.datasets import load_breast_cancer
X,y = load_breast_cancer(return_X_y=True)
model = SGDRegressor(early_stopping=True,
validation_fraction=0.2,
tol=0.001,
n_iter_no_change=5)
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2,
random_state=42)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
  1. A

    It specifies the tolerance level for early stopping based on the change in the validation error.

  2. B

    It controls the learning rate of the stochastic regressor during training.

  3. C

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

  4. D

    It defines the fraction of the validation set used for early stopping.

Show answer

Correct answer

  • A

    It specifies the tolerance level for early stopping based on the change in the validation error.

Question 4

+2 marksOne correct option

Suppose we want to transform features in a dataset using polynomial transformation. The sklearn API provides the functionality in which of the following modules?

  1. A

    sklearn.dataset

  2. B

    sklearn.model_selection

  3. C

    sklearn.preprocessing

  4. D

    sklearn.featureSelection

  5. E

    sklearn.featureExtraction

Show answer

Correct answer

  • C

    sklearn.preprocessing

Question 5

+3 marksOne correct option

For a dataset with 1000 data points and 100 features, the following code will generate how many models during execution?

Note: X is the feature matrix and y is the target vector.

python
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import LeaveOneOut
from sklearn.linear_model import linear_regression
lin_reg = linear_regression()
loocv = LeaveOneOut()
score = cross_val_score(lin_reg, X, y, cv=loocv)
  1. A

    1000

  2. B

    100

  3. C

    99

  4. D

    999

Show answer

Correct answer

  • A

    1000

Question 6

+3 marksOne correct option

Consider the following code:

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

Which of the following is more likely to be true?

  1. A
  2. B
  3. C
Show answer

Correct answer

  • B

Question 7

+2 marksOne or more correct options

Given the following code snippet, which statement is true regarding the use of LabelEncoder?

python
from sklearn.preprocessing import LabelEncoder
data = ["cat", "dog", "fish", "cat", "bird", "dog", "bird"]
encoder = LabelEncoder()
encoded_data = encoder.fit_transform(data)
print(encoded_data)

Select all that apply.

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

Correct answers

  • A
  • D

Question 8

+2 marksOne or more correct options

Which of the following Evaluation metrics can be used in a regression problem?

Select all that apply.

  1. A

    Mean Squared Error

  2. B

    Accuracy

  3. C

    F1-Score

  4. D

    Mean Absolute Error

  5. E

    credit score

  6. F

    CGPA

Show answer

Correct answers

  • A

    Mean Squared Error

  • D

    Mean Absolute Error

Question 9

+2 marksNumerical answer
Show answer

Correct answer: 3.5

Question 10

+3 marksNumerical answer

For LinearRegression with equation Y=W0X0+W1X1+W2X2Y = W_0X_0+W_1X_1+W_2X_2 and given that W2=2∗W1W_2 = 2*W_1.

What will be the value of the W2W_2 for the below code if the model doesn't make any error?

(Write the answer correct upto one 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 = [[1,2], [2,4], [3,6], [4,8]]
y_train = [1,2,3,4]
reg = LinearRegression(fit_intercept=False) #intercept=0
reg.fit(X_train,y_train)
print(reg.coef_[1])
Show answer

Correct answer: 0.4

Question 11

+2 marksOne or more correct options

Consider the given Table 1: Banking data for the given subquestions stored as pandas dataframe in variable df

python
>>> import pandas as pd
>>> df = pd.read_csv('dataset.csv')
>>> print(df)
AgeJobMaritalEducationBalanceHousingContact
21unemployedmarriedsecondary77387notelephone
49managementmarriedtertiary2037nonan
72self-employedmarriedtertiary132nocellular
31blue-collarmarriedsecondary298yesnan
28adminsinglesecondary2831yesnan
39techniciansinglesecondary15yescellular
32blue-collarmarriedprimary131yesnan
59managementmarriedtertiary5314nocellular
27techniciansinglesecondary155yescellular
47blue-collarmarriedprimary259nocellular

Table 1: Banking Data

Based on the above data, answer the given subquestions.

Which of the columns in the banking data are nominal features?

Select all that apply.

  1. A

    Job

  2. B

    Marital

  3. C

    Education

  4. D

    Housing

  5. E

    Contact

Show answer

Correct answers

  • A

    Job

  • B

    Marital

  • D

    Housing

  • E

    Contact

Question 12

+2 marksOne correct option

Consider the given Table 1: Banking data for the given subquestions stored as pandas dataframe in variable df

python
>>> import pandas as pd
>>> df = pd.read_csv('dataset.csv')
>>> print(df)
AgeJobMaritalEducationBalanceHousingContact
21unemployedmarriedsecondary77387notelephone
49managementmarriedtertiary2037nonan
72self-employedmarriedtertiary132nocellular
31blue-collarmarriedsecondary298yesnan
28adminsinglesecondary2831yesnan
39techniciansinglesecondary15yescellular
32blue-collarmarriedprimary131yesnan
59managementmarriedtertiary5314nocellular
27techniciansinglesecondary155yescellular
47blue-collarmarriedprimary259nocellular

Table 1: Banking Data

Based on the above data, answer the given subquestions.

Choose the correct option to find the number of null values (represented as nan) present in the Contact column

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

Correct answer

  • A

Question 13

+2 marksOne correct option

Consider the given Table 1: Banking data for the given subquestions stored as pandas dataframe in variable df

python
>>> import pandas as pd
>>> df = pd.read_csv('dataset.csv')
>>> print(df)
AgeJobMaritalEducationBalanceHousingContact
21unemployedmarriedsecondary77387notelephone
49managementmarriedtertiary2037nonan
72self-employedmarriedtertiary132nocellular
31blue-collarmarriedsecondary298yesnan
28adminsinglesecondary2831yesnan
39techniciansinglesecondary15yescellular
32blue-collarmarriedprimary131yesnan
59managementmarriedtertiary5314nocellular
27techniciansinglesecondary155yescellular
47blue-collarmarriedprimary259nocellular

Table 1: Banking Data

Based on the above data, answer the given subquestions.

In Contact column which of the following statistical measures can be used to replace nan values?

  1. A

    Mean

  2. B

    Median

  3. C

    Mode

  4. D

    Variance

Show answer

Correct answer

  • C

    Mode

Question 14

+2 marksOne or more correct options

Consider the given Table 1: Banking data for the given subquestions stored as pandas dataframe in variable df

python
>>> import pandas as pd
>>> df = pd.read_csv('dataset.csv')
>>> print(df)
AgeJobMaritalEducationBalanceHousingContact
21unemployedmarriedsecondary77387notelephone
49managementmarriedtertiary2037nonan
72self-employedmarriedtertiary132nocellular
31blue-collarmarriedsecondary298yesnan
28adminsinglesecondary2831yesnan
39techniciansinglesecondary15yescellular
32blue-collarmarriedprimary131yesnan
59managementmarriedtertiary5314nocellular
27techniciansinglesecondary155yescellular
47blue-collarmarriedprimary259nocellular

Table 1: Banking Data

Based on the above data, answer the given subquestions.

Which of the following options can be used to compute the median of the Balance column for each category in the Marital feature?

Select all that apply.

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

Correct answers

  • A
  • D

Question 15

+1 markNumerical answer

Consider the given Table 1: Banking data for the given subquestions stored as pandas dataframe in variable df

python
>>> import pandas as pd
>>> df = pd.read_csv('dataset.csv')
>>> print(df)
AgeJobMaritalEducationBalanceHousingContact
21unemployedmarriedsecondary77387notelephone
49managementmarriedtertiary2037nonan
72self-employedmarriedtertiary132nocellular
31blue-collarmarriedsecondary298yesnan
28adminsinglesecondary2831yesnan
39techniciansinglesecondary15yescellular
32blue-collarmarriedprimary131yesnan
59managementmarriedtertiary5314nocellular
27techniciansinglesecondary155yescellular
47blue-collarmarriedprimary259nocellular

Table 1: Banking Data

Based on the above data, answer the given subquestions.

Show answer

Correct answer: 35.5

Question 16

+1 markOne correct option

Consider the given Table 1: Banking data for the given subquestions stored as pandas dataframe in variable df

python
>>> import pandas as pd
>>> df = pd.read_csv('dataset.csv')
>>> print(df)
AgeJobMaritalEducationBalanceHousingContact
21unemployedmarriedsecondary77387notelephone
49managementmarriedtertiary2037nonan
72self-employedmarriedtertiary132nocellular
31blue-collarmarriedsecondary298yesnan
28adminsinglesecondary2831yesnan
39techniciansinglesecondary15yescellular
32blue-collarmarriedprimary131yesnan
59managementmarriedtertiary5314nocellular
27techniciansinglesecondary155yescellular
47blue-collarmarriedprimary259nocellular

Table 1: Banking Data

Based on the above data, answer the given subquestions.

  1. A

    secondary

  2. B

    329

  3. C

    2859

  4. D

    Error: Datatype not matching

Show answer

Correct answer

  • C

    2859

Question 17

+2 marksOne correct option

Consider the Following codeblock for the given subquestions.

python
import pandas as pd
import numpy as np
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.compose import ColumnTransformer
data = {"fruits": ['apple','orange', 'banana', 'orange', 'apple'],
"price": [10,20,5,20,10],
'color': ['red', 'orange', 'yellow', 'orange', 'red']}
df = pd.DataFrame(data)
transformers = [
('Ohe', OneHotEncoder(), [0,2]),
('scaler', StandardScaler(), [1])
]
ct = ColumnTransformer(transformers = transformers)
transformed_df = ct.fit_transform(df)

Based on the above data, answer the given subquestions.

  1. A

    (7,5)

  2. B

    (3,5)

  3. C

    (5,3)

  4. D

    (5,7)

Show answer

Correct answer

  • D

    (5,7)

Question 18

+1 markNumerical answer

Consider the Following codeblock for the given subquestions.

python
import pandas as pd
import numpy as np
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.compose import ColumnTransformer
data = {"fruits": ['apple','orange', 'banana', 'orange', 'apple'],
"price": [10,20,5,20,10],
'color': ['red', 'orange', 'yellow', 'orange', 'red']}
df = pd.DataFrame(data)
transformers = [
('Ohe', OneHotEncoder(), [0,2]),
('scaler', StandardScaler(), [1])
]
ct = ColumnTransformer(transformers = transformers)
transformed_df = ct.fit_transform(df)

Based on the above data, answer the given subquestions.

Show answer

Correct answer: 13

Question 19

+2 marksNumerical answer

Consider the Following codeblock for the given subquestions.

python
import pandas as pd
import numpy as np
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.compose import ColumnTransformer
data = {"fruits": ['apple','orange', 'banana', 'orange', 'apple'],
"price": [10,20,5,20,10],
'color': ['red', 'orange', 'yellow', 'orange', 'red']}
df = pd.DataFrame(data)
transformers = [
('Ohe', OneHotEncoder(), [0,2]),
('scaler', StandardScaler(), [1])
]
ct = ColumnTransformer(transformers = transformers)
transformed_df = ct.fit_transform(df)

Based on the above data, answer the given subquestions.

Show answer

Correct answer: 36

Question 20

+2 marksOne correct option

Consider the Following codeblock for the given subquestions.

python
import pandas as pd
import numpy as np
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.compose import ColumnTransformer
data = {"fruits": ['apple','orange', 'banana', 'orange', 'apple'],
"price": [10,20,5,20,10],
'color': ['red', 'orange', 'yellow', 'orange', 'red']}
df = pd.DataFrame(data)
transformers = [
('Ohe', OneHotEncoder(), [0,2]),
('scaler', StandardScaler(), [1])
]
ct = ColumnTransformer(transformers = transformers)
transformed_df = ct.fit_transform(df)

Based on the above data, answer the given subquestions.

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

Correct answer

  • D