uiz Space

September 2024 term · Machine Learning Practice · BSCS2008

Machine Learning Practice Quiz 1: 27 October 2024 (September 2024 term)

The IIT Madras BS Machine Learning Practice (MLP) Quiz 1 paper sat on 27 Oct 2024, in the September 2024 term: 22 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
22
Marks
50
Duration
120 min
MCQ
16
MSQ
6

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 27 Oct 2024 · No negative marking.

Question 1

+2 marksOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('dataset.csv')
>>> print(df)
FlightIDAirlineFlightNumberOriginDestinationDelayMinutesDelayReasonCancelledDivertedAircraftTypeTailNumberDistance
01United4558ORDMIA8WeatherTrueFalseBoeing 737N710661031
12Delta8021LAXMIA2Air Traffic ControlTrueTrueAirbus A320N226571006
23Southwest7520DFWSFO14WeatherTrueTrueBoeing 737N956112980
34Delta2046ORDBOS-10NaNFalseFalseBoeing 777N900291408
45Delta6049LAXSEA24Air Traffic ControlFalseTrueBoeing 737N274172298
56Southwest6311LAXJFK-5NaNFalseFalseBoeing 777N926521386
67Southwest4188ORDJFK7WeatherFalseTrueBoeing 777N253821674
78Southwest3179DFWMIA24WeatherFalseTrueBoeing 777N654102931
89American Airlines3613ORDMIA2WeatherFalseFalseAirbus A320N455702337
910Southwest2186LAXBOS25MaintenanceTrueFalseBoeing 777N15724605
1011American Airlines9317JFKMIA-6NaNTrueTrueAirbus A320N549052848
1112American Airlines5251DFWBOS30WeatherFalseFalseAirbus A320N94983131

Based on the above data, answer the given subquestions.

Which option will give the total count of canceled flights in the dataset?

  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('dataset.csv')
>>> print(df)
FlightIDAirlineFlightNumberOriginDestinationDelayMinutesDelayReasonCancelledDivertedAircraftTypeTailNumberDistance
01United4558ORDMIA8WeatherTrueFalseBoeing 737N710661031
12Delta8021LAXMIA2Air Traffic ControlTrueTrueAirbus A320N226571006
23Southwest7520DFWSFO14WeatherTrueTrueBoeing 737N956112980
34Delta2046ORDBOS-10NaNFalseFalseBoeing 777N900291408
45Delta6049LAXSEA24Air Traffic ControlFalseTrueBoeing 737N274172298
56Southwest6311LAXJFK-5NaNFalseFalseBoeing 777N926521386
67Southwest4188ORDJFK7WeatherFalseTrueBoeing 777N253821674
78Southwest3179DFWMIA24WeatherFalseTrueBoeing 777N654102931
89American Airlines3613ORDMIA2WeatherFalseFalseAirbus A320N455702337
910Southwest2186LAXBOS25MaintenanceTrueFalseBoeing 777N15724605
1011American Airlines9317JFKMIA-6NaNTrueTrueAirbus A320N549052848
1112American Airlines5251DFWBOS30WeatherFalseFalseAirbus A320N94983131

Based on the above data, answer the given subquestions.

Which of the following code snippets will add a new column ’OnTime’ that shows True if the flight was not delayed, else False?

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

Correct answer

  • A

Question 3

+3 marksOne or more correct options
python
>>> import pandas as pd
>>> df = pd.read_csv('dataset.csv')
>>> print(df)
FlightIDAirlineFlightNumberOriginDestinationDelayMinutesDelayReasonCancelledDivertedAircraftTypeTailNumberDistance
01United4558ORDMIA8WeatherTrueFalseBoeing 737N710661031
12Delta8021LAXMIA2Air Traffic ControlTrueTrueAirbus A320N226571006
23Southwest7520DFWSFO14WeatherTrueTrueBoeing 737N956112980
34Delta2046ORDBOS-10NaNFalseFalseBoeing 777N900291408
45Delta6049LAXSEA24Air Traffic ControlFalseTrueBoeing 737N274172298
56Southwest6311LAXJFK-5NaNFalseFalseBoeing 777N926521386
67Southwest4188ORDJFK7WeatherFalseTrueBoeing 777N253821674
78Southwest3179DFWMIA24WeatherFalseTrueBoeing 777N654102931
89American Airlines3613ORDMIA2WeatherFalseFalseAirbus A320N455702337
910Southwest2186LAXBOS25MaintenanceTrueFalseBoeing 777N15724605
1011American Airlines9317JFKMIA-6NaNTrueTrueAirbus A320N549052848
1112American Airlines5251DFWBOS30WeatherFalseFalseAirbus A320N94983131

Based on the above data, answer the given subquestions.

How can you filter the flights that have a delay due to ’Weather’?

Select all that apply.

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

Correct answers

  • B
  • C

Question 4

+3 marksOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('dataset.csv')
>>> print(df)
FlightIDAirlineFlightNumberOriginDestinationDelayMinutesDelayReasonCancelledDivertedAircraftTypeTailNumberDistance
01United4558ORDMIA8WeatherTrueFalseBoeing 737N710661031
12Delta8021LAXMIA2Air Traffic ControlTrueTrueAirbus A320N226571006
23Southwest7520DFWSFO14WeatherTrueTrueBoeing 737N956112980
34Delta2046ORDBOS-10NaNFalseFalseBoeing 777N900291408
45Delta6049LAXSEA24Air Traffic ControlFalseTrueBoeing 737N274172298
56Southwest6311LAXJFK-5NaNFalseFalseBoeing 777N926521386
67Southwest4188ORDJFK7WeatherFalseTrueBoeing 777N253821674
78Southwest3179DFWMIA24WeatherFalseTrueBoeing 777N654102931
89American Airlines3613ORDMIA2WeatherFalseFalseAirbus A320N455702337
910Southwest2186LAXBOS25MaintenanceTrueFalseBoeing 777N15724605
1011American Airlines9317JFKMIA-6NaNTrueTrueAirbus A320N549052848
1112American Airlines5251DFWBOS30WeatherFalseFalseAirbus A320N94983131

Based on the above data, answer the given subquestions.

Which option will sort the flights first by `Airline` in ascending order, then by DelayMinutes in descending order?

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

Correct answer

  • A

Question 5

+3 marksOne correct option
python
>>> import pandas as pd
>>> df = pd.read_csv('dataset.csv')
>>> print(df)
FlightIDAirlineFlightNumberOriginDestinationDelayMinutesDelayReasonCancelledDivertedAircraftTypeTailNumberDistance
01United4558ORDMIA8WeatherTrueFalseBoeing 737N710661031
12Delta8021LAXMIA2Air Traffic ControlTrueTrueAirbus A320N226571006
23Southwest7520DFWSFO14WeatherTrueTrueBoeing 737N956112980
34Delta2046ORDBOS-10NaNFalseFalseBoeing 777N900291408
45Delta6049LAXSEA24Air Traffic ControlFalseTrueBoeing 737N274172298
56Southwest6311LAXJFK-5NaNFalseFalseBoeing 777N926521386
67Southwest4188ORDJFK7WeatherFalseTrueBoeing 777N253821674
78Southwest3179DFWMIA24WeatherFalseTrueBoeing 777N654102931
89American Airlines3613ORDMIA2WeatherFalseFalseAirbus A320N455702337
910Southwest2186LAXBOS25MaintenanceTrueFalseBoeing 777N15724605
1011American Airlines9317JFKMIA-6NaNTrueTrueAirbus A320N549052848
1112American Airlines5251DFWBOS30WeatherFalseFalseAirbus A320N94983131

Based on the above data, answer the given subquestions.

Which option will give the count of flights that have a delay greater than the average delay?

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

Correct answer

  • A

Question 6

+2 marksOne correct option

Consider the following dataset and transformer pipeline:

python
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import MinMaxScaler, OneHotEncoder
from sklearn.impute import KNNImputer
from sklearn.pipeline import Pipeline
X = np.array([[2.5, 'red', 1],
[2.85, 'blue', np.nan],
[4.0, 'green', 2],
[3.2, 'red', 1]])
pipe = Pipeline([('impute', KNNImputer(n_neighbors=2)),
('scale', MinMaxScaler())])
ct = ColumnTransformer([('num', pipe, [0, 2]),
('cat', OneHotEncoder(), [1])])
transformed_X = ct.fit_transform(X)

Based on the above data, answer the given subquestions.

  1. A

    (4, 5)

  2. B

    (4, 6)

  3. C

    (4, 7)

  4. D

    (4, 8)

  5. E

    None of these

Show answer

Correct answer

  • A

    (4, 5)

Question 7

+3 marksOne correct option

Consider the following dataset and transformer pipeline:

python
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import MinMaxScaler, OneHotEncoder
from sklearn.impute import KNNImputer
from sklearn.pipeline import Pipeline
X = np.array([[2.5, 'red', 1],
[2.85, 'blue', np.nan],
[4.0, 'green', 2],
[3.2, 'red', 1]])
pipe = Pipeline([('impute', KNNImputer(n_neighbors=2)),
('scale', MinMaxScaler())])
ct = ColumnTransformer([('num', pipe, [0, 2]),
('cat', OneHotEncoder(), [1])])
transformed_X = ct.fit_transform(X)

Based on the above data, answer the given subquestions.

  1. A

    0.0

  2. B

    0.5

  3. C

    -0.5

  4. D

    1

  5. E

    None of these

Show answer

Correct answer

  • D

    1

Question 8

+2 marksOne or more correct options

Which of the following preprocessing techniques helps in handling categorical features in a dataset?

Select all that apply.

  1. A

    One-hot encoding

  2. B

    StandardScaler

  3. C

    Label encoding

  4. D

    MinMaxScaler

Show answer

Correct answers

  • A

    One-hot encoding

  • C

    Label encoding

Question 9

+2 marksOne or more correct options

Which of the following imputation strategies can be used for handling missing values?

Select all that apply.

  1. A

    Filling with mean or median

  2. B

    Deleting the rows with missing values

  3. C

    Using a predictive model to estimate missing values

  4. D

    Using a random generator to fill missing values

Show answer

Correct answers

  • A

    Filling with mean or median

  • B

    Deleting the rows with missing values

  • C

    Using a predictive model to estimate missing values

Question 10

+2 marksOne or more correct options

Which of the following is correct about cross-validation in machine learning?

Select all that apply.

  1. A

    Cross-validation helps prevent overfitting.

  2. B

    It is a technique to improve the model’s accuracy.

  3. C

    K-Fold cross-validation is one of the most popular types of cross-validation.

  4. D

    Cross-validation is not suitable for small datasets.

Show answer

Correct answers

  • A

    Cross-validation helps prevent overfitting.

  • C

    K-Fold cross-validation is one of the most popular types of cross-validation.

Question 11

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

+2 marksOne or more correct options

Which of the following could be a correct output from the following code?

python
import numpy as np
from sklearn.model_selection import StratifiedKFold
X = np.random.rand(8, 2)
y = np.array([0, 0, 0, 1, 1, 1, 1, 0])
skf = StratifiedKFold(n_splits=2)
for train_index, test_index in skf.split(X, y):
print("TRAIN:", train_index, "TEST:", test_index)

Select all that apply.

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

Correct answers

  • A
  • D

Question 13

+3 marksOne correct option

Consider the following data and code:

python
import numpy as np
data = np.array([[1, 2, 3, 4],
[np.nan, 5, np.nan, 1],
[3, 4, 5, np.nan],
[2, 2, np.nan, 10]])

Which of the following pairs of data points have the second largest Manhattan distance after imputing the missing values with the column mean?

  1. A

    0 and 1

  2. B

    2 and 3

  3. C

    0 and 3

  4. D

    1 and 2

  5. E

    1 and 3

Show answer

Correct answer

  • B

    2 and 3

Question 14

+3 marksOne correct option

Consider the following data and snippet:

python
from sklearn.preprocessing import FunctionTransformer
import numpy as np
data = np.array([[5, np.nan, 3],
[2, 1, np.nan],
[np.nan, 4, 6]])
def replace_missing(X):
return np.nan_to_num(X, nan=0)
ft = FunctionTransformer(replace_missing)
transformed_data = ft.fit_transform(data)

Which of the following correctly represents the value of transformed_data[2,0] after the transformation?

  1. A

    0

  2. B

    4

  3. C

    6

  4. D

    None of these

Show answer

Correct answer

  • A

    0

Question 15

+3 marksOne correct option

Consider the following code where a ‘Pipeline’ is used for feature scaling, polynomial feature transformation, and applying a ‘SGDRegressor’.

The hyperparameter search is performed using ‘GridSearchCV’.

python
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, PolynomialFeatures
from sklearn.linear_model import SGDRegressor
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import make_regression
# Generate synthetic data
X, y = make_regression(n_samples=100, n_features=5, noise=0.1)
# Define a pipeline with scaling, polynomial features, and regression
pipeline = Pipeline([
('scaler', StandardScaler()),
('poly', PolynomialFeatures()),
('regressor', SGDRegressor(max_iter=1000, tol=1e-3))
])
# Define parameter grid for grid search
param_grid = {
'poly__degree': [1, 2, 3],
'regressor__alpha': [0.01, 0.1, 1],
'regressor__penalty': ['l2', 'l1'],
'regressor__learning_rate': ['constant', 'optimal']
}
# Perform grid search
grid = GridSearchCV(estimator=pipeline, param_grid=param_grid, scoring=
'r2', n_jobs=-1, cv=3)
grid.fit(X, y)

How many different models will be trained during this grid search process?

  1. A

    36

  2. B

    54

  3. C

    72

  4. D

    108

Show answer

Correct answer

  • A

    36

Question 16

+2 marksOne correct option

You are working on a machine learning project and have received a dataset containing numeric and categorical features. The dataset has some missing values and potential outliers. Given the following data cleaning steps:
1. Use One-Hot Encoding for categorical variables.
2. Impute missing values with feature’s mean for numeric features.
3. Remove duplicates.
4. Standardize numeric features using Z-score normalization.
5. Identify and handle outliers using the IQR method.
Which of the following represents the MOST appropriate sequence for preparing the data for a machine learning model?

  1. A

    1 → 4 → 2 → 3 → 5

  2. B

    3 → 2 → 1 → 4 → 5

  3. C

    2 → 3 → 1 → 5 → 4

  4. D

    3 → 5 → 2 → 1 → 4

Show answer

Correct answer

  • D

    3 → 5 → 2 → 1 → 4

Question 17

+2 marksOne correct option

Consider the following code snippet:

python
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.impute import SimpleImputer
pipe = Pipeline([('impute', SimpleImputer(strategy='most_frequent')),
('scale', StandardScaler()),
('reduce', PCA(n_components=2))])
data = np.array([[3, np.nan, 5],
[1, 2, np.nan],
[np.nan, 4, 6]])
transformed_data = pipe.fit_transform(data)

How many components does the PCA reduce the data to, after transformation?

  1. A

    2

  2. B

    3

  3. C

    1

  4. D

    None of these

Show answer

Correct answer

  • A

    2

Question 18

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

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

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

Correct answer

  • C

Question 21

+2 marksOne correct option
  1. A

    Intercept: 3.0, Coefficients: [1.0, 2.0]

  2. B

    Intercept: 3.0, Coefficients: [0.0, 2.0]

  3. C

    Intercept: 0.0, Coefficients: [1.0, 2.0]

  4. D

    Given code will return an error.

Show answer

Correct answer

  • A

    Intercept: 3.0, Coefficients: [1.0, 2.0]

Question 22

+1 markOne correct option
  1. A

    Controls the total number of iterations.

  2. B

    Specifies the tolerance level for early stopping.

  3. C

    Defines the number of iterations with no improvement to stop training.

  4. D

    Sets the learning rate schedule.

Show answer

Correct answer

  • C

    Defines the number of iterations with no improvement to stop training.