MLP End Term: 3 September 2023, Set QPD1-S2 (May 2023 term)
The IIT Madras BS Machine Learning Practice (MLP) End Term paper sat on 3 Sept 2023, in the May 2023 term, set QPD1-S2: 34 questions for 100 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.
- 34
- 100
- 180 min
- 4
- 24
- 6
Show answer
Correct answer: 0.5
Question 2
Given below a y_train list which consists of pizza’s ordered by the customers in a shop.
y_train = [['regular', 'veg'], ['medium', 'veg'], ['regular', 'non-veg'], ['medium', 'non-veg']]MultiLabelBinarizer from sklearn library has been used to convert the y_train into numbers, so which of the following option matches with the output using the following code ?
from sklearn.preprocessing import MultiLabelBinarizermlb = MultiLabelBinarizer(classes=['regular','medium', 'veg', 'non-veg'])print(mlb.fit_transform(y_train))Show answer
Correct answer
Question 3
You’re building a machine learning pipeline to preprocess data and train a model on a classification task. You decide to use a pipeline that includes data preprocessing and a support vector machine (SVM) classifier.
The following code snippet demonstrates the pipeline creation and usage:
from sklearn.pipeline import Pipelinefrom sklearn.svm import SVCfrom sklearn.preprocessing import StandardScalerimport numpy as np
# Simulated data (features: X, target: y)X = np.array([[2, 3], [5, 7], [8, 10]])y = np.array([0, 1, 0])
# Create a pipeline with StandardScaler and SVM classifierpipeline = Pipeline([ ('scaler', StandardScaler()), ('svm', SVC())])# Fit the pipeline on training datapipeline.fit(X, y)
# Make predictions using the trained pipelinepredictions = pipeline.predict(X)What is the purpose of using the pipeline in this code snippet?
The pipeline combines multiple models for better model performance.
The pipeline allows for simultaneous training of the scaler and classifier.
The pipeline simplifies the code by encapsulating preprocessing and modeling steps.
The pipeline ensures that only linear SVM can be used for this classification task.
Show answer
Correct answer
The pipeline simplifies the code by encapsulating preprocessing and modeling steps.
Question 4
You’ve developed a binary classification model to predict whether an email is spam or not. You want to evaluate the model’s performance using appropriate metrics. The following options represent different evaluation metrics. Choose the one that is most suitable for assessing the model’s performance in this scenario:
Show answer
Correct answer
Question 5
You are building a sentiment analysis model using scikit-learn’s SGDClassifier to classify movie reviews as positive or negative. The dataset is quite large, and you’re dealing with a high-dimensional feature space. You want to fine-tune the hyperparameters of the classifier to achieve better convergence and classification performance.
Here’s how you’re setting up the SGDClassifier:
from sklearn.linear_model import SGDClassifierclassifier = SGDClassifier(loss='hinge', alpha=0.0001, max_iter=1000, tol=1e-3, power_t=0.5)In the context of the given code and scenario, what does the power_t parameter value of 0.5 influence during the training process?
It determines the degree of L2 regularization applied to the model’s weights.
It controls the decay rate of the learning rate during each iteration.
It sets the threshold for early stopping based on the loss function improvement.
It adjusts the aggressiveness of stochastic gradient updates for faster convergence.
Show answer
Correct answer
It controls the decay rate of the learning rate during each iteration.
Question 6
What is the output of the following code?
corpus = [‘An overfitted model is a mathematical model that contains moreparameters than can be justified by the data.’]from sklearn.feature_extraction.text import CountVectorizervectorizer = CountVectorizer()vectors = vectorizer.fit_transform(corpus)print(vectors.shape)(16,1)
(8,2)
(4,4)
(1,16)
Show answer
Correct answer
(1,16)
Question 7
It ensures that the model will always produce the same predictions for any input data.
It guarantees that the model will converge to the global optimum during training.
It prevents overfitting by adding randomness to the model’s predictions.
It allows for reproducibility, ensuring consistent results across different runs.
Show answer
Correct answer
It allows for reproducibility, ensuring consistent results across different runs.
Question 8
Consider the following code involving the use of LabelEncoder from sklearn.preprocessing:
from sklearn.preprocessing import LabelEncoder
data = ["apple", "orange", "banana", "apple", "grape", "orange", "grape"]
encoder = LabelEncoder()encoded_data = encoder.fit_transform(data)
print(encoded_data)Which of the following statements is true based on the code?
Show answer
Correct answers
Question 9
Which of the following statements are true?
KNeighborsClassifier with high values of n_neighbors produces complex decision boundaries.
KNeighborsClassifier with high values of n_neighbors produces smooth decision boundaries.
In KNeighborsClassifier the scale of the features(columns) can impact the decision boundaries.
None of these
Show answer
Correct answers
KNeighborsClassifier with high values of n_neighbors produces smooth decision boundaries.
In KNeighborsClassifier the scale of the features(columns) can impact the decision boundaries.
Question 10
Which of the following option(s) are correct regarding regularization?
Regularization is the error given by any model while predicting the values for the test set.
It helps in decreasing the bias of the training model.
Compare to without regularized model regularization decreases the variance of the training model
Predictions made with the Ridge Regression are less sensitive to
weights(coefficients) than the Linear Regression.
Show answer
Correct answers
Compare to without regularized model regularization decreases the variance of the training model
Predictions made with the Ridge Regression are less sensitive to
weights(coefficients) than the Linear Regression.
Question 11
Consider the following sklearn code snippet that employs a Pipeline for data preprocessing:
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import MinMaxScaler, Binarizer
data = [[1, 5], [5, 15], [0, 10], [1, 15]]
pipeline = Pipeline([('scaler', MinMaxScaler()), ('binarize', Binarizer(threshold=0.1))])
transformed_data = pipeline.fit_transform(data)What will be the output of the following code?
print(transformed_data[0])Show answer
Correct answer
Question 12
Consider the following code snippet that uses PCA from sklearn.decomposition for dimensionality reduction on a dataset with 10 features:
import numpy as npfrom sklearn.decomposition import PCA
np.random.seed(42)X = np.random.rand(100, 10)
pca = PCA(n_components=4)X_pca = pca.fit_transform(X)
explained_variance = np.sum(pca.explained_variance_ratio_)After executing this code, which of the following statements is true regarding the explained_variance?
Show answer
Correct answer
Question 13
You’ve built a linear regression model to predict the salary of employees based on their years of experience and education level. The model’s coefficients for the features are as follows: - Coefficient for Years of Experience: 5000
- Coefficient for Education Level: 3000
What does the coefficient for ”Years of Experience” (5000) represent in this context?
For each additional year of experience, an employee’s salary is expected to increase by 5000.
For each additional year of experience, an employee’s salary is expected to decrease by 5000.
Education level has a stronger impact on salary than years of experience.
The coefficient doesn’t have any meaningful interpretation in this scenario.
Show answer
Correct answer
For each additional year of experience, an employee’s salary is expected to increase by 5000.
Question 14
You’re working on a dataset that includes data points for a single feature and a target variable. You decide to use polynomial regression with a degree of 3 to capture potential cubic relationships. The following code snippet demonstrates the process:
from sklearn.preprocessing import PolynomialFeaturesimport numpy as np
# Simulated data (feature: X)X = np.array([1, 2, 3, 4, 5])
# Reshape the featuresX = X.reshape(-1, 1)
# Transform features into polynomial featurespoly = PolynomialFeatures(degree=3)X_poly = poly.fit_transform(X)What will be the shape of the X_poly matrix after transforming the feature ‘X‘ into polynomial features of degree 3?
(5, 1)
(5, 3)
(5, 4)
(5, 6)
Show answer
Correct answer
(5, 4)
Question 15
Show answer
Correct answer
Question 16
Show answer
Correct answer
Question 17
Imagine you’re training a Perceptron using sklearn with the following code:
from sklearn.linear_model import Perceptron
X = [[0, 0.5], [1, 1.5], [1, 2], [2, 3]]y = [-1, -1, 1, 1]
clf = Perceptron( tol=None, shuffle=True, random_state=42)clf.fit(X, y)
iterations = clf.n_iter_Given the linearly separable nature of the data, how many iterations would it most likely take for the perceptron to converge? What will be the value of iterations?
Show answer
Correct answer
Question 18
A higher alpha value results in stronger regularization, leading to larger feature coefficients.
The alpha value has no impact on the regularization strength in
‘RidgeClassifier‘.Cross-validation can be used to find the optimal alpha value.
‘RidgeClassifier‘ automatically determines the alpha value based on the data distribution.
Show answer
Correct answer
Cross-validation can be used to find the optimal alpha value.
Question 19
You’re applying the K-means clustering algorithm to a dataset with a large number of data points. You decide to use the K-means++ initialization method for better convergence and clustering quality. What is the primary advantage of using K-means ++ initialization over random initialization?
K-means++ initialization guarantees finding the global optimum of the clustering solution.
K-means++ initialization speeds up the convergence of the algorithm.
K-means++ initialization reduces the number of clusters needed for accurate results.
K-means++ initialization helps avoid local optima during clustering.
Show answer
Correct answer
K-means++ initialization helps avoid local optima during clustering.
Question 20
Suppose you are working on a classification task involving handwritten digit recognition using scikit-learn’s MLPClassifier. You have a large dataset of digit images and want to train a neural network for this task. However, you’re concerned about overfitting and want to make sure the training process stops at the right time to avoid this issue. In the context of training an MLPClassifier for handwritten digit recognition,how does the early stopping parameter help prevent overfitting?
It terminates the training process as soon as the specified number of hidden layers are trained.
It automatically decreases the learning rate during training to slow down the optimization process.
It pauses the training when the model’s performance on a validation set stops improving.
It enforces a maximum limit on the number of epochs during the training process.
Show answer
Correct answer
It pauses the training when the model’s performance on a validation set stops improving.
Question 21
You’re training a multi-layer perceptron (MLP) classifier on a dataset for a multi-class classification task. The following code snippet demonstrates the process using the ‘MLPClassifier’ from scikit-learn:
from sklearn.neural_network import MLPClassifierimport numpy as np
# Simulated data (features: X, target: y)X = np.array([[1, 2], [3, 4], [5, 6]])y = np.array([0, 1, 2])
# Create an MLPClassifier with a specified maximum number of iterationsmodel = MLPClassifier(max_iter=100, random_state=42)
# Fit the model on the training datamodel.fit(X, y)
# Get the number of iterations used in trainingiterations_used = model.n_iter_What does the parameter max_iter=100 in the MLPClassifier signify?
It specifies the maximum number of features to be used during training.
It determines the maximum number of neurons in the hidden layers.
It sets the maximum number of iterations for the training process.
It controls the maximum number of epochs for the training process.
Show answer
Correct answer
It sets the maximum number of iterations for the training process.
Question 22
You’re working on a multi-class classification task using the ‘MLPClassifier’ from scikit-learn. The dataset contains features with varying scales, and you’re considering whether to scale the features before training the model. How might feature scaling impact the prediction accuracy of the ‘MLPClassifier’?
Feature scaling has no effect on the accuracy of ‘MLPClassifier‘ predictions.
Scaling features is only relevant if the dataset contains categorical features.
Feature scaling can lead to overfitting and decreased prediction accuracy.
Scaling features can help the model converge faster and improve prediction accuracy.
Show answer
Correct answer
Scaling features can help the model converge faster and improve prediction accuracy.
Question 23
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,2.4], [4,4.8], [6,7.2]]y_train = [0,1,2,3]reg = LinearRegression(fit_intercept=False) #intercept = 0reg.fit(X_train,y_train)print(reg.coef_[0])Show answer
Correct answer: 0.20455 (accepted within ±0.00065)
Question 24
Show answer
Correct answer: 0.287 (accepted within ±0.004)
Question 25
Show answer
Correct answer: 2
Question 26
Consider the following code snippet that employs LogisticRegression from sklearn on a feature matrix X and corresponding label vector y:
from sklearn.linear_model import LogisticRegression
model = LogisticRegression(C=0.8, multi_class='multinomial', max_iter=1000)model.fit(X, y)Given the code above, which of the following statements is true?
The logistic regression model is set up for binary classification.
The model does not use any regularization because the parameter C is set.
The model has been specifically set up to handle a multi-class classification problem using a softmax regression approach.
The model will iterate over the data a maximum of 1000 times, irrespective of convergence.
Show answer
Correct answers
The model has been specifically set up to handle a multi-class classification problem using a softmax regression approach.
The model will iterate over the data a maximum of 1000 times, irrespective of convergence.
Question 27
MultinomialNB
RandomForestRegressor
MiniBatchKMeans
LogisticRegressor
Show answer
Correct answers
MultinomialNB
MiniBatchKMeans
Question 28
‘poly’,
‘lasso’
‘scale’
‘sigmoid’
Show answer
Correct answers
‘poly’,
‘sigmoid’
Question 29
Consider the following code snippet where two decision trees are trained on the same dataset:
from sklearn.tree import DecisionTreeClassifierfrom sklearn.datasets import load_digits
data = load_digits()X, y = data.data, data.target
tree_1 = DecisionTreeClassifier(splitter='best', max_leaf_nodes=5)tree_1.fit(X, y)
tree_2 = DecisionTreeClassifier(splitter='random', max_leaf_nodes=None)tree_2.fit(X, y)Given the configurations of tree_1 and tree_2, which decision tree is more likely to overfit the training data?
Show answer
Correct answer
Question 30
Given the following code using BaggingClassifier with KNeighborsClassifier as the base estimator:
from sklearn.ensemble import BaggingClassifierfrom sklearn.neighbors import KNeighborsClassifier
base_knn = KNeighborsClassifier(n_neighbors=3, weights='distance')
bag_clf = BaggingClassifier(base_knn, n_estimators=30, max_samples=100, bootstrap=False, random_state=42)Which of the following statements is correct?
Show answer
Correct answer
Question 31
Show answer
Correct answer
Question 32
Show answer
Correct answer
Question 33
Show answer
Correct answer
Question 34
You’re evaluating the results of a clustering algorithm and you calculate the silhouette score for the clustering solution. The obtained silhouette score is -0.15. What can you infer from this silhouette score?
The clustering solution has well-defined and distinct clusters.
The silhouette score indicates a random distribution of data points across clusters.
The data points are equally spaced across clusters.
The clustering solution is flawed and the data points might be assigned to incorrect clusters.
Show answer
Correct answer
The clustering solution is flawed and the data points might be assigned to incorrect clusters.
