Question 1
Consider the following common data and answer the subquestion:
Consider the following code snippet:
Which of the following will be equivalent to the above code snippet?
The IIT Madras BS Machine Learning Practice (MLP) End Term paper sat on 1 Sept 2024, in the May 2024 term, set QDF3: 37 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.
Consider the following common data and answer the subquestion:
Consider the following code snippet:
Which of the following will be equivalent to the above code snippet?
Correct answers
Consider the following common data and answer the subquestion:
What is the output of the following code snippet:
Enter -1, if you think the above statement will generate an error.
Correct answer: 120
Consider the following common data and answer the subquestion:
What is the output of the following code snippet:
Enter -1, if you think the above statement will generate an error.
Correct answer: 3
Consider the following common data and answer the subquestion:
What is the output of the following code snippet:
Enter -1, if you think the above statement will generate an error.
Correct answer: -1
Consider the following common data and answer the subquestion:
What is the output of the following code snippet:
Choose correct options from following:
The number of rows will decrease in the dataset.
The number of columns will decrease in the dataset.
The number of columns and number of rows, both, will decrease in the dataset.
There will be no change.
Insufficient information.
Correct answer
The number of rows will decrease in the dataset.
To load datasets from openml.org, which method will be appropriate?
load_openml()
read_openl()
read_data()
fetch_openml()
load_data()
load_csv()
fetch_csv()
Correct answer
fetch_openml()
In which of the option given below data preprocessing is required?
In some columns which has values between 0 and 1.
A column contains entity names such as ‘Chennai’, ‘CHENNAI’ and ‘MADRAS’.
The data has only numbers in all the columns.
Correct answer
A column contains entity names such as ‘Chennai’, ‘CHENNAI’ and ‘MADRAS’.
Consider the following code block:
X = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']from sklearn.model_selection import KFoldkf = KFold(n_splits = 3)for train, test in kf.split(X): print(train, test)Which of the following may be the correct output of the above code?
Correct answer
Which of the following scikit-learn classes is best suited for examining how the number of samples impacts training and testing errors?
Correct answer
Consider following two statements:
Statement 1: The GaussianNB classifier can incrementally learn using partial_fit.
Statement 2: GaussianNB performance suffers when features are dependent, as it assumes independence in calculating conditional probabilities.
Both statements are True
Only statement 1 is True
Only statement 2 is True
Both statements are False
Correct answer
Both statements are True
Given below code to load a huge file name as filename.csv and this file is not loading at once in the system which parameter should be added to pd.read_csv to load this file ?
import pandas as pdfrom sklearn.linear_model import SGDRegressorfor train_df in pd.read_csv("filename.csv", __________=1024): X = train_df.iloc[:, :-1] y = train_df.iloc[:, -1] model = SGDRegressor() model.partial_fit(prep_X,y)Correct answer
Which of the following is true for a hard margin SVM algorithm ?
It does not create hyperplanes as a decision boundary
It will correctly classify all the data point if the data is linearly separable
It is robust to outliers
It is mostly used for clustering the data
Correct answer
It will correctly classify all the data point if the data is linearly separable
What could be the output for below code
from sklearn.feature_extraction.text import CountVectorizercorpus = [ 'This is the first document.', 'This document is the second document.']vectorizer = CountVectorizer()vectorizer.fit_transform(corpus)print(vectorizer.vocabulary_)Correct answer
Decision Trees are prone to:
Low bias, low variance
High bias, low variance
Low bias, high variance
High bias, high variance
Correct answer
Low bias, high variance
Following is the code to tune the degree parameter of a polynomial regression model.
from sklearn.model_selection import GridSearchCVfrom sklearn.pipeline import Pipelinefrom sklearn.preprocessing import PolynomialFeaturesfrom sklearn.linear_model import SGDRegressor
param_grid = [{_________: [2, 3, 4, 5, 6, 7, 8, 9]}]pipeline = Pipeline(steps=[('poly', PolynomialFeatures()), ('sgd', SGDRegressor())])grid_search = GridSearchCV(pipeline, param_grid, cv=5,scoring='neg_mean_squared_error',return_train_score=True)grid_search.fit(X_train, y_train)What should the blank space contain?
Correct answer
Consider the following code block:
from sklearn.datasets import make_regressionX, y = make_regression(n_samples = 1000, n_features = 4, n_informative = 2, random_state=42)
from sklearn.linear_model import SGDRegressorsgd1 = SGDRegressor(alpha=1e-3, random_state=42 penalty='________________', )sgd1.fit(X, y)print(sgd1.coef_)
sgd2 = SGDRegressor(alpha=1e-3, random_state=42, penalty='_________________')sgd2.fit(X, y)print(sgd2.coef_)What are the most suitable values to be filled in the two blank spaces (in that order) in the code to expect the following output?:
[48.50064306, 0 , 0 , 8.53931469][4.84494867e+01, -7.58443057e-04, -2.09844306e-03, 8.53220113e+00]‘l1’, ‘l2’
‘l1’, None
‘l2’, ‘l1’
‘l2’, None
Correct answer
‘l1’, ‘l2’
Consider following code:
estimator = SGDClassifier(loss='log_loss', penalty='l2', max_iter=1, warm_start="_____", eta0=0.01, alpha=0, learning_rate='constant', )pipe_sgd= make_pipeline(MinMaxScaler(), estimator)Which of the following is a suitable choice for warm_start if you wanted to plot learning curve with decreasing loss when trained for 100 epochs? Make necessary assumptions.
True
False
Yes
No
None of these
Correct answer
True
It controls the number of weak learners.
It shrinks the contribution of each classifier.
It sets the weight of each weak learner.
It adjusts the speed at which the model learns.
Correct answer
It shrinks the contribution of each classifier.
The following code produces an output of 0.9125. How is the output expected to change if we increase the max_depth value?:
from sklearn.datasets import load_winefrom sklearn.tree import DecisionTreeClassifierfrom sklearn.model_selection import train_test_splitX,y = load_wine(as_frame = True, return_X_y = True)
X_train,X_test,y_train,y_test = train_test_split(X, y, test_size = 0.10, random_state = 12)
clf = DecisionTreeClassifier(max_depth = 2, min_samples_split = 2, min_samples_leaf=3, random_state = 81)
clf.fit(X_train, y_train)print(clf.score(X_train, y_train))Output score is likely to increase.
Output score is likely to decrease.
Output score may increase or decrease.
Output score will remain the same.
Correct answer
Output score is likely to increase.
Consider the following code. How many different combinations of DecisionTreeClassifier models will be trained internally?
from sklearn.tree import DecisionTreeClassifierfrom sklearn.model_selection import GridSearchCVparam_grid = [{'max_depth':range(1, 10, 2), 'min_samples_split': range(1, 10, 3)}]gs = GridSearchCV(DecisionTreeClassifier(), param_grid, cv = 5)gs.fit(X,y)20
75
8
15
40
Correct answer
15
Consider the following code for a VotingClassifier. What is the effect of setting voting='soft'?
from sklearn.ensemble import VotingClassifierclf1 = LogisticRegression()clf2 = RandomForestClassifier()clf3 = SVC(probability=True)eclf = VotingClassifier(estimators=[('lr', clf1), ('rf', clf2), ('svc', clf3)], voting='soft')eclf.fit(X_train, y_train)The final predictions are based on the majority vote.
The final predictions are based on the average of probabilities predicted by each classifier.
The final predictions are based on the weighted sum of the predictions.
The final predictions are based on the classifier with the highest accuracy.
Correct answer
The final predictions are based on the average of probabilities predicted by each classifier.
The mean accuracy across all cross-validation folds.
The mean precision across all cross-validation folds.
The mean recall across all cross-validation folds.
The mean F1 score across all cross-validation folds.
Correct answer
The mean accuracy across all cross-validation folds.
Plotting the sum of the squared distances of samples to their closest cluster center
by Changing the distance metric for KMeans
By initialising clustering centroids very far from each other
All of these
Correct answer
Plotting the sum of the squared distances of samples to their closest cluster center
Consider the following code:
from sklearn.datasets import load_irisfrom sklearn.model_selection import train_test_splitX, y = load_iris(return_X_y = True)The sizes of X and y are (150, 4) and (150,) respectively. Which of the following would be the correct code snippet to split X and y into training and test data such that test data has exactly 30 samples?
Correct answers
Consider the following code block:
from sklearn.linear_model import linear_regressionfrom sklearn.model_selection import cross_val_scorefrom sklearn.model_selection import ShuffleSplitlin_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?
Correct answers
Which of the following is a hyper parameter?
Correct answers
Which of the following models are inherently multiclass models?
Perceptron
DecisionTreeClassifier
KNeighborClassifier
LogisticRegression
Correct answers
DecisionTreeClassifier
KNeighborClassifier
Which of the following class(es) is/are used to instantiate a neural network in Sklearn.
SGDClassifier()
MLPClassifier()
NNClassifier()
MLPRegressor()
Correct answers
MLPClassifier()
MLPRegressor()
Which of the following is correct?
Correct answers
Which of the following processes can be done if we have a dataset with imbalanced target class distribution?
Remove all the minority classes
Up-sample the minority classes
Remove all the majority classes
Down-sample the majority classes
create synthetic samples to balance the classes
Correct answers
Up-sample the minority classes
Down-sample the majority classes
create synthetic samples to balance the classes
Which of the following is true about Naive Bayes algorithm ?
It is primarily used for regression problems
It is primarily used for classification problems
Hyperparameter tuning is required
Hyperparameter tuning is not required
Correct answers
It is primarily used for classification problems
Hyperparameter tuning is not required
Which of the following is/are correct regarding RadiusNeighborsClassifier
Only 5 neighbours in the range of some radius are used to compute the label of a sample.
All the neighbours in the range of some radius are used to compute the label of a sample.
It is sensitive to outliers.
It is not sensitive to outliers.
Correct answers
All the neighbours in the range of some radius are used to compute the label of a sample.
It is not sensitive to outliers.
Data is continuously being generated
Data is generated every month
Whole data is generated and its in a huge file size
For very small dataset
Correct answers
Data is continuously being generated
Data is generated every month
Whole data is generated and its in a huge file size
The neural network contains 3 hidden layers with 5 neurons in each hidden layer
The neural network contains 5 hidden layers with 3 neurons in each hidden layer
The neural network contains 2 hidden layers with 3 neurons in the second hidden layer
The neural network contains 2 hidden layers with 5 neurons in the first hidden layer
All of the given options are correct
Correct answers
The neural network contains 2 hidden layers with 3 neurons in the second hidden layer
The neural network contains 2 hidden layers with 5 neurons in the first hidden layer
Consider the following block of code:
from sklearn.datasets import load_breast_cancerfrom sklearn.tree import DecisionTreeClassifierfrom sklearn.model_selection import train_test_splitX,y = load_breast_cancer(as_frame = True, return_X_y = True)X_train,X_test,y_train,y_test = train_test_split(X,y, test_size = 0.2, random_state=42)clf = DecisionTreeClassifier(min_samples_split = 6, min_samples_leaf = 4, random_state = 5)clf.fit(X_train, y_train)print(clf.score(X_test, y_test))In which of the following scenarios, the split will can happen at node N?
Number of samples at node N = 15. If it is split, it will result in 9 samples in the left child node and 6 sample in the right child node.
Number of samples at node N = 5. If it is split, it will result in 4 samples in the left child node and 2 samples in the right child node.
Number of samples at node N = 12. If it is split, it will result in 3 samples in the left child node and 9 samples in the right child node.
Number of samples at node N = 7. If it is split, it will result in 4 samples in the left child node and 3 samples in the right child node.
Correct answers
Number of samples at node N = 15. If it is split, it will result in 9 samples in the left child node and 6 sample in the right child node.
Number of samples at node N = 7. If it is split, it will result in 4 samples in the left child node and 3 samples in the right child node.
Correct answer: 0.3235 (accepted within ±0.0045)
Correct answer: 180