Home
MCQs by exam
Interviews
Data Science
Interviews MCQs – Data Science · Page 4
231 multiple choice questions typical of the Interviews exam, with answers and explanations. Switch on practice mode to test yourself first.
A
qcut, which uses sample quantiles, whereas cut splits on equal-width value ranges
Correct answer
B
cut, which uses sample quantiles, whereas qcut splits on equal-width value ranges
C
cut, because both functions are identical except for the naming of their labels
D
qcut, because it always produces equal-width bins regardless of the data distribution
A
A boolean Series aligned to the index, with NaN rows marked False unless NaN is listed
Correct answer
B
A boolean Series of identical length, with NaN rows marked True so every record is kept
C
An integer array of row positions, because isin returns the matching row numbers
D
A filtered DataFrame directly, since isin applies the mask as soon as it is called
A
df.transpose, which swaps rows and columns and therefore creates a long form table
B
df.melt with id_vars, which turns the monthly columns into rows of key-value pairs
Correct answer
C
df.pivot with the month columns as index, which expands the columns into extra rows
D
df.stack on axis=1, which returns a wide frame with the months kept as columns
A
Scattered in place, because pandas leaves NaN rows where they originally stood
B
The call raises, because sorting a column with NaN requires dropna first
C
At the end by default, because na_position defaults to last in sort_values
Correct answer
D
At the beginning by default, because NaN sorts before every numeric value
A
The duplicate cells are averaged, because the default aggregation is the mean
Correct answer
B
A ValueError is raised, because duplicate entries need an explicit aggfunc
C
The last row for each cell wins, because pivot_table keeps the final value
D
The rows are concatenated into a list inside the cell, preserving every value
A
CAST(order_date AS TEXT) LIKE '2024%', which cannot use the index
B
order_date + INTERVAL '1 day' = '2024-06-01', a computed date
C
order_date >= '2024-01-01' AND order_date < '2025-01-01'
Correct answer
D
EXTRACT(YEAR FROM order_date) = 2024, which scans every row
A
TRUNCATE accepts a WHERE clause but is slower than DELETE, because it scans the whole table row by row
B
Both fire row-level triggers once per removed row, so auditing behaves exactly the same for the two statements here
C
DELETE cannot be rolled back in any database, while TRUNCATE always can, because it is DDL and not DML
D
TRUNCATE removes all rows in one operation, cannot take a WHERE clause and fires no row-level delete triggers
Correct answer
A
The store's average sales, with 0 substituted wherever the partition is empty or has one row
B
The next month's sales within the same store, with 0 substituted for the last row of each partition
C
The running total of sales within each store, starting at 0 at the very first row of every partition here
D
The previous month's sales within the same store, with 0 substituted for the first row of each partition
Correct answer
A
Because NOT IN converts the NULL to zero and then compares numerically, matching every zero value
B
Because x <> NULL is UNKNOWN, so the NOT IN predicate can never be TRUE; NOT EXISTS is null-safe
Correct answer
C
Because the subquery is executed only when it contains no NULL values, and otherwise the whole subquery is skipped
D
Because NOT IN is not valid with a subquery at all, so the parser rejects the statement outright
A
UNION removes duplicate rows and therefore usually needs a sort or hash, while UNION ALL concatenates and keeps duplicates
Correct answer
B
Both remove duplicate rows, differing only in the column ordering they produce, so the choice between them is purely cosmetic
C
UNION requires matching column names, while UNION ALL does not, which is why UNION ALL is faster to write
D
UNION ALL removes duplicate rows, while UNION keeps them, so the two operators are exact opposites in effect
A
20, because the median of the three values is used instead of the mean
B
NULL, because any NULL in the input makes the aggregate NULL
C
15, because the NULL is excluded from both the sum and the count
Correct answer
D
10, because the NULL is treated as a zero value in the average
A
The rows are excluded from the result entirely, because the grouping key is missing
B
The query fails unless NULLs are filtered out first, since grouping needs a known key
C
All NULLs form a single group, because GROUP BY treats them as equal to each other
Correct answer
D
Each NULL forms its own separate group, because NULL is never equal to another one
A
Because COUNT(*) ignores NULLs in the customer key, so rows with a missing key are never counted at all by the aggregate
B
The one-to-many join repeats each customer row per order, so COUNT(DISTINCT customer_id) or a subquery gives the true count
Correct answer
C
Because the join sorts the rows and duplicates them during the sort, so the sort key must therefore be made distinct first of all
D
Because COUNT(*) counts columns rather than rows, so it returns the width of the joined result instead of its height
A
It includes them only if the column is indexed, since the index stores a default value
B
It includes them, because NULL differs from every value including the string x
C
It excludes them, because NULL <> 'x' evaluates to UNKNOWN rather than TRUE
Correct answer
D
It raises an error unless col is declared NOT NULL, because the comparison is invalid
A
Nothing changes, because the optimiser moves the predicate into the ON clause
B
All inactive matches are kept while unmatched rows are duplicated
C
The query fails because WHERE cannot reference the right table
D
Rows with no matching b row are removed, turning the outer join into an effective inner join
Correct answer
A
1,2,3 for all three functions, because every row receives a distinct sequential position
B
1,1,2 for RANK and 1,1,3 for DENSE_RANK, with 1,2,3 for ROW_NUMBER in the very same single query
C
1,1,3 for RANK; 1,1,2 for DENSE_RANK; and 1,2,3 for ROW_NUMBER with an arbitrary tie order
Correct answer
D
1,1,3 for all three, since ties always skip a position whatever function is used
A
RANGE requires a PARTITION BY clause, whereas ROWS can be used over the whole table without one
B
ROWS ignores the ORDER BY, whereas RANGE sorts the partition before summing
C
Rows that tie on d are all included in the same running total under RANGE, while ROWS admits them one at a time
Correct answer
D
RANGE includes only the current row, whereas ROWS accumulates every preceding row in the partition
A
10 and 7
Correct answer
B
7 and 7
C
10 and 10
D
7 and 10
A
The precision-recall curve, which plots precision against recall at every threshold
B
The validation curve, which plots scores against one hyperparameter value at a time
C
The ROC curve, which plots the true positive rate against the false positive rate of the model
D
The learning curve, which plots training and validation scores against training-set size
Correct answer
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
Practise on paper
Preparing for Interviews?
Make it your exam plan: see your progress in every subject and topic, set a daily goal and practise what you have not done yet.
Start my Interviews plan
Test yourself
Take a timed online test and get a certificate, or play today's quick quiz.
Online tests
Daily quiz