60 questions pulled from past papers whose wording matches this week's topics, newest first, duplicates removed. Pick your answers, then press Check answers. Figures and answer keys are the originals.
In the following question an Assertion (A) is followed by a Reason (R). Choose the correct option. Assertion (A): In a scikit-learn , the last step must be a transformer that implements both and . Reason (R): Only the intermediate steps of a are required to implement ; the final estimator only needs to implement .
Both A and R are true, and R is the correct explanation of A
Both A and R are true, but R is not the correct explanation of A
A news article dataset contains 10,000 documents. The word "government" appears in 9,500 documents, while the word "cryptocurrency" appears in only 200 documents. A TF-IDF vectorizer is applied to this dataset. Which of the following statements is most likely true?
The TF value of "government" will always be lower than the TF value of "cryptocurrency" because it appears in more documents.
The IDF contribution of "cryptocurrency" will be higher than that of "government", even if both words occur the same number of times in a document.
If "government" appears 50 times in one article, its TF-IDF score must be higher than "cryptocurrency" appearing once in the same article.
Removing "government" from the vocabulary will always decrease model performance because it appears in most documents.
What is the output of the following code? import pandas as pd from sklearn.preprocessing import OneHotEncoder df = pd.DataFrame({ "Color": ["Red", "Blue", "Green", "Blue", "Red"], "Size": ["S", "M", "L", "XL", "M"] }) encoder = OneHotEncoder(drop="first", sparse_output=False) X = encoder.fit_transform(df) print(X.shape[1])
Consider two regularization models, Model A (Ridge) and Model B (Lasso), trained on a dataset where two input features are highly collinear ( X1≈X2 ).
Which of the following statements accurately describe the expected behavior of these models and their evaluation metrics under severe collinearity?
Model B (Lasso) will distribute the regression coefficients evenly across both X1 and X2 to balance the penalty, while Model A (Ridge) will force one of the coefficients to be exactly zero.
Model A (Ridge) will shrink the coefficients of X1 and X2 toward zero but keep them roughly equal, whereas Model B (Lasso) will unstablely select one feature to keep and drive the coefficient of the other exactly to zero.
If the target variable y contains extreme outliers, evaluating these models using Mean Squared Error (MSE) will penalize those large errors more heavily than Mean Absolute Error (MAE).
Minimizing the MSE loss function during the training of Model A and Model B mathematically guarantees that the sum of the residual errors ( y−ŷ ) will always equal zero.
In the following question an Assertion (A) is followed by a Reason (R). Choose the correct option. Assertion (A): The order in which training samples are presented to the Perceptron can affect the final learned weight vector, even when the training data is linearly separable. Reason (R): If a dataset is linearly separable, the Perceptron algorithm is guaranteed to converge after a finite number of weight updates.
Both A and R are true, and R is the correct explanation of A.
Both A and R are true, but R is not the correct explanation of A.
A hospital develops a machine learning model to identify patients who may have a rare but life-threatening disease. Only about 1% of patients actually have the disease. Every patient predicted as positive is referred for an inexpensive follow-up blood test. However, missing an actual patient with the disease could delay treatment and have severe consequences. Which evaluation metric should be given the highest priority while selecting the model?
After training a KMeans clustering algorithm on a dataset we find a data point is sitting exactly on or extremely close to the decision boundary between two neighboring clusters. Which of the following values will the silhouette score be close / equal to?
Consider the following pandas DataFrame representing employee training records:
We want to retrieve all records of employees who belong to departments where the average training score is strictly greater than 75. Which of the following code snippets correctly achieves this?
Suppose the orginal dataset has 10 rows (1 to 10) Which row/rows of the dataset will be printed if the following code is executed?
Enter the line number (1,2...,10) of the printed row. If multiple lines are printed enter the sum of the row numbers (i.e. if line 1 and 2 are printed enter 3)
The pipeline first imputes the missing value with the (mean) strategy and then standardizes the column. What is the value of (the transformed value of the first sample, whose original value is 2)? (Enter up to 2 decimals)
Consider a 3 class classification problem where the training dataset contains 10 features. The given model is trained on the dataset. What is the output of the code given below?
Assume both models in the code given below are fit on the same dataset (X_train) containing 10 features.
Enter the difference between the total number of learnable parameters in both the models. (Enter the absolute value of the difference)
What is the output of the following code? (Round Upto one decmimal) X = [[0], [1], [2], [3]] y = [0, 0, 1, 1] from sklearn.neighbors import RadiusNeighborsRegressor neigh = RadiusNeighborsRegressor(radius=1.0) neigh.fit(X, y) print(neigh.predict([[1.5]]))
Consider the following feature matrix with one missing entry, imputed using :
The nearest neighbours are decided using the nan-aware (weighted) Euclidean distance computed over the present coordinates. What is the imputed value at position ? (Enter up to 2 decimals)
A binary classification model was evaluated on a test set with 500 samples. The model correctly identified 90 positive samples and 360 negative samples. Out of all the samples predicted as positive, 120 were predicted as positive. There were 100 actual positive samples in the dataset. Compute the F1-score of the model. (Round to 2 decimals)
Consider the following two ensemble regression architectures trained on the same dataset:
How do these two models differ in their output strategy to produce the final prediction for a given test instance, and how does adding more estimators affect them?
ensemble1 computes a weighted sum of predictions where later trees have higher weights; ensemble2 takes a simple arithmetic mean of all trees.
ensemble1 reduces variance by averaging independent predictions from 100 trees, meaning increasing n_estimators to 500 will ideally not cause overfitting.
ensemble2 reduces bias sequentially, meaning increasing n_estimators to 500 carries no risk of overfitting.
Both models output predictions by calculating the majority vote across the terminal leaf nodes of all individual base estimators.
A company uses K-Means clustering to divide its customers into 4 groups based on their purchasing behavior. After training the model, the data science team observes the following: Two different runs of K-Means on the same dataset produce different customer groups. One cluster contains customers that are much farther away from their assigned cluster center compared to other clusters. Which of the following statements are most likely to explain these observations?
K-Means can converge to different solutions because the initial placement of cluster centroids can affect the final clusters.
The cluster with customers far from its centroid may indicate that the chosen value of K does not represent the natural grouping structure of the data.
K-Means guarantees finding the globally optimal clustering solution regardless of initialization.
K-Means assigns clusters by maximizing the distance between points within the same cluster.
Consider the given 2 different lasso regression models trained on the same dataset:
Statements: 1. The coefficients of lasso2 are more likely to be smaller in magnitude than those of lasso1. 2. lasso1 may have fewer zero coefficients than lasso2. 3. The predictions of lasso1 on the training data will exactly match y. 4. Increasing alpha always increases model accuracy on unseen data. Which of the given statements are correct?
Consider the following code snippet. Assume that all required libraries have been imported correctly.
A practitioner observes that each time the fit() method is called on clf, the model is trained from scratch and the parameters learned in the previous training call are discarded. Which of the following changes should be made so that the model continues training from the previously learned parameters when fit() is called again?
Set warm_start=True
Combine training data from all training sessions into a single dataset
Consider the following code snippet that trains a Decision Tree classifier using scikit-learn:
A node in the trained decision tree is split only if both of the following conditions are satisfied: • The node contains at least min_samples_split samples. • Each child node created after the split contains at least min_samples_leaf samples. Assume node (N) is a non-leaf node being considered for splitting. In which of the following cases will the split at node (N) be allowed?
Node (N) contains 15 samples. After splitting, the left child has 9 samples and the right child has 6 samples.
Node (N) contains 6 samples. After splitting, the left child has 4 samples and the right child has 2 samples.
Node (N) contains 12 samples. After splitting, the left child has 3 samples and the right child has 9 samples.
Node (N) contains 8 samples. After splitting, the left child has 4 samples and the right child has 4 samples.
You are given a dataset where each row represents a customer using two numerical features. You apply K-means clustering with K=3 clusters using the following code:
What does the variable labels represent after the model is fitted?
The values of the input features used for clustering.
You are given the following DataFrame:
You want to perform the following imputation strategy: • Age → Replace missing values with the mean Age of each Department • Salary → Replace missing values with the median Salary of the entire column • Department → No imputation Which of the following code snippets correctly performs the above imputation?
You are training a RandomForestRegressor on a dataset with 20 features and 10,000 samples. Consider the following code:
Which of the following statements is TRUE about how this Random Forest model will behave?
With bootstrap=True, every tree sees the entire dataset, but the samples are shuffled randomly for each tree.
The forest will use all 20 features for each split, but only 5 trees out of the 200 will be trained on bootstrap samples.
Setting max_features=5 means only 5 trees out of 200 will use feature subsets, while the rest use all features.
Each tree will consider only 5 randomly chosen features when looking for the best split at every node.
Given below a y_train list which consists of coffee order's preference by the customers in a cafe.
MultiLabelBinarizer from sklearn library has been used to convert the y_train into numbers, so which of the following option matches with the output of the following code ?
Based on the above data, answer the given subquestions.
Consider the following assertion & reason and select the correct option:
Assertion: This is a good model as we see a very high accuracy of 96% Reason: In the case of imbalanced datasets, accuracy might not be the best metric for evaluating a model
Both the assertion and reason are correct, and the reason is a correctexplanation of the assertion
Both the assertion and reason are correct, but the reason is not a correctexplanation of the assertion.
The assertion is correct, but the reason is incorrect.
The assertion is incorrect, but the reason is correct.
The following code attempts to implement Ridge regression on the Boston housing dataset but contains an error. The missing part should be correctly filled in to avoid issues during training.
The following code attempts to implement Ridge regression on the Boston housing dataset but contains an error. The missing part should be correctly filled in to avoid issues during training.
Which of the following correctly fills the missing part while ensuring proper preprocessing?
Based on the above data, answer the given subquestions.
What is the given code below trying to accomplish for the given titanic dataset ?
What is the given code below trying to accomplish for the given titanic dataset ?
Based on the above data, answer the given subquestions.
Consider the following and select the corrrect option:
Assertion: This is a good model as we see a very high accuracy of 97% Reason: In the case of imbalanced datasets, accuracy might not be the best metric for evaluating a model
Both the assertion and reason are correct, and the reason is a correctexplanation of the assertion
Both the assertion and reason are correct, but the reason is not a correctexplanation of the assertion.
The assertion is correct, but the reason is incorrect.
The assertion is incorrect, but the reason is correct.
Suppose we want to transform features in a dataset using polynomial transformation. The sklearn API provides the functionality in which of the following modules?