uiz Space

May 2023 term · Machine Learning Practice · BSCS2008

Machine Learning Practice Quiz 1: 16 July 2023 (May 2023 term)

The IIT Madras BS Machine Learning Practice (MLP) Quiz 1 paper sat on 16 Jul 2023, in the May 2023 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
MSQ
8
MCQ
16

Updated

Official paper: IIT M DIPLOMA AN2 EXAM QPD2 16 JULY 2023 · No negative marking.

Question 1

+2 marksOne or more correct options

Which of the following things can be observed from a Histogram ?

Select all that apply.

  1. A

    The range of scale of a numerical feature in the data

  2. B

    The distribution of a numerical feature in the data

  3. C

    The null values present in a feature of the data

  4. D

    The correlation between features and labels in the data

Show answer

Correct answers

  • A

    The range of scale of a numerical feature in the data

  • B

    The distribution of a numerical feature in the data

Question 2

+2 marksOne or more correct options

Which of the following are use cases of ColumnTransformer?

Select all that apply.

  1. A

    Data has some numerical and some categorical features.

  2. B

    Data has only categorical features and all of them are nominal.

  3. C

    Data has only categorical features, however, some features are ordinal and some are nominal.

  4. D

    Data has only numerical features, and all of them are uniformly distributed in range of 0 and 1 (both inclusive).

Show answer

Correct answers

  • A

    Data has some numerical and some categorical features.

  • C

    Data has only categorical features, however, some features are ordinal and some are nominal.

Question 3

+2 marksOne or more correct options

Consider a regression dataset, the features are "Temperature" and "Humidity", and the label is "Precipitation" (i.e. rain fall in centimeter), both the features are numerical and there are no missing values in the dataset. Following code snippet trains a simple model on this dataset, assume necessary imports:

python
data = pd.read_csv('dataset.csv')
X = data[data.columns[:-1]]
y = data[data.columns[-1]]
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size = 0.8)
mms = MinMaxScaler()
X_train['Temperature'] = mms.fit_transform(X_train['Temperature'])
X_train['Humidity'] = mms.fit_transform(X_train['Humidity'])
X_test['Temperature'] = mms.fit_transform(X_test['Temperature'])
X_test['Humidity'] = mms.fit_transform(X_test['Humidity'])
lr = LinearRegression().fit(X_train,y_train)

Choose the correct statements from the options:

Select all that apply.

  1. A

    The training set will have 20% of the data, which is a good practice.

  2. B

    The training set size is smaller than test set size.

  3. C

    The train and test samples are not scaled appropriately.

  4. D

    One of the fundamental assumption of Machine Learning, which is, training and test data belong to same distribution, is not upheld.

Show answer

Correct answers

  • B

    The training set size is smaller than test set size.

  • C

    The train and test samples are not scaled appropriately.

  • D

    One of the fundamental assumption of Machine Learning, which is, training and test data belong to same distribution, is not upheld.

Question 4

+2 marksOne or more correct options

Which of the following options is/are correct?

Select all that apply.

  1. A

    If the data contains many outliers, scaling using the mean and variance of the data is likely to not work very well.

  2. B

    RFE first removes a few features which are not important and then fits and removes again and fits. It repeats this iteration until it reaches a suitable number of features.

  3. C

    A pipeline cannot have any feature selection steps.

  4. D

    If you will execute model.fit() for a second time, it will start training again using passed data and will remove the existing results.

Show answer

Correct answers

  • A

    If the data contains many outliers, scaling using the mean and variance of the data is likely to not work very well.

  • B

    RFE first removes a few features which are not important and then fits and removes again and fits. It repeats this iteration until it reaches a suitable number of features.

  • D

    If you will execute model.fit() for a second time, it will start training again using passed data and will remove the existing results.

Question 5

+2 marksOne or more correct options

Select all that apply.

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

Correct answers

  • B
  • D

Question 6

+2 marksOne correct option

For the below code which option will provide the samples(rows) containing outliers according to the standard Boxplot in the weight feature ?

python
dataset = {
"height" : [100,103,102,102,176,150,143,133,122,200,230,222,143],
"weight" : [30,32,33,34,33,33,37,48,44,51,100,123,111]
}
data = pd.DataFrame(dataset, columns=['height','weight'])
q1 = data['weight'].quantile(0.25)
q3 = data['weight'].quantile(0.75)
iqr = q3-q1
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 7

+2 marksOne correct option

What will be the output of the following code snippet ?

python
import pandas as pd
import numpy as np
from sklearn.preprocessing import OneHotEncoder
data = {"fruits": ['apple','orange', 'banana', 'orange', 'apple'],
"price": [10,20,5,20,10]}
df = pd.DataFrame(data)
ohe = OneHotEncoder()
print(ohe.fit_transform(df[['fruits']]).toarray())
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 8

+2 marksOne correct option

What will be the output of the following code ?

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)
print(transformed_df.shape)
  1. A

    (7,5)

  2. B

    (3,5)

  3. C

    (5,3)

  4. D

    (5,7)

Show answer

Correct answer

  • D

    (5,7)

Question 9

+2 marksOne correct option

Which of the following is(are) true statements?
Statement 1: A dataset is splitted into the train set and the test set to obtain the better performance for the unseen data
statement 2 : We should not use the learning, observations and information gained from the test set while training the model

  1. A

    Statement 1 is True and statement 2 is False

  2. B

    Statement 1 is False and statement 2 is True

  3. C

    Statement 1 and statement 2 both are True

  4. D

    Both the statements are False

Show answer

Correct answer

  • C

    Statement 1 and statement 2 both are True

Question 10

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

Correct answer

  • A

Question 11

+2 marksOne correct option

Consider the following code:

python
from sklearn.datasets import make_regression
from sklearn.datasets import make_classification
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import LogisticRegression
X_r, y_r = make_regression()
lr = LinearRegression()
lr.fit(X_r, y_r)
score1 = lr.score(X_r, y_r)
X_c, y_c = make_classification()
logr = LogisticRegression()
logr.fit(X_c, y_c)
score2 = logr.score(X_c, y_c)
print(score1)
print(score2)

Which metrics will be contained in score1 and score2 respectively?

  1. A

    Accuracy, Accuracy

  2. B

    R2 score, R2 score

  3. C

    Accuracy, R2 score

  4. D

    R2 score, Accuracy

  5. E

    F1 score, Precision

  6. F

    Precision, Recall

  7. G

    MAE, MSE

  8. H

    The code will result in an error

Show answer

Correct answer

  • D

    R2 score, Accuracy

Question 12

+2 marksOne correct option

Suppose you have a trained stochastic gradient regressor model by enabling warm start parameter. What happens if you call the fit method again with the same model instance and different training data?

python
from sklearn.linear_model import SGDRegressor
model = SGDRegressor(warm_start=True)
X_train = [[0, 0], [1, 1]]
y_train = [0, 1]
model.fit(X_train, y_train)
# Call fit() again with different training data
X_train_new = [[2, 2], [3, 3]]
y_train_new = [2, 3]
model.fit(X_train_new, y_train_new)
  1. A

    The new training data is ignored, and the model continues training from the previously learned weights.

  2. B

    The new training data is used to update the model weights, but the previous weights are discarded.

  3. C

    An error is raised, indicating that the model has already been trained.

  4. D

    The model weights are reset, and the model begins training again from scratch.

Show answer

Correct answer

  • B

    The new training data is used to update the model weights, but the previous weights are discarded.

Question 13

+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
model = SGDRegressor()
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2,
random_state=42)
model.fit(X_train, y_train, early_stopping=True, validation_data=(X_val,
y_val), validation_fraction=0.2, tol=0.001, n_iter_no_change=5)
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 14

+2 marksOne correct option
  1. A

    (8,4)

  2. B

    (8,5)

  3. C

    (8,8)

  4. D

    (8,10)

Show answer

Correct answer

  • C

    (8,8)

Question 15

+2 marksOne correct option

How many models with different combinations of parameter values will get trained in the following code?

python
from sklearn.model_selection import GridSearchCV
from sklearn.linear_model import SGDRegressor
params = [
{'alpha': [0.001,0.01,0.1,1],'learning_rate': ['constant','optimal']},
{'warm_start':[True], 'alpha':
[0.0001,0.001],'learning_rate':['constant','invscaling']}]
grid= GridSearchCV(estimator= SGDRegressor(),
param_grid = params,
cv= 2,
scoring = 'neg_mean_squared_error',
return_train_score=True
)
grid.fit(X_train,y_train)
  1. A

    10

  2. B

    12

  3. C

    14

  4. D

    16

Show answer

Correct answer

  • B

    12

Question 16

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

Correct answer

  • C

Question 17

+2 marksOne correct option

To see the distribution of the data along each numerical feature which of the following codes will show all the histograms?
• Variable name df contains all the data as pandas.core.frame.DataFrame type
• Assume all the necessary imports are made

  1. A

    df.hist()

  2. B

    df.histplot()

  3. C

    pandas.hist(df)

  4. D

    seaborn.histogram(df)

Show answer

Correct answer

  • A

    df.hist()

Question 18

+2 marksOne correct option

Which of the following can affect performance of the Simple linear Regression while training the model?

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

Correct answer

  • A

Question 19

+3 marksOne or more correct options

Select all that apply.

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

Correct answers

  • A
  • C
  • E
  • F
  • H

Question 20

+3 marksOne or more correct options

Consider the following code block:

python
from sklearn.linear_model import linear_regression
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import ShuffleSplit
lin_reg = linear_regression()
shuffle_split = ShuffleSplit(n_splits=5, test_size=0.2, random_state=42)
score = cross_val_score(lin_reg, X, y, cv=shuffle_split,
scoring='-----------------------')

Which of the following may be appropriate to be filled in the blank space?

Select all that apply.

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

Correct answers

  • B
  • C

Question 21

+1 markOne or more correct options

Which of the following are correct statements?

Select all that apply.

  1. A

    Data with missing values can not be used to train a logistic or linear regression model.

  2. B

    KNN model is agnostic to scale of numerical features.

  3. C

    Like KNN imputer, other models e.g. decision tree, can also be used for imputation.

  4. D

    Filling 0 (zero) in place of missing values, is always the best approach for imputation.

Show answer

Correct answers

  • A

    Data with missing values can not be used to train a logistic or linear regression model.

  • C

    Like KNN imputer, other models e.g. decision tree, can also be used for imputation.

Question 22

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

Correct answer

  • C

Question 23

+3 marksOne correct option

Consider the following code:

python
import numpy as np
from sklearn.model_selection import ShuffleSplit
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [1, 3], [2, 3], [3, 3], [4, 3]])
y = np.array([0, 1, 0, 1, 1, 0, 1, 0])
rs = ShuffleSplit(n_splits=5, test_size=.25, random_state=0)
for each in rs.split(X):
print(each[0], each[1])

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

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

Correct answer

  • A

Question 24

+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

    s1 = s2

  2. B

    s1 < s2

  3. C

    s1 > s2

Show answer

Correct answer

  • B

    s1 < s2