Home
Subjects
Data Science
Data Science MCQs · Page 22
1,613 multiple choice questions with answers across 28 topics.
⚔️
Challenge a friend on Data Science
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
A
step1 and step2, numbered in order
B
scaler and clf, fixed default aliases
C
It raises an error, because make_pipeline requires explicit names
D
standardscaler and logisticregression, the lowercased class names
Correct answer
A
It multiplies each row's contribution to the loss by its weight, without resampling the data
Correct answer
B
It sorts the rows so that heavier samples are fitted first and influence the coefficients more
C
It affects only predict, not the fitted coefficients, which are always learned unweighted
D
It physically replicates rows in proportion to their weights before the fit begins to run
A
max_features must equal the total number of features, so that every split always sees the whole feature set
B
The number of trees must be less than the number of samples, so that every tree sees fresh data
C
criterion must be set to entropy, because the Gini criterion cannot track the out-of-bag error
D
bootstrap=True, since out-of-bag samples exist only when each tree is trained on a bootstrap resample
Correct answer
A
It maps the unseen category to the first known category
B
It encodes that row as all zeros instead of raising an error
Correct answer
C
It adds a new column for the unseen category automatically
D
It raises an error, since ignore only downgrades the error to a warning
A
predict_proba returns normalised class probabilities summing to one, while decision_function returns unbounded signed distances to the decision boundary
Correct answer
B
decision_function returns probabilities between zero and one, while predict_proba returns raw margins, so the two names are swapped in most of the documentation
C
Both return probabilities, but predict_proba is only for regressors while decision_function is only for classifiers, so neither applies here
D
predict_proba is available on every estimator, while decision_function is not, which is why predict_proba is the preferred interface for scoring
A
It requires a separate hold-out set and raises NotFittedError when none is supplied alongside cv
B
The predictions are out-of-fold, but the same folds would also drive selection, so the resulting score is not a clean estimate
Correct answer
C
cross_val_predict refits on the full dataset first, so every prediction is in-sample and therefore over-optimistic
D
It returns one aggregate score per fold instead of predictions, so accuracy cannot be computed from its output
A
The estimator fitted on the first fold only
B
An ensemble average of all candidate estimators
C
It raises NotFittedError because refit must be False before predict
D
The best estimator refitted on the full training set, not just the winning fold
Correct answer
A
Because without centring the transformed features are always positive and therefore easier to interpret
B
Because with_mean=False switches to median and interquartile scaling instead of the ordinary mean
C
Centring would densify a sparse matrix, so scaling by the standard deviation alone preserves sparsity
Correct answer
D
Sparse matrices cannot be divided by a scalar, so only centring is available for them in practice
A
The training and test sets keep approximately the same class proportions as the full dataset
Correct answer
B
Only samples with non-missing labels are used, and rows with NaN labels are dropped
C
Each class appears exactly once in the test set, regardless of how many samples it has
D
The split is reproducible without setting random_state, because stratification fixes the seed
A
Pipeline refits the scaler on every validation fold to check stability across the splits
B
The pipeline scales the whole dataset once before splitting, which is equivalent and faster
C
During each fold, fit runs on the training part only and transform is applied to the held-out part
Correct answer
D
Pipeline disables scaling during cross-validation entirely, so the scaler only runs on the final fit
A
LeaveOneOut, giving one fold per sample and a very large number of separate fits
B
ShuffleSplit with a fixed random seed and a single random shuffle per call
C
StratifiedKFold with five splits, preserving class proportions in each fold
Correct answer
D
Plain KFold with ten splits, ignoring the class labels of the samples entirely
A
Test statistics leak into preprocessing, so the reported score is optimistically biased
Correct answer
B
No effect at all, because scaling cannot change model accuracy on any dataset
C
It causes the model to underfit, lowering the reported score well below the true value
D
The test set silently becomes the training set, so the model never sees genuinely new data
A
An error, because the series is shorter than the window
B
NaN, because min_periods defaults to the window size
Correct answer
C
The mean of the available values, because partial windows are used
D
Zero, because missing window values are treated as zero
A
To skip that column entirely while reading, so it never appears in the frame
B
To speed up parsing by disabling the C engine and using the Python parser
C
To stop pandas inferring ZIP codes as integers and stripping leading zeros
Correct answer
D
To force every column in the file to be parsed as text rather than numbers
A
Relative frequencies excluding NaN, so the resulting proportions sum to less than one overall
B
Boolean flags indicating whether each value is missing, aligned to the original index
C
Absolute counts per value, excluding NaN, sorted in ascending order of frequency
D
Relative frequencies per distinct value, including NaN as its own category, summing to 1
Correct answer
A
Only labels present in both frames are kept, as an inner join on the index
B
The frames are concatenated positionally and the index is ignored, so no alignment occurs
C
The index union is used and missing labels produce NaN, as an outer join on the index
Correct answer
D
An error is raised because the indexes are not identical, and the frames must be reindexed
A
A NumPy array of the whole frame
B
A tuple of the row values in column order
C
A Series for each row, indexed by the column labels
Correct answer
D
A Series for each column, indexed by the row labels
A
The data and index are copied, but the Python objects inside object columns are not recursively copied, so they remain shared
Correct answer
B
deep=True is not allowed for object dtype columns, because pandas cannot deep-copy arbitrary Python objects
C
Every nested list is deep-copied, guaranteeing full independence, so mutating one frame never affects the contents of the other
D
deep=True copies only the index and shares all of the column data, while deep=False copies the column arrays
A
Columns containing at least three non-missing values
B
Rows containing at least three non-missing values
Correct answer
C
Rows containing fewer than three missing values
D
Rows containing exactly three non-missing values
A
res.droplevel('year') returns a Series indexed by month only
Correct answer
B
res.reset_index(level='year') removes the level without adding a column
C
res.drop('year') drops the level from the index
D
res.swaplevel() removes the level entirely
A
It converts the bad entries to zero
B
It replaces them with NaN and returns a numeric dtype column
Correct answer
C
It leaves the column as object and keeps the original strings
D
It raises a ValueError listing the offending values
A
It converts every string to an interned string object, for faster hashing and lower memory use
B
It stores integer codes plus a dictionary of categories, cutting memory and enabling ordered comparisons
Correct answer
C
It drops duplicate values from the column, keeping only the first occurrence of every distinct string value
D
It permanently sorts the DataFrame by that column and rebuilds the row index in sorted order
A
A boolean column showing whether the join key was unique in both of the input frames
B
It raises an error if any of the keys fail to match, instead of reporting them in the result
C
It sorts the result by the join key automatically and resets the index of the output
D
A _merge column whose values are left_only, right_only or both, showing each row's origin
Correct answer
A
Both return one row per group, differing only in the index name that the resulting object carries afterwards
B
transform can only be used with user-defined functions, while apply also accepts built-in method strings
C
transform returns a Series aligned to the original index with the same length, while apply returns one value per group
Correct answer
D
apply returns a column the same length as the input frame itself, while transform reduces the result to one row per group
A
loc returns rows 0, 1 and 2 inclusive, while iloc returns rows 0 and 1 only
Correct answer
B
Both return rows 0, 1 and 2
C
loc returns rows 0 and 1, while iloc returns 0, 1 and 2
D
Both return rows 0 and 1, because slices always exclude the endpoint