uiz Space

May 2024 term · Machine Learning Practice · BSCS2008

Machine Learning Practice Quiz 1: 7 July 2024 (May 2024 term)

The IIT Madras BS Machine Learning Practice (MLP) Quiz 1 paper sat on 7 Jul 2024, in the May 2024 term: 24 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
24
Marks
50
Duration
120 min
Numerical
9
MSQ
7
MCQ
8

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 7 July 2024 · No negative marking.

Question 1

+1 markNumerical answer

Consider following common data and answer the given subquestions:

python
import pandas as pd
import numpy as np
columns = ["Name", "Manufacturer", "Year_of_purchase",
"Price_in_lacs","Fuel_type"]
data = [["800 AC", "Maruti", 2007, 0.6, "Petrol", ],
["Wagon R", "Maruti", 2007, 1.35, "Petrol", ],
["Verna", "Hyundai", 2012, 6.0, "Diesel", ],
["Corolla", "Toyota", 2018, 16.5, "Petrol", ],
["Amaze", "Honda", 2014, 4.5, "Diesel", ],
["Alto", "Maruti", 2007, 1.4, "Petrol", ],]
df = pd.DataFrame(data=data, columns=columns)

What will be the output of the following code snippet?

Enter -1, if you think the above code snippet will generate an error.

Show answer

Correct answer: 11

Question 2

+1 markNumerical answer

Consider following common data and answer the given subquestions:

python
import pandas as pd
import numpy as np
columns = ["Name", "Manufacturer", "Year_of_purchase",
"Price_in_lacs","Fuel_type"]
data = [["800 AC", "Maruti", 2007, 0.6, "Petrol", ],
["Wagon R", "Maruti", 2007, 1.35, "Petrol", ],
["Verna", "Hyundai", 2012, 6.0, "Diesel", ],
["Corolla", "Toyota", 2018, 16.5, "Petrol", ],
["Amaze", "Honda", 2014, 4.5, "Diesel", ],
["Alto", "Maruti", 2007, 1.4, "Petrol", ],]
df = pd.DataFrame(data=data, columns=columns)

What will be the output of the following code snippet?

Enter -1, if you think the above code snippet will generate an error.

Show answer

Correct answer: 3

Question 3

+2 marksNumerical answer

Consider following common data and answer the given subquestions:

python
import pandas as pd
import numpy as np
columns = ["Name", "Manufacturer", "Year_of_purchase",
"Price_in_lacs","Fuel_type"]
data = [["800 AC", "Maruti", 2007, 0.6, "Petrol", ],
["Wagon R", "Maruti", 2007, 1.35, "Petrol", ],
["Verna", "Hyundai", 2012, 6.0, "Diesel", ],
["Corolla", "Toyota", 2018, 16.5, "Petrol", ],
["Amaze", "Honda", 2014, 4.5, "Diesel", ],
["Alto", "Maruti", 2007, 1.4, "Petrol", ],]
df = pd.DataFrame(data=data, columns=columns)

What will be the output of the following code snippet?

Enter -1, if you think the above code snippet will generate an error.

Show answer

Correct answer: 2

Question 4

+2 marksNumerical answer

Consider following common data and answer the given subquestions:

python
import pandas as pd
import numpy as np
columns = ["Name", "Manufacturer", "Year_of_purchase",
"Price_in_lacs","Fuel_type"]
data = [["800 AC", "Maruti", 2007, 0.6, "Petrol", ],
["Wagon R", "Maruti", 2007, 1.35, "Petrol", ],
["Verna", "Hyundai", 2012, 6.0, "Diesel", ],
["Corolla", "Toyota", 2018, 16.5, "Petrol", ],
["Amaze", "Honda", 2014, 4.5, "Diesel", ],
["Alto", "Maruti", 2007, 1.4, "Petrol", ],]
df = pd.DataFrame(data=data, columns=columns)

What will be the output of the following code snippet?

Enter -1, if you think the above code snippet will generate an error.

Show answer

Correct answer: 2

Question 5

+2 marksOne or more correct options

Consider following common data and answer the given subquestions:

python
import pandas as pd
import numpy as np
columns = ["Name", "Manufacturer", "Year_of_purchase",
"Price_in_lacs","Fuel_type"]
data = [["800 AC", "Maruti", 2007, 0.6, "Petrol", ],
["Wagon R", "Maruti", 2007, 1.35, "Petrol", ],
["Verna", "Hyundai", 2012, 6.0, "Diesel", ],
["Corolla", "Toyota", 2018, 16.5, "Petrol", ],
["Amaze", "Honda", 2014, 4.5, "Diesel", ],
["Alto", "Maruti", 2007, 1.4, "Petrol", ],]
df = pd.DataFrame(data=data, columns=columns)

Given the data, which of the following options will provide the same output?

Select all that apply.

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

Correct answers

  • A
  • B
  • C
  • D
  • E

Question 6

+2 marksOne or more correct options

Consider following common data and answer the given subquestions:

python
import pandas as pd
import numpy as np
columns = ["Name", "Manufacturer", "Year_of_purchase",
"Price_in_lacs","Fuel_type"]
data = [["800 AC", "Maruti", 2007, 0.6, "Petrol", ],
["Wagon R", "Maruti", 2007, 1.35, "Petrol", ],
["Verna", "Hyundai", 2012, 6.0, "Diesel", ],
["Corolla", "Toyota", 2018, 16.5, "Petrol", ],
["Amaze", "Honda", 2014, 4.5, "Diesel", ],
["Alto", "Maruti", 2007, 1.4, "Petrol", ],]
df = pd.DataFrame(data=data, columns=columns)

If you would like to see the most frequent car manufacturers in the dataset, which of the following can be used?

Select all that apply.

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

Correct answers

  • A
  • B

Question 7

+2 marksOne or more correct options

Which of the following choice(s) are correct ?

Select all that apply.

  1. A

    Null values cannot be interpreted by the model hence we need to handle them accordingly.

  2. B

    Null values cannot be replaced because we can not manipulate the dataset.

  3. C

    We should let the sklearn or software automatically decide how to handle different kinds of missing values.

  4. D

    Different types of representation of missing values could be seen in the dataset.

Show answer

Correct answers

  • A

    Null values cannot be interpreted by the model hence we need to handle them accordingly.

  • D

    Different types of representation of missing values could be seen in the dataset.

Question 8

+2 marksOne or more correct options

Which of the following options are true about Pearson correlation matrix ?

Select all that apply.

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

Correct answers

  • A
  • C

Question 9

+3 marksOne or more correct options

Select all that apply.

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

Correct answers

  • B
  • D

Question 10

+2 marksOne correct option

We need to preprocess the data before using it for model building due to which of the following reasons ?

  1. A

    Due to errors in data capture, data may contain outliers or missing values.

  2. B

    Different features may be at different scales.

  3. C

    Data contains non numerical features.

  4. D

    All of these

Show answer

Correct answer

  • D

    All of these

Question 11

+3 marksOne correct option

Consider following data and answer the given subquestions:

Each row represents a data point. There are exactly 4 points. The index of points starts from 0 and ends at 3 (included).

Which of the following pairs have the highest euclidean distance? Note: take care of the missing values and adjust accordingly. The options refer to the indices of points.

  1. A

    1 and 2

  2. B

    0 and 2

  3. C

    1 and 3

  4. D

    2 and 3

  5. E

    0 and 1

  6. F

    There is a tie between two or more options.

  7. G

    None of these.

Show answer

Correct answer

  • E

    0 and 1

Question 12

+2 marksOne correct option

Consider following data and answer the given subquestions:

Each row represents a data point. There are exactly 4 points. The index of points starts from 0 and ends at 3 (included).

Which of the following pairs have the smallest euclidean distance? Note: take care of the missing values and adjust accordingly. The options refer to the indices of points.

  1. A

    1 and 2

  2. B

    0 and 2

  3. C

    1 and 3

  4. D

    2 and 3

  5. E

    0 and 1

  6. F

    There is a tie between two or more options.

  7. G

    None of these.

Show answer

Correct answer

  • B

    0 and 2

Question 13

+2 marksNumerical answer

Consider following data and code snippet:

python
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import MinMaxScaler, OrdinalEncoder, MaxAbsScaler
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline
X = np.array([[5, 4, 'cat'],
[4, -1, 'dog'],
[3, 1, 'bird'],
[np.nan, 3, 'cat']])
impute_scale_pipe = Pipeline([('impute', SimpleImputer()),
('scale', MinMaxScaler())])
ct = ColumnTransformer([('impute_scale', impute_scale_pipe, [0,1]),
('scale_only', MaxAbsScaler(), [1]),
('categorical', OrdinalEncoder(), [2])])
transformed_X = ct.fit_transform(X)

Based on the above data, answer the given subquestions.

What will be the output of the following code snippet:

Enter -1, if you think the above code snippet will generate an error.

Show answer

Correct answer: 4

Question 14

+2 marksNumerical answer

Consider following data and code snippet:

python
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import MinMaxScaler, OrdinalEncoder, MaxAbsScaler
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline
X = np.array([[5, 4, 'cat'],
[4, -1, 'dog'],
[3, 1, 'bird'],
[np.nan, 3, 'cat']])
impute_scale_pipe = Pipeline([('impute', SimpleImputer()),
('scale', MinMaxScaler())])
ct = ColumnTransformer([('impute_scale', impute_scale_pipe, [0,1]),
('scale_only', MaxAbsScaler(), [1]),
('categorical', OrdinalEncoder(), [2])])
transformed_X = ct.fit_transform(X)

Based on the above data, answer the given subquestions.

What will be the output of the following code snippet:

Enter -1, if you think the above code snippet will generate an error.

Show answer

Correct answer: 0.5

Question 15

+2 marksNumerical answer

Consider following data and code snippet:

python
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import MinMaxScaler, OrdinalEncoder, MaxAbsScaler
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline
X = np.array([[5, 4, 'cat'],
[4, -1, 'dog'],
[3, 1, 'bird'],
[np.nan, 3, 'cat']])
impute_scale_pipe = Pipeline([('impute', SimpleImputer()),
('scale', MinMaxScaler())])
ct = ColumnTransformer([('impute_scale', impute_scale_pipe, [0,1]),
('scale_only', MaxAbsScaler(), [1]),
('categorical', OrdinalEncoder(), [2])])
transformed_X = ct.fit_transform(X)

Based on the above data, answer the given subquestions.

What will be the output of the following code snippet:

Enter -1, if you think the above code snippet will generate an error.

Show answer

Correct answer: 1.0

Question 16

+2 marksNumerical answer

Consider following data and code snippet:

python
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import MinMaxScaler, OrdinalEncoder, MaxAbsScaler
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline
X = np.array([[5, 4, 'cat'],
[4, -1, 'dog'],
[3, 1, 'bird'],
[np.nan, 3, 'cat']])
impute_scale_pipe = Pipeline([('impute', SimpleImputer()),
('scale', MinMaxScaler())])
ct = ColumnTransformer([('impute_scale', impute_scale_pipe, [0,1]),
('scale_only', MaxAbsScaler(), [1]),
('categorical', OrdinalEncoder(), [2])])
transformed_X = ct.fit_transform(X)

Based on the above data, answer the given subquestions.

What will be the output of the following code snippet:

Enter -1, if you think the above code snippet will generate an error.

Show answer

Correct answer: 0.4

Question 17

+2 marksOne or more correct options

Consider following data and code snippet:

python
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import MinMaxScaler, OrdinalEncoder, MaxAbsScaler
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline
X = np.array([[5, 4, 'cat'],
[4, -1, 'dog'],
[3, 1, 'bird'],
[np.nan, 3, 'cat']])
impute_scale_pipe = Pipeline([('impute', SimpleImputer()),
('scale', MinMaxScaler())])
ct = ColumnTransformer([('impute_scale', impute_scale_pipe, [0,1]),
('scale_only', MaxAbsScaler(), [1]),
('categorical', OrdinalEncoder(), [2])])
transformed_X = ct.fit_transform(X)

Based on the above data, answer the given subquestions.

Which of the following can be used to get the simpleimputer object?

Select all that apply.

  1. A
  2. B
  3. C
  4. D
  5. E
  6. F
  7. G
Show answer

Correct answers

  • B
  • C

Question 18

+2 marksOne correct option

Go through the code snippet given below and answer the given subquestions.

python
import numpy as np
from sklearn.linear_model import SGDRegressor
from sklearn.pipeline import make_pipeline
n_samples, n_features = 18, 4
rng = np.random.RandomState(0)
y = rng.randn(n_samples)
X = rng.randn(n_samples, n_features)
reg = SGDRegressor(max_iter=1000,
tol=1e-3,
eta0= 0.04,
power_t=5,
n_iter_no_change=3,
validation_fraction=0.3 ,
random_state=42)
reg.fit(X, y)
print(reg.coef_)

Which of the following options will be the output of the given code?

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

Correct answer

  • A

Question 19

+2 marksOne correct option

Go through the code snippet given below and answer the given subquestions.

python
import numpy as np
from sklearn.linear_model import SGDRegressor
from sklearn.pipeline import make_pipeline
n_samples, n_features = 18, 4
rng = np.random.RandomState(0)
y = rng.randn(n_samples)
X = rng.randn(n_samples, n_features)
reg = SGDRegressor(max_iter=1000,
tol=1e-3,
eta0= 0.04,
power_t=5,
n_iter_no_change=3,
validation_fraction=0.3 ,
random_state=42)
reg.fit(X, y)
print(reg.coef_)
  1. A

    -0.528

  2. B

    1

  3. C

    0.528

  4. D

    Given code will return an error

Show answer

Correct answer

  • D

    Given code will return an error

Question 20

+3 marksOne correct option

Consider the following code:

Which of the following may be the correct output of the above code?:

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

Correct answer

  • A

Question 21

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

+2 marksNumerical answer

What will be the output of the following code ?

Show answer

Correct answer: 0.78 (accepted within ±0.02)

Question 23

+2 marksOne correct option

What is the purpose of the tol parameter of the SGDRegressor() in the given code below?

python
from sklearn.linear_model import SGDRegressor
model = SGDRegressor(early_stopping=True,
validation_fraction=0.2,
tol=0.001,
n_iter_no_change=5)
model.fit(X, y)
  1. A

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

  2. B

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

  3. C

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

  4. D

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

Show answer

Correct answer

  • D

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

Question 24

+2 marksOne or more correct options

Consider the following code block and if needed make appropriate assumptions:

python
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import ShuffleSplit
shuffle_split = ShuffleSplit(n_splits=5, test_size=0.2, random_state=42)
score = cross_val_score(estimator= LinearRegression(),
X= X_train,
y= y_train,
cv= shuffle_split,
scoring= '____________')

Which of the following may be appropriate to be filled in the blank space value for scoring parameter?

Select all that apply.

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

Correct answers

  • B
  • C