uiz Space

January 2024 term · Machine Learning Practice · BSCS2008

Machine Learning Practice Quiz 1: 25 February 2024 (January 2024 term)

The IIT Madras BS Machine Learning Practice (MLP) Quiz 1 paper sat on 25 Feb 2024, in the January 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
MCQ
16
MSQ
7
Numerical
1

Updated

Official paper: IIT M DIPLOMA AN2 EXAM QDD2 25 Feb 2024 · No negative marking.

Question 1

+2 marksOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('titanic.csv')
>>> print(df)
sexagesibspparchfareclassembark_townalivealone
0male22.0107.2500ThirdSouthamptonnoFalse
1female38.01071.2833FirstCherbourgyesFalse
2female26.0007.9250ThirdSouthamptonyesTrue
3female35.01053.1000FirstSouthamptonyesFalse
4male35.0008.0500ThirdSouthamptonnoTrue
5maleNaN008.4583ThirdQueenstownnoTrue
6male54.00051.8625FirstSouthamptonnoTrue
7male2.03121.0750ThirdSouthamptonnoFalse
8female27.00211.1333ThirdSouthamptonyesFalse
9female14.01030.0708SecondCherbourgyesFalse
10female4.01116.7000ThirdSouthamptonyesFalse
11female58.00026.5500FirstSouthamptonyesTrue
12male20.0008.0500ThirdSouthamptonnoTrue
13male39.01531.2750ThirdSouthamptonnoFalse
14female14.0007.8542ThirdSouthamptonnoTrue
15female55.00016.0000SecondSouthamptonyesTrue

Based on the above data, answer the given subquestions.

Choose the correct options to determine the count of NULL values in each column of a pandas DataFrame named ’df’

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

Correct answer

  • A

Question 2

+2 marksOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('titanic.csv')
>>> print(df)
sexagesibspparchfareclassembark_townalivealone
0male22.0107.2500ThirdSouthamptonnoFalse
1female38.01071.2833FirstCherbourgyesFalse
2female26.0007.9250ThirdSouthamptonyesTrue
3female35.01053.1000FirstSouthamptonyesFalse
4male35.0008.0500ThirdSouthamptonnoTrue
5maleNaN008.4583ThirdQueenstownnoTrue
6male54.00051.8625FirstSouthamptonnoTrue
7male2.03121.0750ThirdSouthamptonnoFalse
8female27.00211.1333ThirdSouthamptonyesFalse
9female14.01030.0708SecondCherbourgyesFalse
10female4.01116.7000ThirdSouthamptonyesFalse
11female58.00026.5500FirstSouthamptonyesTrue
12male20.0008.0500ThirdSouthamptonnoTrue
13male39.01531.2750ThirdSouthamptonnoFalse
14female14.0007.8542ThirdSouthamptonnoTrue
15female55.00016.0000SecondSouthamptonyesTrue

Based on the above data, answer the given subquestions.

Which option will help in selecting data of odd indexed columns only? (ie. age, parch are odd indexed 1 and 3 respectively)

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

Correct answer

  • B

Question 3

+2 marksOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('titanic.csv')
>>> print(df)
sexagesibspparchfareclassembark_townalivealone
0male22.0107.2500ThirdSouthamptonnoFalse
1female38.01071.2833FirstCherbourgyesFalse
2female26.0007.9250ThirdSouthamptonyesTrue
3female35.01053.1000FirstSouthamptonyesFalse
4male35.0008.0500ThirdSouthamptonnoTrue
5maleNaN008.4583ThirdQueenstownnoTrue
6male54.00051.8625FirstSouthamptonnoTrue
7male2.03121.0750ThirdSouthamptonnoFalse
8female27.00211.1333ThirdSouthamptonyesFalse
9female14.01030.0708SecondCherbourgyesFalse
10female4.01116.7000ThirdSouthamptonyesFalse
11female58.00026.5500FirstSouthamptonyesTrue
12male20.0008.0500ThirdSouthamptonnoTrue
13male39.01531.2750ThirdSouthamptonnoFalse
14female14.0007.8542ThirdSouthamptonnoTrue
15female55.00016.0000SecondSouthamptonyesTrue

Based on the above data, answer the given subquestions.

What is datatype of sex column in the given titanic dataset

  1. A

    number

  2. B

    bool

  3. C

    str

  4. D

    object

Show answer

Correct answer

  • D

    object

Question 4

+2 marksOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('titanic.csv')
>>> print(df)
sexagesibspparchfareclassembark_townalivealone
0male22.0107.2500ThirdSouthamptonnoFalse
1female38.01071.2833FirstCherbourgyesFalse
2female26.0007.9250ThirdSouthamptonyesTrue
3female35.01053.1000FirstSouthamptonyesFalse
4male35.0008.0500ThirdSouthamptonnoTrue
5maleNaN008.4583ThirdQueenstownnoTrue
6male54.00051.8625FirstSouthamptonnoTrue
7male2.03121.0750ThirdSouthamptonnoFalse
8female27.00211.1333ThirdSouthamptonyesFalse
9female14.01030.0708SecondCherbourgyesFalse
10female4.01116.7000ThirdSouthamptonyesFalse
11female58.00026.5500FirstSouthamptonyesTrue
12male20.0008.0500ThirdSouthamptonnoTrue
13male39.01531.2750ThirdSouthamptonnoFalse
14female14.0007.8542ThirdSouthamptonnoTrue
15female55.00016.0000SecondSouthamptonyesTrue

Based on the above data, answer the given subquestions.

Which option will help in filtering data to find females who are alive after titanic incident?

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

Correct answer

  • A

Question 5

+2 marksOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('titanic.csv')
>>> print(df)
sexagesibspparchfareclassembark_townalivealone
0male22.0107.2500ThirdSouthamptonnoFalse
1female38.01071.2833FirstCherbourgyesFalse
2female26.0007.9250ThirdSouthamptonyesTrue
3female35.01053.1000FirstSouthamptonyesFalse
4male35.0008.0500ThirdSouthamptonnoTrue
5maleNaN008.4583ThirdQueenstownnoTrue
6male54.00051.8625FirstSouthamptonnoTrue
7male2.03121.0750ThirdSouthamptonnoFalse
8female27.00211.1333ThirdSouthamptonyesFalse
9female14.01030.0708SecondCherbourgyesFalse
10female4.01116.7000ThirdSouthamptonyesFalse
11female58.00026.5500FirstSouthamptonyesTrue
12male20.0008.0500ThirdSouthamptonnoTrue
13male39.01531.2750ThirdSouthamptonnoFalse
14female14.0007.8542ThirdSouthamptonnoTrue
15female55.00016.0000SecondSouthamptonyesTrue

Based on the above data, answer the given subquestions.

What is the given code below trying to accomplish for the given titanic dataset ?

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

Correct answer

  • C

Question 6

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

Correct answer

  • C

Question 7

+2 marksOne correct option

You are working on a machine learning project that aims to predict housing prices based on various features of the houses. As the first step, you decide to perform exploratory data analysis and visualize the data to understand its structure and relationships. Which of the following visualization techniques or principles is LEAST likely to provide meaningful insights for this kind of regression problem?

  1. A

    Plotting a heatmap of the correlation matrix to understand the linear relationship between the numeric features.

  2. B

    Using a scatter plot to visualize the relationship between the square footage of a house and its price.

  3. C

    Visualizing the distribution of housing prices using a pie chart.

  4. D

    Creating box plots for housing prices, grouped by the number of bedrooms, to detect outliers and understand the distribution across different categories.

Show answer

Correct answer

  • C

    Visualizing the distribution of housing prices using a pie chart.

Question 8

+2 marksOne correct option

A company collects 40000 samples (examples) to build a Machine Learning model for an application. They decide to use 30% of the total samples for testing (to be stored in the variable testset) and the rest 70% for training (to be stored in the variable trainset). They also want to sample the same set of samples across multiple runs. Which of the following line (statement) achieves this task? Assume that all samples are stored in the variable data.

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

Correct answer

  • C

Question 9

+2 marksOne correct option

Choose the option based on the following statements:
Statement 1: The train-test split allows us to simulate the model’s performance on new data by reserving a portion of the dataset for testing.
Statement 2: Separating the dataset into training and testing sets helps prevent data leakage, where information from the test set unintentionally influences the model during training. This ensures a fair assessment of the model’s generalization capabilities.

  1. A

    Statement 1 is True and statement 2 is False

  2. B

    Statement 1 is False and statement 2 is True

  3. C

    Both the statements are False

  4. D

    Both the statements are True

Show answer

Correct answer

  • D

    Both the statements are True

Question 10

+2 marksOne correct option

In which of the following scenarios is data cleaning most required?

  1. A

    Data has missing values and categorical string data.

  2. B

    Data consists a lot of outliers based on values in target(y) column

  3. C

    The data consists solely of numerical values and are on a similar scale.

  4. D

    None of the choices

Show answer

Correct answer

  • A

    Data has missing values and categorical string data.

Question 11

+2 marksOne correct option

Consider the below code:

python
data = [[-3, 1],
[-3, 1],
[ 3, 5],
[ 3, 5]]
from sklearn.preprocessing import StandardScaler
ss = StandardScaler()
print(ss.fit_transform(data))

What will be the output of the code snippet given above?

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

Correct answer

  • D

Question 12

+2 marksOne correct option

Which of the following metrics indicate higher their value, better the regression model’s performance?

  1. A

    RMSE

  2. B

    R2

  3. C

    Mean absolute error

  4. D

    Mean squared error

Show answer

Correct answer

  • B

    R2

Question 13

+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
from sklearn.datasets import load_diabetes
X, y = load_diabetes(return_X_y=True)
params = [
{'alpha': [0.01,0.1,1],'learning_rate': ['constant','optimal']},
{'loss' : ['squared_error', 'huber'], 'alpha':
↪ [0.0001,0.001],'learning_rate':['constant','invscaling']}]
grid= GridSearchCV(estimator= SGDRegressor(),
param_grid = params,
scoring = 'neg_mean_squared_error',
return_train_score=True,
verbose = 2,
n_jobs= -1
)
grid.fit(X,y)
  1. A

    10

  2. B

    12

  3. C

    14

  4. D

    16

Show answer

Correct answer

  • C

    14

Question 14

+2 marksOne correct option
  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 15

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

+3 marksOne correct option

Consider following dataset:

HouseAgeAveRoomsPopulationCityIncomeGroup
41.06.98322.0DelhiLow
21.06.232401.0KolkataHigh
52.08.28496.0AgraMedium
52.0-558.0KolkataMedium
52.06.28565.0MumbaiMedium

Which one of the following code snippets will correctly preprocess above data? Assume necessary imports. The data is stored in a dataframe named X.

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

Correct answer

  • A

Question 17

+2 marksOne or more correct options

Suppose that we plot the histogram of numerical features in a data set. This reveals which of the following information?

Select all that apply.

  1. A

    Scale of the features

  2. B

    (left or right) Skew of the distribution

  3. C

    Modes in the distribution

  4. D

    Missing values

Show answer

Correct answers

  • A

    Scale of the features

  • B

    (left or right) Skew of the distribution

  • C

    Modes in the distribution

Question 18

+2 marksOne or more correct options

Select all that apply.

  1. A

    house.data.shape will give the count of number of rows and columns for features and labels(target) both

  2. B

    house.target_names will give the name of the target column

  3. C

    house.data.head() will show last 5 rows of the data

  4. D

    house.feature_names will give a list of names of the columns of the feature matrix

Show answer

Correct answers

  • B

    house.target_names will give the name of the target column

  • D

    house.feature_names will give a list of names of the columns of the feature matrix

Question 19

+2 marksOne or more correct options

Which of the following are valid loss functions for SGDClassifier?

Select all that apply.

  1. A

    Squared Loss

  2. B

    Hinge Loss

  3. C

    Log Loss

  4. D

    Mean Absolute Error

Show answer

Correct answers

  • B

    Hinge Loss

  • C

    Log Loss

Question 20

+2 marksOne or more correct options

Which columns will not be included in the selected data within the code below?

python
import numpy as np
from sklearn.feature_selection import VarianceThreshold
data = np.array([[ 95, 0.332, 112, 1, 0.56 ],
[ 146, 0.332, 177, 1, 9.2 ],
[ -96, 0.332, -139, 1, -0.82 ],
[ 116, 0.332, 117, 1, 4.8 ],
[ -87, 0.332, -63, 1, -1.1 ]])
vf = VarianceThreshold(threshold=0)
selected_data = vf.fit_transform(data)
selected_data

Select all that apply.

  1. A

    Column indexed at 0

  2. B

    Column indexed at 1

  3. C

    Column indexed at 2

  4. D

    Column indexed at 3

  5. E

    Column indexed at 4

  6. F

    No columns

Show answer

Correct answers

  • B

    Column indexed at 1

  • D

    Column indexed at 3

Question 21

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

+3 marksOne or more correct options

Consider the below code :

keep following symbols in mind:

  • >>>: Represents input code
  • # : Represents comment in a code
  • ... : Represents code continuation
  • Without any symbols at the beginning of a line then it is output of just above input line of code.
  • arrow pointing towards right is code continuation to another line.
python
>>> from sklearn.feature_selection import SelectKBest, chi2
>>> from sklearn.datasets import load_wine
>>> X,y = load_wine(return_X_y=True,as_frame=True)
>>> print(X.shape)
(178, 13)
>>> print(X.columns)
['alcohol', 'malic_acid', 'ash', 'alcalinity_of_ash', 'magnesium',
'total_phenols', 'flavanoids', 'nonflavanoid_phenols', 'proanthocyanins',
'color_intensity', 'hue', 'od280/od315_of_diluted_wines', 'proline']
>>> skb = SelectKBest(chi2, k=3)
>>> X_selected = skb.fit_transform(X, y)
>>> print(skb.scores_)
[5.44, 28.06, 0.74, 29.38, 45.02, 15.62, 63.33, 1.81,
9.36, 109.01, 5.18, 23.38, 16540.06]
>>> print(skb.pvalues_)
[6.56e-02, 8.03e-07, 0.68, 4.16e-07, 1.66e-10, 4.05e-04,
1.76e-14, 0.40, 9.24e-03, 2.12e-24, 0.074, 8.33e-06, 0]
>>> print(skb.pvalues_.argsort())
[12, 9, 6, 4, 3, 1, 11, 5, 8, 0, 10, 7, 2]

Which of the following feature(s) will be selected in X_selected from X ?

Select all that apply.

  1. A

    malic_acid

  2. B

    magnesium

  3. C

    flavanoids

  4. D

    proanthocyanins

  5. E

    color_intensity

  6. F

    proline

Show answer

Correct answers

  • C

    flavanoids

  • E

    color_intensity

  • F

    proline

Question 23

+3 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 24

+2 marksNumerical answer

What will be the output of the following code ?

python
data = [['apple', 120],
['apple', 125],
['grapes',120]]
from sklearn.preprocessing import OneHotEncoder
ohe = OneHotEncoder(sparse_output=False)
ohe.fit(data)
print(ohe.transform(data).shape[1])
Show answer

Correct answer: 4