Question 1
The highest score for each student.
A list of subjects sorted by their average scores.
The average score of each student across all subjects.
A DataFrame with the scores of all students for each subject.

The IIT Madras BS Machine Learning Practice (MLP) Quiz 1 paper sat on 29 Oct 2023, in the September 2023 term: 23 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.
The highest score for each student.
A list of subjects sorted by their average scores.
The average score of each student across all subjects.
A DataFrame with the scores of all students for each subject.
Correct answer
The average score of each student across all subjects.
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:
Which of the following represents the MOST appropriate sequence for preparing the data for a machine learning model?
Correct answer
You’re working with a dataset that consists of training data (‘train_data’) and test data (‘test_data’). The dataset contains both numerical and categorical features. You decide to employ a combination of ‘StandardScaler’ (for numerical columns) and ‘OneHotEncoder’ (for categorical columns) from ‘scikit-learn’ using the ‘ColumnTransformer’ utility. Which of the following actions is MOST likely to introduce data leakage or potential modeling issues?
You utilize ‘fit_transform’ on ‘train_data’ and then ‘transform’ on ‘test_data’ using the ‘ColumnTransformer’.
After observing a new category in the test data that was not present in the training data, you set the ‘handle_unknown’ parameter to ’ignore’ in ‘OneHotEncoder’.
You first apply ‘fit’ on the ‘test_data’ and then ‘transform’ on ‘train_data’ using the ‘ColumnTransformer’.
Before using ‘ColumnTransformer’, you independently apply ‘fit_transform’ to ‘train_data’ for both ‘StandardScaler’ and ‘OneHotEncoder’.
Correct answer
You first apply ‘fit’ on the ‘test_data’ and then ‘transform’ on ‘train_data’ using the ‘ColumnTransformer’.
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?
Plotting a heatmap of the correlation matrix to understand the linear relationship between the numeric features.
Using a scatter plot to visualize the relationship between the square footage of a house and its price.
Visualizing the distribution of housing prices using a pie chart.
Creating box plots for housing prices, grouped by the number of bedrooms, to detect outliers and understand the distribution across different categories.
Correct answer
Visualizing the distribution of housing prices using a pie chart.
Important parameter in MinMaxScaler was missing while transforming the data.
train_test_split shouldn’t be done while setting random_state parameter.
X_test was transformed incorrectly.
All the steps are correct
Correct answer
X_test was transformed incorrectly.
Imagine you’ve loaded a dataset with 1000 samples into a Pandas DataFrame, and each sample has 30 features. Unfortunately, some samples have missing values for a few features, and you want to remove samples with more than 3 null values present. Please select the method to accomplish this task.?
drop(how= 27)
drop(columns=[‘all’])
dropna(thresh = 27)
dropna(how=‘any’)
dropna(thresh=3)
Correct answer
dropna(thresh = 27)
Choose the options with respect to the given statements:
Statement1 : To apply various sklearn methods from in series on a column we should use Pipeline.
Statement2 : To apply various sklearn methods on various columns in parallel we should use ColumnTransformer.
Statement 1 False, Statement 2 False
Statement 1 True, Statement 2 False
Statement 1 False, Statement 2 True
Both statements are True
Correct answer
Both statements are True
Consider the following code:
import numpy as npfrom sklearn.model_selection import ShuffleSplit
X = np.array([[24, 13],[19, 18], [25, 18],[27, 23], [11, 25],[22, 12], [27, 16],[17, 25]])y = np.array([-1, 1, -1, 1, 1, -1, 1, -1])
ss = ShuffleSplit(n_splits=3, test_size=.25, random_state= 42)
for train_index, test_index in ss.split(X): print(train_index,test_index)Which of the following may be the correct output of the above code?:
Correct answer
Which of the following is likely to be the correct output of the code given below?
from sklearn import linear_modelclf = linear_model.Ridge(alpha=0.01)X= [[1,0], [2, 1], [3, 2]]y= [1, 2, 3]clf.fit(X, y)linear_model.Ridge(alpha=0.01,max_iter=1000, tol=0.0001,fit_intercept=True)clf.score(X,y)5
99
0.999
No evaluation metrics is mentioned, hence it will produce error.
Correct answer
0.999
You are working on optimizing a machine learning model for predicting the energy efficiency of buildings. To capture potential non-linear relationships between features like floor area, wall area, and roof area, you decide to introduce polynomial features. However, considering the risk of multicollinearity due to the introduction of these polynomial features, you also want to ensure the data is appropriately scaled. You construct the following pipeline:
from sklearn.pipeline import Pipelinefrom sklearn.preprocessing import PolynomialFeatures, MinMaxScaler
pipeline = Pipeline([ ('poly', PolynomialFeatures(degree=2, interaction_only=True)), ('scaler', MinMaxScaler())])Given this setup, which of the following statements accurately describes the operation of this pipeline on the training data?
The pipeline will generate polynomial features (including squared terms) and then scale these features to a range between 0 and 1.
The transformed data will consist of the original features, their squares, and interaction terms, all scaled between 0 and 1.
The pipeline scales the original features between 0 and 1, then subsequently generates polynomial combinations including both square terms and interaction terms.
Only interaction terms between features are generated by the pipeline, which are then scaled between 0 and 1, without including the squared terms of individual features.
Correct answer
Only interaction terms between features are generated by the pipeline, which are then scaled between 0 and 1, without including the squared terms of individual features.
You’re developing a regression model for predicting house prices based on various attributes of a house. Given that some features might be redundant or irrelevant, you consider Lasso regression to help with feature selection. To determine the most appropriate regularization strength , you decide to use LassoCV from scikit-learn. Here’s a part of your implemented code:
from sklearn.datasets import make_regressionfrom sklearn.linear_model import LassoCV
X, y = make_regression(n_samples=400, n_features=25, noise=1.0, random_state=7)lasso = LassoCV(cv=10)lasso.fit(X, y)Given the nature of Lasso regression and the purpose of the code, which potential benefit are you hoping to achieve?
Optimize the model’s complexity by automatically determining the best α through cross-validation.
Reduce overfitting by incorporating 10-fold cross-validation during model selection.
Make predictions using an ensemble of 10 different Lasso models trained on different subsets of the data.
Maximize the number of features retained in the model, ensuring a complex model representation.
Correct answer
Optimize the model’s complexity by automatically determining the best α through cross-validation.
You are working on a regression problem and decide to use the SGDRegressor from scikit-learn. You set up two different regressors with distinct parameter values and train them on the same dataset:
from sklearn.linear_model import SGDRegressor
# First SGDRegressorsgd1 = SGDRegressor(max_iter=1000, tol= None, penalty='none')sgd1.fit(X_train, y_train)
# Second SGDRegressorsgd2 = SGDRegressor(max_iter=5, tol=None, penalty='none')sgd2.fit(X_train, y_train)Given the configurations above, which SGDRegressor is more likely to underfit the training data?
sgd1
sgd2
Correct answer
sgd2
Which columns may not be included in the selected data within the code below?
from sklearn.feature_selection import VarianceThreshold
data =[[ 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 ], [ 5, 0.332, 139, 1, 1.40 ], [-142, 0.332, -214, 1, -1.31 ], [ 148, 0.332, 6, 1, -8.6 ], [ 162, 0.332, 34, 1, -6.5 ], [ -65, 0.332, -120, 1, -8.3 ], [ 197, 0.332, 44, 1, -0.76 ]]
vf = VarianceThreshold(threshold=0)
selected_data = vf.fit_transform(data)selected_dataColumn indexed at 0
Column indexed at 1
Column indexed at 2
Column indexed at 3
Column indexed at 4
No columns
Correct answers
Column indexed at 1
Column indexed at 3
Which of the following code blocks will correctly take the learning rate as ‘optimal’ ?
Correct answer
While performing exploratory data analysis (EDA) on a dataset, you come across some columns with a high percentage of missing values. Along with that, a few categorical columns have a large number of unique categories. Which of the following actions would typically be a recommended initial approach during EDA? (Choose multiple correct options.)
Visualizing the data distribution of columns to understand their characteristics.
Using dimensionality reduction techniques, like PCA, to handle columns with many unique categories.
Visualizing the distribution of missing values across the dataset to ascertain any patterns or systematic missingness.
Removing columns that have more than 90% missing values without any context.
Correct answers
Visualizing the data distribution of columns to understand their characteristics.
Visualizing the distribution of missing values across the dataset to ascertain any patterns or systematic missingness.
Removing columns that have more than 90% missing values without any context.
Given the following code snippet involving GridSearchCV for hyperparameter tuning of a LinearRegression model:
from sklearn.datasets import make_regressionfrom sklearn.linear_model import SGDRegressorfrom sklearn.model_selection import GridSearchCV
X, y = make_regression(n_samples=200, n_features=15, noise=0.5, random_state=24)
params = {'penalty': ['l1', 'l2'], 'max_iter': [500, 1000]}reg = GridSearchCV(estimator= SGDRegressor(), param_grid= params, scoring= 'neg_mean_squared_error', refit= True)reg.fit(X, y)Select all statements that are TRUE given this code snippet:
Correct answers
Given the following code snippet, how many unique values will be present in the column of the resulting DataFrame ?
import pandas as pd
# Creating a DataFramedata = { 'X': ['apple', 'orange', 'apple', 'banana', 'banana', 'orange'], 'Y': [1, 2, 3, 3, 2, 2]}df = pd.DataFrame(data)
df['Z'] = df['X'] + df['Y'].astype(str)Correct answer: 5
What will be the output of the following code ?
data = [['apple', 120], ['cherry', 130], ['apple', 122], ['apple', 125], ['grapes', 70]]
from sklearn.preprocessing import OneHotEncoderohe = OneHotEncoder(sparse_output=False)ohe.fit(data)print(ohe.transform(data).shape[1])Correct answer: 8
What will be the output of the following code ?
from sklearn.preprocessing import MinMaxScaler, StandardScaler
data = [[0, 5], [8, 3], [3, 4], [7, 2], [7, 9]]
scaler = StandardScaler()scaler.fit(data)print(scaler.var_[0])Correct answer: 9.2
You’re using GridSearchCV to optimize a Ridge regression model from scikit-learn. Consider the following hyperparameter grid:
from sklearn.linear_model import Ridgefrom sklearn.model_selection import GridSearchCV
param_grid = { 'alpha': [0.001, 0.01, 0.1, 1, 10, 100], 'fit_intercept': [True, False], 'solver': ['auto', 'lsqr', 'sag']}
grid_search = GridSearchCV(Ridge(), param_grid, cv=5)How many combinations will GridSearchCV evaluate?
Correct answer: 36
For LinearRegression with equation and given that and . What will be the value of the for the below code? (Write 3 digits after the decimal)
Where and are column1 and column2 respectively and and are weights associated to the respected columns while fitting
from sklearn.linear_model import LinearRegressionX_train = [[0,0], [2,1.43], [4,2.86], [6,4.29]]y_train = [0,1,2,3]reg = LinearRegression(fit_intercept=False) #intercept=0reg.fit(X_train,y_train)print(reg.coef_[0])Correct answer: 0.33 (accepted within ±0.003)
Go through the code snippet given below and answer the given subquestions.
from sklearn.linear_model import SGDRegressorfrom sklearn.pipeline import make_pipelinen_samples, n_features = 18, 4rng = 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?
[-0.02634908 0.01189399 0.0917284 0.08966849]
array([-0.22622766, -0.00582008, -0.1820344 , 0.03518086, -0.14490955])
array([-0.22622766, -0.00582008, -0.1820344 ])
Given code will return an error because the data set is not given.
Correct answer
[-0.02634908 0.01189399 0.0917284 0.08966849]
Go through the code snippet given below and answer the given subquestions.
from sklearn.linear_model import SGDRegressorfrom sklearn.pipeline import make_pipelinen_samples, n_features = 18, 4rng = 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 could be the possible output of print(reg.score())?
-0.528
1
0.528
Given code will return an error
Correct answer
Given code will return an error